pmcf 4.6.2 → 4.8.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "4.6.2",
3
+ "version": "4.8.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -60,7 +60,7 @@
60
60
  "package-directory": "^8.1.0"
61
61
  },
62
62
  "devDependencies": {
63
- "@types/node": "^25.0.8",
63
+ "@types/node": "^25.0.9",
64
64
  "ava": "^6.4.1",
65
65
  "c8": "^10.1.3",
66
66
  "documentation": "^14.0.3",
package/src/base.mjs CHANGED
@@ -310,29 +310,35 @@ export class Base {
310
310
  return this.owner.addObject(object);
311
311
  }
312
312
 
313
- *_allExtends(all) {
314
- for (const e of this.extends) {
315
- if (!all.has(e)) {
316
- all.add(e);
317
- yield e;
318
- yield* e._allExtends(all);
319
- }
320
- }
313
+ *walkDirections(directions = ["this", "extends", "owner"]) {
314
+ yield* this._walkDirections(
315
+ directions,
316
+ directions.indexOf("this") >= 0,
317
+ new Set()
318
+ );
321
319
  }
322
320
 
323
- *allExtends() {
324
- yield* this._allExtends(new Set());
325
- }
321
+ *_walkDirections(directions, withThis, seen) {
322
+ if (!seen.has(this)) {
323
+ seen.add(this);
326
324
 
327
- *owners() {
328
- if (this.owner) {
329
- yield* this.owner.thisAndOwners();
330
- }
331
- }
325
+ if (withThis) {
326
+ yield this;
327
+ }
328
+ for (const direction of directions) {
329
+ const value = this[direction];
332
330
 
333
- *thisAndOwners() {
334
- yield this;
335
- yield* this.owners();
331
+ if (value) {
332
+ if (value[Symbol.iterator]) {
333
+ for (const node of value) {
334
+ yield* node._walkDirections(directions, true, seen);
335
+ }
336
+ } else {
337
+ yield* value._walkDirections(directions, true, seen);
338
+ }
339
+ }
340
+ }
341
+ }
336
342
  }
337
343
 
338
344
  forOwner(owner) {
@@ -361,49 +367,20 @@ export class Base {
361
367
  return this.constructor.typeDefinition.name;
362
368
  }
363
369
 
364
- *_extendedPropertyIterator(propertyName, seen) {
365
- if (!seen.has(this)) {
366
- seen.add(this);
367
-
368
- const value = getAttribute(this, propertyName);
370
+ /**
371
+ *
372
+ * @param {string} name
373
+ * @returns {any}
374
+ */
375
+ extendedAttribute(name) {
376
+ for (const node of this.walkDirections(["this", "extends"])) {
377
+ const value = getAttribute(node, name);
369
378
  if (value !== undefined) {
370
- yield value;
371
- } else {
372
- const value = this._properties?.[propertyName];
373
- if (value !== undefined) {
374
- yield value;
375
- }
376
- }
377
-
378
- for (const e of this.allExtends()) {
379
- yield* e._extendedPropertyIterator(propertyName, seen);
380
- }
381
- }
382
- }
383
-
384
- _extendedProperty(propertyName, seen) {
385
- if (!seen.has(this)) {
386
- seen.add(this);
387
- for (const e of this.allExtends()) {
388
- const value =
389
- getAttribute(e, propertyName) ??
390
- e._extendedProperty(propertyName, seen);
391
- if (value !== undefined) {
392
- return value;
393
- }
379
+ return value;
394
380
  }
395
381
  }
396
382
  }
397
383
 
398
- extendedProperty(propertyName) {
399
- const value = getAttribute(this, propertyName);
400
- if (value !== undefined) {
401
- return value;
402
- }
403
-
404
- return this._extendedProperty(propertyName, new Set());
405
- }
406
-
407
384
  /**
408
385
  * Retrive attribute values from an object.
409
386
  * @param {Function} [filter]
@@ -420,7 +397,7 @@ export class Base {
420
397
  filter
421
398
  )) {
422
399
  const name = path.join(".");
423
- const value = this.extendedProperty(name);
400
+ const value = this.extendedAttribute(name);
424
401
 
425
402
  if (value !== undefined) {
426
403
  yield [def.externalName ?? name, toExternal(value, def), path, def];
@@ -581,15 +558,16 @@ export class Base {
581
558
  )
582
559
  ];
583
560
 
584
- return [...this.allExtends(), this].map(e => {
585
- const dir = join(e.directory, "content") + "/";
586
- console.log("DIR", dir);
587
-
588
- return transform(
589
- new FileContentProvider(dir, entryProperties, directoryProperties),
561
+ return [...this.walkDirections(["this", "extends"])].map(e =>
562
+ transform(
563
+ new FileContentProvider(
564
+ { dir: join(e.directory, "content"), pattern: "**/*" },
565
+ entryProperties,
566
+ directoryProperties
567
+ ),
590
568
  transformers
591
- );
592
- });
569
+ )
570
+ );
593
571
  }
594
572
 
