@stream44.studio/encapsulate 0.4.0-rc.14 → 0.4.0-rc.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stream44.studio/encapsulate",
3
- "version": "0.4.0-rc.14",
3
+ "version": "0.4.0-rc.15",
4
4
  "license": "BSD-2-Clause-Patent",
5
5
  "repository": {
6
6
  "type": "git",
@@ -204,6 +204,23 @@ class MembraneContractCapsuleInstanceFactory extends ContractCapsuleInstanceFact
204
204
  }
205
205
  }
206
206
 
207
+ // Separate nested capsule-name-targeted options from own options
208
+ // Keys starting with '#' are own options for the mapped capsule
209
+ // Non-'#' keys are matched against capsule names in the mapping tree
210
+ let ownMappingOptions: Record<string, any> | undefined = undefined
211
+ let nestedCapsuleOptions: Record<string, any> | undefined = undefined
212
+ if (mappingOptions) {
213
+ for (const [key, value] of Object.entries(mappingOptions)) {
214
+ if (key.startsWith('#')) {
215
+ if (!ownMappingOptions) ownMappingOptions = {}
216
+ ownMappingOptions[key] = value
217
+ } else {
218
+ if (!nestedCapsuleOptions) nestedCapsuleOptions = {}
219
+ nestedCapsuleOptions[key] = value
220
+ }
221
+ }
222
+ }
223
+
207
224
  // Transform overrides if this mapping has a propertyContractDelegate
208
225
  let mappedOverrides = overrides
209
226
  if (property.definition.propertyContractDelegate) {
@@ -229,9 +246,21 @@ class MembraneContractCapsuleInstanceFactory extends ContractCapsuleInstanceFact
229
246
  }
230
247
  }
231
248
 
249
+ // Merge nested capsule-name-targeted options into overrides
250
+ // These will be picked up when child capsules with matching names are instantiated
251
+ if (nestedCapsuleOptions) {
252
+ mappedOverrides = { ...mappedOverrides }
253
+ for (const [capsuleNameKey, capsuleOptions] of Object.entries(nestedCapsuleOptions)) {
254
+ mappedOverrides[capsuleNameKey] = {
255
+ ...(mappedOverrides[capsuleNameKey] || {}),
256
+ ...capsuleOptions
257
+ }
258
+ }
259
+ }
260
+
232
261
  const mappedCapsuleInstance = await mappedCapsule.makeInstance({
233
262
  overrides: mappedOverrides,
234
- options: mappingOptions,
263
+ options: ownMappingOptions,
235
264
  runtimeSpineContracts: this.runtimeSpineContracts,
236
265
  rootCapsule: this.capsuleInstance?.rootCapsule
237
266
  })
@@ -214,6 +214,23 @@ export class ContractCapsuleInstanceFactory {
214
214
  }
215
215
  }
216
216
 
217
+ // Separate nested capsule-name-targeted options from own options
218
+ // Keys starting with '#' are own options for the mapped capsule
219
+ // Non-'#' keys are matched against capsule names in the mapping tree
220
+ let ownMappingOptions: Record<string, any> | undefined = undefined
221
+ let nestedCapsuleOptions: Record<string, any> | undefined = undefined
222
+ if (mappingOptions) {
223
+ for (const [key, value] of Object.entries(mappingOptions)) {
224
+ if (key.startsWith('#')) {
225
+ if (!ownMappingOptions) ownMappingOptions = {}
226
+ ownMappingOptions[key] = value
227
+ } else {
228
+ if (!nestedCapsuleOptions) nestedCapsuleOptions = {}
229
+ nestedCapsuleOptions[key] = value
230
+ }
231
+ }
232
+ }
233
+
217
234
  // Transform overrides if this mapping has a propertyContractDelegate
218
235
  let mappedOverrides = overrides
219
236
  if (property.definition.propertyContractDelegate) {
@@ -238,10 +255,22 @@ export class ContractCapsuleInstanceFactory {
238
255
  }
239
256
  }
240
257
 
258
+ // Merge nested capsule-name-targeted options into overrides
259
+ // These will be picked up when child capsules with matching names are instantiated
260
+ if (nestedCapsuleOptions) {
261
+ mappedOverrides = { ...mappedOverrides }
262
+ for (const [capsuleNameKey, capsuleOptions] of Object.entries(nestedCapsuleOptions)) {
263
+ mappedOverrides[capsuleNameKey] = {
264
+ ...(mappedOverrides[capsuleNameKey] || {}),
265
+ ...capsuleOptions
266
+ }
267
+ }
268
+ }
269
+
241
270
  const apiTarget = this.getApiTarget({ property })
242
271
  const mappedInstance = await mappedCapsule.makeInstance({
243
272
  overrides: mappedOverrides,
244
- options: mappingOptions,
273
+ options: ownMappingOptions,
245
274
  runtimeSpineContracts: this.runtimeSpineContracts,
246
275
  rootCapsule: this.capsuleInstance?.rootCapsule
247
276
  })