@crossplane-org/function-sdk-typescript 0.4.0 → 0.5.0-20260305214119-9b69c9f3611e
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.
- package/README.md +102 -8
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/proto/run_function.d.ts +97 -2
- package/dist/proto/run_function.d.ts.map +1 -1
- package/dist/proto/run_function.js +460 -3
- package/dist/proto/run_function.js.map +1 -1
- package/dist/request/request.d.ts +158 -1
- package/dist/request/request.d.ts.map +1 -1
- package/dist/request/request.js +213 -1
- package/dist/request/request.js.map +1 -1
- package/dist/resource/resource.d.ts +113 -0
- package/dist/resource/resource.d.ts.map +1 -1
- package/dist/resource/resource.js +173 -0
- package/dist/resource/resource.js.map +1 -1
- package/dist/response/response.d.ts +78 -1
- package/dist/response/response.d.ts.map +1 -1
- package/dist/response/response.js +107 -1
- package/dist/response/response.js.map +1 -1
- package/package.json +2 -2
package/dist/request/request.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* including composite resources, composed resources, input configuration, context values,
|
|
6
6
|
* required resources, and credentials.
|
|
7
7
|
*/
|
|
8
|
-
import { Credentials, Resource, Resources, RunFunctionRequest } from '../proto/run_function.js';
|
|
8
|
+
import { Capability, Credentials, Resource, Resources, RunFunctionRequest, } from '../proto/run_function.js';
|
|
9
9
|
/**
|
|
10
10
|
* Get the desired composite resource (XR) from the request.
|
|
11
11
|
*
|
|
@@ -216,4 +216,216 @@ export function getCredentials(req, name) {
|
|
|
216
216
|
}
|
|
217
217
|
return creds;
|
|
218
218
|
}
|
|
219
|
+
/**
|
|
220
|
+
* Get a required resource from the request by name.
|
|
221
|
+
*
|
|
222
|
+
* Required resources are resources that the function specified it needs using
|
|
223
|
+
* response.requireResource. Crossplane fetches the requested resources and includes
|
|
224
|
+
* them in the next request. The boolean return value indicates whether Crossplane
|
|
225
|
+
* has resolved the requirement.
|
|
226
|
+
*
|
|
227
|
+
* @param req - The RunFunctionRequest containing required resources
|
|
228
|
+
* @param name - The name of the required resource group to retrieve
|
|
229
|
+
* @returns A tuple of [resources, resolved]:
|
|
230
|
+
* - resources: Array of Resource objects (empty if not found)
|
|
231
|
+
* - resolved: true if Crossplane attempted to resolve the requirement, false otherwise
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* // After calling requireResource in a previous function invocation:
|
|
236
|
+
* const [resources, resolved] = getRequiredResource(req, "app-config");
|
|
237
|
+
* if (!resolved) {
|
|
238
|
+
* console.log("Resource requirement not yet resolved by Crossplane");
|
|
239
|
+
* } else if (resources.length === 0) {
|
|
240
|
+
* console.log("Resource requirement resolved but no resources found");
|
|
241
|
+
* } else {
|
|
242
|
+
* console.log("Found resources:", resources);
|
|
243
|
+
* resources.forEach(r => console.log(r.resource));
|
|
244
|
+
* }
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
export function getRequiredResource(req, name) {
|
|
248
|
+
if (!req.requiredResources) {
|
|
249
|
+
return [[], false];
|
|
250
|
+
}
|
|
251
|
+
const rrs = req.requiredResources[name];
|
|
252
|
+
if (!rrs) {
|
|
253
|
+
return [[], false];
|
|
254
|
+
}
|
|
255
|
+
const out = [];
|
|
256
|
+
for (const item of rrs.items || []) {
|
|
257
|
+
if (!item || !item.resource) {
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
out.push({
|
|
261
|
+
resource: item.resource,
|
|
262
|
+
connectionDetails: item.connectionDetails || {},
|
|
263
|
+
ready: item.ready || 0,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
return [out, true];
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Get all required schemas from the request.
|
|
270
|
+
*
|
|
271
|
+
* Returns all schemas that were requested using response.requireSchema and
|
|
272
|
+
* resolved by Crossplane. The map key corresponds to the name used in
|
|
273
|
+
* requireSchema. Each value is the OpenAPI v3 schema as an unstructured object,
|
|
274
|
+
* or undefined if the schema could not be found.
|
|
275
|
+
*
|
|
276
|
+
* @param req - The RunFunctionRequest containing required schemas
|
|
277
|
+
* @returns A map of schema names to OpenAPI v3 schema objects (or undefined if not found)
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```typescript
|
|
281
|
+
* const schemas = getRequiredSchemas(req);
|
|
282
|
+
* for (const [name, schema] of Object.entries(schemas)) {
|
|
283
|
+
* if (schema) {
|
|
284
|
+
* console.log(`Schema ${name}:`, schema);
|
|
285
|
+
* } else {
|
|
286
|
+
* console.log(`Schema ${name} was requested but not found`);
|
|
287
|
+
* }
|
|
288
|
+
* }
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
export function getRequiredSchemas(req) {
|
|
292
|
+
const out = {};
|
|
293
|
+
if (!req.requiredSchemas) {
|
|
294
|
+
return out;
|
|
295
|
+
}
|
|
296
|
+
for (const [name, schema] of Object.entries(req.requiredSchemas)) {
|
|
297
|
+
out[name] = schema?.openapiV3;
|
|
298
|
+
}
|
|
299
|
+
return out;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Get a required schema from the request by name.
|
|
303
|
+
*
|
|
304
|
+
* Returns the OpenAPI v3 schema for a resource kind that was requested using
|
|
305
|
+
* response.requireSchema. The boolean return value indicates whether Crossplane
|
|
306
|
+
* has resolved the requirement.
|
|
307
|
+
*
|
|
308
|
+
* @param req - The RunFunctionRequest containing required schemas
|
|
309
|
+
* @param name - The name of the required schema to retrieve
|
|
310
|
+
* @returns A tuple of [schema, resolved]:
|
|
311
|
+
* - schema: The OpenAPI v3 schema object, or undefined if not found
|
|
312
|
+
* - resolved: true if Crossplane attempted to resolve the requirement, false otherwise
|
|
313
|
+
*
|
|
314
|
+
* Note: When resolved is true but schema is undefined, it means Crossplane tried
|
|
315
|
+
* to find the schema but it doesn't exist for that resource kind.
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* ```typescript
|
|
319
|
+
* // After calling requireSchema in a previous function invocation:
|
|
320
|
+
* const [schema, resolved] = getRequiredSchema(req, "xr-schema");
|
|
321
|
+
* if (!resolved) {
|
|
322
|
+
* console.log("Schema not yet resolved by Crossplane");
|
|
323
|
+
* } else if (!schema) {
|
|
324
|
+
* console.log("Schema resolved but not found (kind may not exist)");
|
|
325
|
+
* } else {
|
|
326
|
+
* console.log("Schema properties:", schema.properties);
|
|
327
|
+
* console.log("Required fields:", schema.required);
|
|
328
|
+
* }
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
export function getRequiredSchema(req, name) {
|
|
332
|
+
const schemas = req.requiredSchemas;
|
|
333
|
+
if (!schemas) {
|
|
334
|
+
return [undefined, false];
|
|
335
|
+
}
|
|
336
|
+
const schema = schemas[name];
|
|
337
|
+
if (!schema) {
|
|
338
|
+
return [undefined, false];
|
|
339
|
+
}
|
|
340
|
+
return [schema.openapiV3, true];
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Check whether Crossplane advertises its capabilities.
|
|
344
|
+
*
|
|
345
|
+
* Crossplane v2.2 and later advertise their capabilities in the request
|
|
346
|
+
* metadata. If this returns false, the calling Crossplane predates capability
|
|
347
|
+
* advertisement and hasCapability will always return false, even for features
|
|
348
|
+
* the older Crossplane does support.
|
|
349
|
+
*
|
|
350
|
+
* @param req - The RunFunctionRequest to check
|
|
351
|
+
* @returns true if Crossplane advertises its capabilities
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* ```typescript
|
|
355
|
+
* if (!advertiseCapabilities(req)) {
|
|
356
|
+
* // Pre-v2.2 Crossplane, capabilities are unknown
|
|
357
|
+
* console.log("Crossplane version predates capability advertisement");
|
|
358
|
+
* } else if (hasCapability(req, Capability.CAPABILITY_REQUIRED_SCHEMAS)) {
|
|
359
|
+
* requireSchema(rsp, "xr", xrApiVersion, xrKind);
|
|
360
|
+
* }
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
363
|
+
export function advertiseCapabilities(req) {
|
|
364
|
+
if (!req.meta?.capabilities) {
|
|
365
|
+
return false;
|
|
366
|
+
}
|
|
367
|
+
return req.meta.capabilities.includes(Capability.CAPABILITY_CAPABILITIES);
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Check whether Crossplane advertises a particular capability.
|
|
371
|
+
*
|
|
372
|
+
* Crossplane sends its capabilities in the request metadata. Functions can use
|
|
373
|
+
* this to determine whether Crossplane will honor certain fields in their
|
|
374
|
+
* response, or populate certain fields in their request.
|
|
375
|
+
*
|
|
376
|
+
* Use advertiseCapabilities to check whether Crossplane advertises its
|
|
377
|
+
* capabilities at all. If it doesn't, hasCapability always returns false even
|
|
378
|
+
* for features the older Crossplane does support.
|
|
379
|
+
*
|
|
380
|
+
* @param req - The RunFunctionRequest to check
|
|
381
|
+
* @param cap - The capability to check for (e.g., Capability.CAPABILITY_REQUIRED_SCHEMAS)
|
|
382
|
+
* @returns true if the capability is present in the request metadata
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* ```typescript
|
|
386
|
+
* import { Capability } from './proto/run_function.js';
|
|
387
|
+
*
|
|
388
|
+
* if (hasCapability(req, Capability.CAPABILITY_REQUIRED_SCHEMAS)) {
|
|
389
|
+
* requireSchema(rsp, "xr", xrApiVersion, xrKind);
|
|
390
|
+
* }
|
|
391
|
+
*
|
|
392
|
+
* if (hasCapability(req, Capability.CAPABILITY_CONDITIONS)) {
|
|
393
|
+
* // Safe to return status conditions
|
|
394
|
+
* rsp.conditions = [{ type: "Ready", status: "True" }];
|
|
395
|
+
* }
|
|
396
|
+
* ```
|
|
397
|
+
*/
|
|
398
|
+
export function hasCapability(req, cap) {
|
|
399
|
+
if (!req.meta?.capabilities) {
|
|
400
|
+
return false;
|
|
401
|
+
}
|
|
402
|
+
return req.meta.capabilities.includes(cap);
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Get the watched resource that triggered this operation.
|
|
406
|
+
*
|
|
407
|
+
* When a WatchOperation creates an Operation, it injects the resource that
|
|
408
|
+
* changed using the special requirement name 'ops.crossplane.io/watched-resource'.
|
|
409
|
+
* This helper makes it easy to access that resource.
|
|
410
|
+
*
|
|
411
|
+
* @param req - The RunFunctionRequest to check for a watched resource
|
|
412
|
+
* @returns The watched resource object, or undefined if not found
|
|
413
|
+
*
|
|
414
|
+
* @example
|
|
415
|
+
* ```typescript
|
|
416
|
+
* // In an operation function triggered by a WatchOperation
|
|
417
|
+
* const watched = getWatchedResource(req);
|
|
418
|
+
* if (watched) {
|
|
419
|
+
* console.log("Operation triggered by change to:", watched.metadata?.name);
|
|
420
|
+
* console.log("Resource kind:", watched.kind);
|
|
421
|
+
* }
|
|
422
|
+
* ```
|
|
423
|
+
*/
|
|
424
|
+
export function getWatchedResource(req) {
|
|
425
|
+
const [resources, resolved] = getRequiredResource(req, 'ops.crossplane.io/watched-resource');
|
|
426
|
+
if (!resolved || resources.length === 0) {
|
|
427
|
+
return undefined;
|
|
428
|
+
}
|
|
429
|
+
return resources[0].resource;
|
|
430
|
+
}
|
|
219
431
|
//# sourceMappingURL=request.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/request/request.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/request/request.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,UAAU,EACV,WAAW,EACX,QAAQ,EACR,SAAS,EACT,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,2BAA2B,CAAC,GAAuB;IACjE,OAAO,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC;AAChC,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,4BAA4B,CAAC,GAAuB;IAClE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CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAuB;IACxD,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,GAAG,mBAAmB,CAAC,GAAG,EAAE,oCAAoC,CAAC,CAAC;IAC7F,IAAI,CAAC,QAAQ,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxC,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC/B,CAAC"}
|
|
@@ -2,6 +2,33 @@ import { Ready, Resource } from '../proto/run_function.js';
|
|
|
2
2
|
export type ConnectionDetails = {
|
|
3
3
|
[key: string]: Buffer;
|
|
4
4
|
};
|
|
5
|
+
/**
|
|
6
|
+
* Condition represents a status condition of a Kubernetes resource
|
|
7
|
+
*/
|
|
8
|
+
export interface Condition {
|
|
9
|
+
/** Type of the condition - e.g. Ready, Synced */
|
|
10
|
+
type: string;
|
|
11
|
+
/** Status of the condition - True, False, or Unknown */
|
|
12
|
+
status: string;
|
|
13
|
+
/** Reason for the condition status - typically CamelCase */
|
|
14
|
+
reason?: string;
|
|
15
|
+
/** Optional message providing details about the condition */
|
|
16
|
+
message?: string;
|
|
17
|
+
/** The last time the condition transitioned to this status */
|
|
18
|
+
lastTransitionTime?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Options for controlling merge behavior when updating resources
|
|
22
|
+
*/
|
|
23
|
+
export interface MergeOptions {
|
|
24
|
+
/**
|
|
25
|
+
* Whether to merge arrays by concatenation (true) or replace them (false).
|
|
26
|
+
* Default is false.
|
|
27
|
+
*
|
|
28
|
+
* @default false
|
|
29
|
+
*/
|
|
30
|
+
mergeArrays?: boolean;
|
|
31
|
+
}
|
|
5
32
|
/**
|
|
6
33
|
* Composite represents a Crossplane composite resource (XR) with its state
|
|
7
34
|
*/
|
|
@@ -128,4 +155,90 @@ export declare function toObject(resource: Resource): Record<string, unknown> |
|
|
|
128
155
|
export declare function fromModel<T extends Record<string, unknown>>(obj: {
|
|
129
156
|
toJSON: () => T;
|
|
130
157
|
}, connectionDetails?: ConnectionDetails, ready?: Ready): Resource;
|
|
158
|
+
/**
|
|
159
|
+
* Update a Resource by merging a source into it.
|
|
160
|
+
*
|
|
161
|
+
* This function performs a deep merge of the source object into the target Resource,
|
|
162
|
+
* allowing you to update specific fields while preserving others. The source can be
|
|
163
|
+
* a plain JavaScript object, a protobuf Struct (Record<string, unknown>), or a
|
|
164
|
+
* Resource object.
|
|
165
|
+
*
|
|
166
|
+
* The merge semantics match the Python SDK's behavior (similar to a dictionary's
|
|
167
|
+
* update method): fields that don't exist will be added, and fields that exist will
|
|
168
|
+
* be overwritten. By default, arrays are replaced rather than concatenated to match
|
|
169
|
+
* Python SDK behavior.
|
|
170
|
+
*
|
|
171
|
+
* @param r - The Resource to update
|
|
172
|
+
* @param source - The source data to merge (plain object, Struct, or Resource)
|
|
173
|
+
* @param options - Optional merge configuration (default: { mergeArrays: false })
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* const bucket = getDesiredComposedResources(req)["my-bucket"];
|
|
178
|
+
* if (bucket) {
|
|
179
|
+
* // Update specific fields while preserving others
|
|
180
|
+
* // Arrays are replaced by default (Python SDK behavior)
|
|
181
|
+
* update(bucket, {
|
|
182
|
+
* resource: {
|
|
183
|
+
* spec: {
|
|
184
|
+
* forProvider: {
|
|
185
|
+
* region: "us-west-2",
|
|
186
|
+
* tags: ["env:prod", "team:platform"] // Replaces existing tags
|
|
187
|
+
* }
|
|
188
|
+
* }
|
|
189
|
+
* }
|
|
190
|
+
* });
|
|
191
|
+
* }
|
|
192
|
+
*
|
|
193
|
+
* // Optionally concatenate arrays instead of replacing them
|
|
194
|
+
* update(bucket, {
|
|
195
|
+
* resource: {
|
|
196
|
+
* spec: {
|
|
197
|
+
* forProvider: {
|
|
198
|
+
* tags: ["new-tag"] // Will be appended to existing tags
|
|
199
|
+
* }
|
|
200
|
+
* }
|
|
201
|
+
* }
|
|
202
|
+
* }, { mergeArrays: true });
|
|
203
|
+
*
|
|
204
|
+
* // You can also merge from another Resource
|
|
205
|
+
* const template = Resource.fromJSON({ resource: templateConfig });
|
|
206
|
+
* update(bucket, template);
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
export declare function update(r: Resource, source: Record<string, unknown> | Resource, options?: MergeOptions): void;
|
|
210
|
+
/**
|
|
211
|
+
* Get a status condition from a Kubernetes resource.
|
|
212
|
+
*
|
|
213
|
+
* This function extracts a specific status condition from a resource by type.
|
|
214
|
+
* Status conditions follow the Kubernetes standard pattern and are typically
|
|
215
|
+
* found in the resource's status.conditions array.
|
|
216
|
+
*
|
|
217
|
+
* @param resource - A Kubernetes resource object (plain JavaScript object)
|
|
218
|
+
* @param type - The type of status condition to get (e.g., "Ready", "Synced")
|
|
219
|
+
* @returns The requested status condition, or a condition with status "Unknown" if not found
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* const oxr = getObservedCompositeResource(req);
|
|
224
|
+
* if (oxr?.resource) {
|
|
225
|
+
* const readyCondition = getCondition(oxr.resource, "Ready");
|
|
226
|
+
* if (readyCondition.status === "True") {
|
|
227
|
+
* console.log("Resource is ready");
|
|
228
|
+
* } else if (readyCondition.status === "False") {
|
|
229
|
+
* console.log("Resource not ready:", readyCondition.message);
|
|
230
|
+
* } else {
|
|
231
|
+
* console.log("Ready status unknown");
|
|
232
|
+
* }
|
|
233
|
+
* }
|
|
234
|
+
*
|
|
235
|
+
* // Check if a composed resource is synced
|
|
236
|
+
* const bucket = observedResources["my-bucket"];
|
|
237
|
+
* if (bucket?.resource) {
|
|
238
|
+
* const synced = getCondition(bucket.resource, "Synced");
|
|
239
|
+
* console.log("Sync status:", synced.status, synced.reason);
|
|
240
|
+
* }
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
export declare function getCondition(resource: Record<string, unknown> | undefined, type: string): Condition;
|
|
131
244
|
//# sourceMappingURL=resource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../src/resource/resource.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../src/resource/resource.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAI3D,MAAM,MAAM,iBAAiB,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,MAAM,EAAE,MAAM,CAAC;IACf,4DAA4D;IAC5D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8DAA8D;IAC9D,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;OAKG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,QAAQ,CAAC;IACnB,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,KAAK,EAAE,KAAK,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,QAAQ,CAAC;IACnB,iBAAiB,EAAE,iBAAiB,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,QAAQ,CAAC;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAgB,MAAM,CACpB,CAAC,EAAE,QAAQ,EACX,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,QAAQ,EAC1C,OAAO,CAAC,EAAE,YAAY,GACrB,IAAI,CA0DN;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAC7C,IAAI,EAAE,MAAM,GACX,SAAS,CA4CX"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Resource utilities for working with Kubernetes resources and protobuf conversion
|
|
2
2
|
import { Ready, Resource } from '../proto/run_function.js';
|
|
3
|
+
import { merge } from 'ts-deepmerge';
|
|
3
4
|
/**
|
|
4
5
|
* Create a new empty DesiredComposed resource
|
|
5
6
|
*/
|
|
@@ -141,6 +142,178 @@ export function toObject(resource) {
|
|
|
141
142
|
* ```
|
|
142
143
|
*/
|
|
143
144
|
export function fromModel(obj, connectionDetails, ready) {
|
|
145
|
+
// T already extends Record<string, unknown>, so the cast is unnecessary.
|
|
146
|
+
// Pass the result directly to fromObject which accepts T via its signature.
|
|
144
147
|
return fromObject(obj.toJSON(), connectionDetails, ready);
|
|
145
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Update a Resource by merging a source into it.
|
|
151
|
+
*
|
|
152
|
+
* This function performs a deep merge of the source object into the target Resource,
|
|
153
|
+
* allowing you to update specific fields while preserving others. The source can be
|
|
154
|
+
* a plain JavaScript object, a protobuf Struct (Record<string, unknown>), or a
|
|
155
|
+
* Resource object.
|
|
156
|
+
*
|
|
157
|
+
* The merge semantics match the Python SDK's behavior (similar to a dictionary's
|
|
158
|
+
* update method): fields that don't exist will be added, and fields that exist will
|
|
159
|
+
* be overwritten. By default, arrays are replaced rather than concatenated to match
|
|
160
|
+
* Python SDK behavior.
|
|
161
|
+
*
|
|
162
|
+
* @param r - The Resource to update
|
|
163
|
+
* @param source - The source data to merge (plain object, Struct, or Resource)
|
|
164
|
+
* @param options - Optional merge configuration (default: { mergeArrays: false })
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* const bucket = getDesiredComposedResources(req)["my-bucket"];
|
|
169
|
+
* if (bucket) {
|
|
170
|
+
* // Update specific fields while preserving others
|
|
171
|
+
* // Arrays are replaced by default (Python SDK behavior)
|
|
172
|
+
* update(bucket, {
|
|
173
|
+
* resource: {
|
|
174
|
+
* spec: {
|
|
175
|
+
* forProvider: {
|
|
176
|
+
* region: "us-west-2",
|
|
177
|
+
* tags: ["env:prod", "team:platform"] // Replaces existing tags
|
|
178
|
+
* }
|
|
179
|
+
* }
|
|
180
|
+
* }
|
|
181
|
+
* });
|
|
182
|
+
* }
|
|
183
|
+
*
|
|
184
|
+
* // Optionally concatenate arrays instead of replacing them
|
|
185
|
+
* update(bucket, {
|
|
186
|
+
* resource: {
|
|
187
|
+
* spec: {
|
|
188
|
+
* forProvider: {
|
|
189
|
+
* tags: ["new-tag"] // Will be appended to existing tags
|
|
190
|
+
* }
|
|
191
|
+
* }
|
|
192
|
+
* }
|
|
193
|
+
* }, { mergeArrays: true });
|
|
194
|
+
*
|
|
195
|
+
* // You can also merge from another Resource
|
|
196
|
+
* const template = Resource.fromJSON({ resource: templateConfig });
|
|
197
|
+
* update(bucket, template);
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
export function update(r, source, options) {
|
|
201
|
+
if (!r.resource) {
|
|
202
|
+
r.resource = {};
|
|
203
|
+
}
|
|
204
|
+
// Default to Python SDK behavior: replace arrays rather than concatenating
|
|
205
|
+
const mergeArrays = options?.mergeArrays ?? false;
|
|
206
|
+
// Detect genuine protobuf `Resource` instances by checking for protobuf-specific fields
|
|
207
|
+
// (the generated Resource interface includes `connectionDetails` and `ready`).
|
|
208
|
+
const isProtoResource = typeof source === 'object' &&
|
|
209
|
+
source !== null &&
|
|
210
|
+
'resource' in source &&
|
|
211
|
+
typeof source.resource === 'object' &&
|
|
212
|
+
('connectionDetails' in source || 'ready' in source);
|
|
213
|
+
let sourceData;
|
|
214
|
+
if (isProtoResource) {
|
|
215
|
+
// Unwrap only genuine protobuf Resource instances
|
|
216
|
+
sourceData = source.resource ?? {};
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
// Treat as plain object. If it has a top-level `resource` object (but isn't a
|
|
220
|
+
// protobuf Resource), merge both the `resource` field and any top-level
|
|
221
|
+
// `metadata` into the resource data so callers that pass plain objects keep
|
|
222
|
+
// expected semantics.
|
|
223
|
+
const srcObj = source;
|
|
224
|
+
if (srcObj &&
|
|
225
|
+
'resource' in srcObj &&
|
|
226
|
+
typeof srcObj.resource === 'object' &&
|
|
227
|
+
srcObj.resource !== null &&
|
|
228
|
+
!Array.isArray(srcObj.resource)) {
|
|
229
|
+
const resourcePart = srcObj.resource;
|
|
230
|
+
if ('metadata' in srcObj &&
|
|
231
|
+
typeof srcObj.metadata === 'object' &&
|
|
232
|
+
srcObj.metadata !== null &&
|
|
233
|
+
!Array.isArray(srcObj.metadata)) {
|
|
234
|
+
sourceData = merge.withOptions({ mergeArrays }, resourcePart, {
|
|
235
|
+
metadata: srcObj.metadata,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
sourceData = resourcePart;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
sourceData = srcObj;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
// Perform deep merge with configured array handling
|
|
247
|
+
r.resource = merge.withOptions({ mergeArrays }, r.resource, sourceData);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Get a status condition from a Kubernetes resource.
|
|
251
|
+
*
|
|
252
|
+
* This function extracts a specific status condition from a resource by type.
|
|
253
|
+
* Status conditions follow the Kubernetes standard pattern and are typically
|
|
254
|
+
* found in the resource's status.conditions array.
|
|
255
|
+
*
|
|
256
|
+
* @param resource - A Kubernetes resource object (plain JavaScript object)
|
|
257
|
+
* @param type - The type of status condition to get (e.g., "Ready", "Synced")
|
|
258
|
+
* @returns The requested status condition, or a condition with status "Unknown" if not found
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```typescript
|
|
262
|
+
* const oxr = getObservedCompositeResource(req);
|
|
263
|
+
* if (oxr?.resource) {
|
|
264
|
+
* const readyCondition = getCondition(oxr.resource, "Ready");
|
|
265
|
+
* if (readyCondition.status === "True") {
|
|
266
|
+
* console.log("Resource is ready");
|
|
267
|
+
* } else if (readyCondition.status === "False") {
|
|
268
|
+
* console.log("Resource not ready:", readyCondition.message);
|
|
269
|
+
* } else {
|
|
270
|
+
* console.log("Ready status unknown");
|
|
271
|
+
* }
|
|
272
|
+
* }
|
|
273
|
+
*
|
|
274
|
+
* // Check if a composed resource is synced
|
|
275
|
+
* const bucket = observedResources["my-bucket"];
|
|
276
|
+
* if (bucket?.resource) {
|
|
277
|
+
* const synced = getCondition(bucket.resource, "Synced");
|
|
278
|
+
* console.log("Sync status:", synced.status, synced.reason);
|
|
279
|
+
* }
|
|
280
|
+
* ```
|
|
281
|
+
*/
|
|
282
|
+
export function getCondition(resource, type) {
|
|
283
|
+
const unknown = { type, status: 'Unknown' };
|
|
284
|
+
if (!resource || !('status' in resource)) {
|
|
285
|
+
return unknown;
|
|
286
|
+
}
|
|
287
|
+
const status = resource.status;
|
|
288
|
+
if (!status || !('conditions' in status)) {
|
|
289
|
+
return unknown;
|
|
290
|
+
}
|
|
291
|
+
const conditions = status.conditions;
|
|
292
|
+
if (!Array.isArray(conditions)) {
|
|
293
|
+
return unknown;
|
|
294
|
+
}
|
|
295
|
+
for (const c of conditions) {
|
|
296
|
+
if (c.type !== type) {
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
const condition = {
|
|
300
|
+
type: String(c.type),
|
|
301
|
+
status: String(c.status),
|
|
302
|
+
};
|
|
303
|
+
if (c.message !== undefined && c.message !== null) {
|
|
304
|
+
condition.message = typeof c.message === 'string' ? c.message : JSON.stringify(c.message);
|
|
305
|
+
}
|
|
306
|
+
if (c.reason !== undefined && c.reason !== null) {
|
|
307
|
+
condition.reason = typeof c.reason === 'string' ? c.reason : JSON.stringify(c.reason);
|
|
308
|
+
}
|
|
309
|
+
if (c.lastTransitionTime !== undefined && c.lastTransitionTime !== null) {
|
|
310
|
+
condition.lastTransitionTime =
|
|
311
|
+
typeof c.lastTransitionTime === 'string'
|
|
312
|
+
? c.lastTransitionTime
|
|
313
|
+
: JSON.stringify(c.lastTransitionTime);
|
|
314
|
+
}
|
|
315
|
+
return condition;
|
|
316
|
+
}
|
|
317
|
+
return unknown;
|
|
318
|
+
}
|
|
146
319
|
//# sourceMappingURL=resource.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../../src/resource/resource.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../../src/resource/resource.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AA2DrC;;GAEG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO;QACL,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC/B,KAAK,EAAE,KAAK,CAAC,iBAAiB;KAC/B,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,QAAQ,CAAC,MAA2C;IAClE,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,EAAE,CAAC;IACZ,CAAC;IA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CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC;QAC7C,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* including setting desired state, managing results, handling context, and working with
|
|
6
6
|
* composite resources and their status.
|
|
7
7
|
*/
|
|
8
|
-
import { Resource, RunFunctionRequest, RunFunctionResponse, Ready } from '../proto/run_function.js';
|
|
8
|
+
import { Resource, RunFunctionRequest, RunFunctionResponse, Ready, ResourceSelector } from '../proto/run_function.js';
|
|
9
9
|
import { Duration } from '../proto/google/protobuf/duration.js';
|
|
10
10
|
/**
|
|
11
11
|
* Default time-to-live for function responses (60 seconds).
|
|
@@ -300,4 +300,81 @@ export declare function setDesiredCompositeResource(rsp: RunFunctionResponse, re
|
|
|
300
300
|
* ```
|
|
301
301
|
*/
|
|
302
302
|
export declare function setOutput(rsp: RunFunctionResponse, output: Record<string, unknown>): RunFunctionResponse;
|
|
303
|
+
/**
|
|
304
|
+
* Add a schema requirement to the response.
|
|
305
|
+
*
|
|
306
|
+
* This tells Crossplane to fetch the OpenAPI schema for the specified resource kind
|
|
307
|
+
* and include it in the next request's required_schemas field. Use request.getRequiredSchema
|
|
308
|
+
* to retrieve the resolved schema.
|
|
309
|
+
*
|
|
310
|
+
* For CRDs, Crossplane returns the spec.versions[].schema.openAPIV3Schema field.
|
|
311
|
+
* If Crossplane cannot find a schema for the requested kind, the schema will be
|
|
312
|
+
* empty (getRequiredSchema will return undefined with resolved true).
|
|
313
|
+
*
|
|
314
|
+
* @param rsp - The RunFunctionResponse to update
|
|
315
|
+
* @param name - A unique name to identify this schema requirement
|
|
316
|
+
* @param apiVersion - API version of the resource kind (e.g., "example.org/v1")
|
|
317
|
+
* @param kind - Kind of resource (e.g., "MyResource")
|
|
318
|
+
* @returns The updated response
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* ```typescript
|
|
322
|
+
* // Request the OpenAPI schema for an XR type
|
|
323
|
+
* rsp = requireSchema(rsp, "xr-schema", "example.org/v1", "MyResource");
|
|
324
|
+
*
|
|
325
|
+
* // In the next function invocation, retrieve the schema:
|
|
326
|
+
* const [schema, ok] = getRequiredSchema(req, "xr-schema");
|
|
327
|
+
* if (ok && schema) {
|
|
328
|
+
* console.log("Schema properties:", schema.properties);
|
|
329
|
+
* }
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
332
|
+
export declare function requireSchema(rsp: RunFunctionResponse, name: string, apiVersion: string, kind: string): RunFunctionResponse;
|
|
333
|
+
/**
|
|
334
|
+
* Add a resource requirement to the response.
|
|
335
|
+
*
|
|
336
|
+
* This tells Crossplane to fetch resources matching the selector and include them
|
|
337
|
+
* in the next request's required_resources field. Use request.getRequiredResource
|
|
338
|
+
* to retrieve the resolved resources.
|
|
339
|
+
*
|
|
340
|
+
* The selector can match resources by name or by labels. If namespace is omitted,
|
|
341
|
+
* cluster-scoped resources are matched, or namespaced resources across all namespaces
|
|
342
|
+
* when matching by labels.
|
|
343
|
+
*
|
|
344
|
+
* @param rsp - The RunFunctionResponse to update
|
|
345
|
+
* @param name - A unique name to identify this resource requirement
|
|
346
|
+
* @param selector - The resource selector specifying which resources to fetch
|
|
347
|
+
* @returns The updated response
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* ```typescript
|
|
351
|
+
* // Match a specific ConfigMap by name
|
|
352
|
+
* rsp = requireResource(rsp, "app-config", {
|
|
353
|
+
* apiVersion: "v1",
|
|
354
|
+
* kind: "ConfigMap",
|
|
355
|
+
* matchName: "my-app-config",
|
|
356
|
+
* namespace: "production"
|
|
357
|
+
* });
|
|
358
|
+
*
|
|
359
|
+
* // Match all Secrets with specific labels
|
|
360
|
+
* rsp = requireResource(rsp, "db-secrets", {
|
|
361
|
+
* apiVersion: "v1",
|
|
362
|
+
* kind: "Secret",
|
|
363
|
+
* matchLabels: {
|
|
364
|
+
* labels: {
|
|
365
|
+
* app: "database",
|
|
366
|
+
* tier: "backend"
|
|
367
|
+
* }
|
|
368
|
+
* },
|
|
369
|
+
* namespace: "production"
|
|
370
|
+
* });
|
|
371
|
+
*
|
|
372
|
+
* // In the next function invocation, retrieve the resources:
|
|
373
|
+
* const [resources, resolved, error] = getRequiredResource(req, "app-config");
|
|
374
|
+
* if (resolved && !error && resources.length > 0) {
|
|
375
|
+
* console.log("Found config:", resources[0].resource);
|
|
376
|
+
* }
|
|
377
|
+
* ```
|
|
378
|
+
*/
|
|
379
|
+
export declare function requireResource(rsp: RunFunctionResponse, name: string, selector: ResourceSelector): RunFunctionResponse;
|
|
303
380
|
//# sourceMappingURL=response.d.ts.map
|