595
573
  get tags() {
@@ -609,21 +587,21 @@ export class Base {
609
587
  }
610
588
 
611
589
  getGlobal(a) {
612
- return globals[a] ?? this.property(a);
590
+ return globals[a] ?? this.extendedAttribute(a) ?? this.property(a);
613
591
  }
614
592
 
615
593
  get properties() {
616
594
  return this._properties;
617
595
  }
618
596
 
597
+ /**
598
+ *
599
+ * @param {string} name
600
+ * @returns {any}
601
+ */
619
602
  property(name) {
620
- let value = this._properties?.[name];
621
- if (value !== undefined) {
622
- return value;
623
- }
624
-
625
- for (const o of this.owners()) {
626
- const value = o.property(name);
603
+ for (const node of this.walkDirections(["this", "extends", "owner"])) {
604
+ const value = node._properties?.[name];
627
605
  if (value !== undefined) {
628
606
  return value;
629
607
  }
package/src/host.mjs CHANGED
@@ -143,7 +143,7 @@ export class Host extends ServiceOwner {
143
143
  }
144
144
 
145
145
  get serial() {
146
- return this.extendedProperty("_serial");
146
+ return this.extendedAttribute("_serial");
147
147
  }
148
148
 
149
149
  set deployment(value) {
@@ -151,7 +151,7 @@ export class Host extends ServiceOwner {
151
151
  }
152
152
 
153
153
  get deployment() {
154
- return this.extendedProperty("_deployment");
154
+ return this.extendedAttribute("_deployment");
155
155
  }
156
156
 
157
157
  set chassis(value) {
@@ -159,7 +159,7 @@ export class Host extends ServiceOwner {
159
159
  }
160
160
 
161
161
  get chassis() {
162
- return this.extendedProperty("_chassis");
162
+ return this.extendedAttribute("_chassis");
163
163
  }
164
164
 
165
165
  set vendor(value) {
@@ -167,7 +167,7 @@ export class Host extends ServiceOwner {
167
167
  }
168
168
 
169
169
  get vendor() {
170
- return this.extendedProperty("_vendor");
170
+ return this.extendedAttribute("_vendor");
171
171
  }
172
172
 
173
173
  set keymap(value) {
@@ -175,7 +175,7 @@ export class Host extends ServiceOwner {
175
175
  }
176
176
 
177
177
  get keymap() {
178
- return this.extendedProperty("_keymap");
178
+ return this.extendedAttribute("_keymap");
179
179
  }
180
180
 
181
181
  set architecture(value) {
@@ -183,7 +183,7 @@ export class Host extends ServiceOwner {
183
183
  }
184
184
 
185
185
  get architecture() {
186
- return this.extendedProperty("_architecture");
186
+ return this.extendedAttribute("_architecture");
187
187
  }
188
188
 
189
189
  get derivedPackaging() {
@@ -261,7 +261,7 @@ export class Host extends ServiceOwner {
261
261
  }
262
262
 
263
263
  get os() {
264
- return this.extendedProperty("_os");
264
+ return this.extendedAttribute("_os");
265
265
  }
266
266
 
267
267
  set distribution(value) {
@@ -269,7 +269,7 @@ export class Host extends ServiceOwner {
269
269
  }
270
270
 
271
271
  get distribution() {
272
- return this.extendedProperty("_distribution");
272
+ return this.extendedAttribute("_distribution");
273
273
  }
274
274
 
275
275
  get modelName() {
@@ -126,7 +126,7 @@ export class NetworkInterface extends SkeletonNetworkInterface {
126
126
  }
127
127
 
128
128
  get hostName() {
129
- return this.extendedProperty("_hostName") ?? this.host.hostName;
129
+ return this.extendedAttribute("_hostName") ?? this.host.hostName;
130
130
  }
131
131
 
132
132
  set hostName(value) {
@@ -147,7 +147,7 @@ export class NetworkInterface extends SkeletonNetworkInterface {
147
147
 
148
148
  get scope() {
149
149
  return (
150
- this.extendedProperty("_scope") ??
150
+ this.extendedAttribute("_scope") ??
151
151
  this.network?.scope ??
152
152
  networkAttributes.scope.default
153
153
  );
@@ -158,7 +158,7 @@ export class NetworkInterface extends SkeletonNetworkInterface {
158
158
  }
159
159
 
160
160
  get hwaddr() {
161
- return this.extendedProperty("_hwaddr");
161
+ return this.extendedAttribute("_hwaddr");
162
162
  }
163
163
 
164
164
  set metric(value) {
@@ -167,7 +167,7 @@ export class NetworkInterface extends SkeletonNetworkInterface {
167
167
 
168
168
  get metric() {
169
169
  return (
170
- this.extendedProperty("_metric") ??
170
+ this.extendedAttribute("_metric") ??
171
171
  this.network?.metric ??
172
172
  networkAttributes.metric.default
173
173
  );
@@ -178,7 +178,7 @@ export class NetworkInterface extends SkeletonNetworkInterface {
178
178
  }
179
179
 
180
180
  get mtu() {
181
- return this.extendedProperty("_mtu"); // ?? networkAttributes.mtu.default;
181
+ return this.extendedAttribute("_mtu"); // ?? networkAttributes.mtu.default;
182
182
  }
183
183
 
184
184
  set class(value) {
@@ -186,7 +186,7 @@ export class NetworkInterface extends SkeletonNetworkInterface {
186
186
  }
187
187
 
188
188
  get class() {
189
- return this.extendedProperty("_class") ?? this.network?.class;
189
+ return this.extendedAttribute("_class") ?? this.network?.class;
190
190
  }
191
191
 
192
192
  set kind(value) {
@@ -194,7 +194,7 @@ export class NetworkInterface extends SkeletonNetworkInterface {
194
194
  }
195
195
 
196
196
  get kind() {
197
- return this.extendedProperty("_kind") ?? this.network?.kind;
197
+ return this.extendedAttribute("_kind") ?? this.network?.kind;
198
198
  }
199
199
 
200
200
  async systemdDefinitions(packageData) {
@@ -52,7 +52,7 @@ export class SkeletonNetworkInterface extends ServiceOwner {
52
52
  }
53
53
 
54
54
  get network() {
55
- return this.extendedProperty("_network") ?? this.host?.network;
55
+ return this.extendedAttribute("_network") ?? this.host?.network;
56
56
  }
57
57
 
58
58
  set network(network) {
@@ -52,7 +52,7 @@ export class WLANNetworkInterface extends EthernetNetworkInterface {
52
52
 
53
53
  get secretName() {
54
54
  return (
55
- this.extendedProperty("_secretName") ??
55
+ this.extendedAttribute("_secretName") ??
56
56
  this.network?.secretName ??
57
57
  `${this.network.name}.password`
58
58
  );
@@ -63,7 +63,7 @@ export class WLANNetworkInterface extends EthernetNetworkInterface {
63
63
  }
64
64
 
65
65
  get ssid() {
66
- return this.extendedProperty("_ssid") ?? this.network?.ssid;
66
+ return this.extendedAttribute("_ssid") ?? this.network?.ssid;
67
67
  }
68
68
 
69
69
  set psk(value) {
@@ -71,7 +71,7 @@ export class WLANNetworkInterface extends EthernetNetworkInterface {
71
71
  }
72
72
 
73
73
  get psk() {
74
- return this.extendedProperty("_psk") ?? this.network?.psk;
74
+ return this.extendedAttribute("_psk") ?? this.network?.psk;
75
75
  }
76
76
 
77
77
  async systemdDefinitions(packageData) {
package/src/service.mjs CHANGED
@@ -218,7 +218,7 @@ export class Service extends Base {
218
218
  }
219
219
 
220
220
  get alias() {
221
- return this.extendedProperty("_alias");
221
+ return this.extendedAttribute("_alias");
222
222
  }
223
223
 
224
224
  set port(value) {
@@ -234,7 +234,7 @@ export class Service extends Base {
234
234
  }
235
235
 
236
236
  get weight() {
237
- return this.extendedProperty("_weight") ?? this.owner.weight ?? 1;
237
+ return this.extendedAttribute("_weight") ?? this.owner.weight ?? 1;
238
238
  }
239
239
 
240
240
  set type(value) {
@@ -251,7 +251,7 @@ export class Service extends Base {
251
251
 
252
252
  get systemdService() {
253
253
  return (
254
- this.extendedProperty("_systemdService") ??
254
+ this.extendedAttribute("_systemdService") ??
255
255
  ServiceTypes[this.type]?.systemdService
256
256
  );
257
257
  }
package/types/base.d.mts CHANGED
@@ -60,17 +60,18 @@ export class Base {
60
60
  named(name: any): void;
61
61
  typeNamed(typeName: any, name: any): any;
62
62
  addObject(object: any): any;
63
- _allExtends(all: any): Generator<any, void, any>;
64
- allExtends(): Generator<any, void, any>;
65
- owners(): any;
66
- thisAndOwners(): any;
63
+ walkDirections(directions?: string[]): Generator<any, void, any>;
64
+ _walkDirections(directions: any, withThis: any, seen: any): Generator<any, void, any>;
67
65
  forOwner(owner: any): any;
68
66
  isNamed(name: any): boolean;
69
67
  relativeName(name: any): any;
70
68
  get typeName(): any;
71
- _extendedPropertyIterator(propertyName: any, seen: any): Generator<any, void, any>;
72
- _extendedProperty(propertyName: any, seen: any): any;
73
- extendedProperty(propertyName: any): any;
69
+ /**
70
+ *
71
+ * @param {string} name
72
+ * @returns {any}
73
+ */
74
+ extendedAttribute(name: string): any;
74
75
  /**
75
76
  * Retrive attribute values from an object.
76
77
  * @param {Function} [filter]
@@ -129,7 +130,12 @@ export class Base {
129
130
  get isTemplate(): any;
130
131
  getGlobal(a: any): any;
131
132
  get properties(): any;
132
- property(name: any): any;
133
+ /**
134
+ *
135
+ * @param {string} name
136
+ * @returns {any}
137
+ */
138
+ property(name: string): any;
133
139
  /**
134
140
  *
135
141
  * @param {any} object