pmcf 6.37.2 → 6.38.1

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/src/base.mjs CHANGED
@@ -1,20 +1,14 @@
1
1
  import { join } from "node:path";
2
2
  import { stat } from "node:fs/promises";
3
- import { AggregatedMap } from "aggregated-map";
4
- import { allOutputs } from "npm-pkgbuild";
5
3
  import {
6
4
  createExpressionTransformer,
7
5
  transform
8
6
  } from "content-entry-transform";
9
7
  import { FileContentProvider } from "npm-pkgbuild";
10
8
  import {
11
- getAttribute,
12
9
  parse,
13
10
  globals,
14
- expand,
15
11
  extract,
16
- toExternal,
17
- filterPublic,
18
12
  extendingAttributeIterator,
19
13
  name_attribute_writable,
20
14
  type_attribute_writable,
@@ -22,10 +16,10 @@ import {
22
16
  string_set_attribute_writable,
23
17
  description_attribute_writable,
24
18
  boolean_attribute_writable,
25
- object_attribute
19
+ default_attribute_writable
26
20
  } from "pacc";
27
21
  import { union } from "./utils.mjs";
28
- import { addType } from "pmcf";
22
+ import { addType, Core } from "pmcf";
29
23
  import { owner_attribute, aliases_attribute } from "./common-attributes.mjs";
30
24
 
31
25
  /**
@@ -33,7 +27,7 @@ import { owner_attribute, aliases_attribute } from "./common-attributes.mjs";
33
27
  * attributes: as declared in the types
34
28
  * properties: use defined values to support attribute value definitions
35
29
  */
36
- export class Base {
30
+ export class Base extends Core {
37
31
  static name = "base";
38
32
  static key = "name";
39
33
  static priority = 0;
@@ -52,8 +46,7 @@ export class Base {
52
46
  private: true
53
47
  },
54
48
 
55
- packaging: { ...string_set_attribute_writable, name: "packaging" },
56
- // packageContentProperties: { ...object_attribute, writable: true, name: "packageContentProperties"}
49
+ content: { ...default_attribute_writable, type: "content", name: "content" }
57
50
  };
58
51
 
59
52
  static {
@@ -67,94 +60,22 @@ export class Base {
67
60
  description;
68
61
  name;
69
62
  properties = {};
70
- extends = new Set();
71
63
  _aliases = new Set();
72
64
  _tags = new Set();
73
- _packaging = new Set();
74
65
  _directory;
75
66
 
76
- constructor(owner, data) {
77
- if (owner) {
78
- this.owner = owner;
79
- }
80
- }
81
-
82
- set owner(value) {
83
- if (this === value || this === value?.owner) {
84
- this.error("Unable to own myself", value.fullName);
85
- } else {
86
- this._owner = value;
87
- }
88
- }
89
-
90
- get owner() {
91
- return this._owner;
92
- }
93
-
94
- forOwner(owner) {
95
- if (this.owner !== owner) {
96
- const newObject = Object.create(this);
97
- newObject.owner = owner;
98
- return newObject;
99
- }
100
-
101
- return this;
67
+ value(name) {
68
+ return this.attribute(name) ?? this.property(name) ?? this.named(name);
102
69
  }
103
70
 
104
71
  materializeExtends() {
105
- for (const [path, attribute] of extendingAttributeIterator(
106
- this.constructor,
107
- attribute => attribute.collection && !attribute.type.primitive
108
- )) {
109
- if (attribute.deferredExpression) {
110
- const name = attribute.name;
111
- if (!this.hasOwnProperty(name)) {
112
- for (const e of this.walkDirections(["extends"])) {
113
- if (e.hasOwnProperty(name)) {
114
- Object.defineProperty(this, name, {
115
- get: () => e[name]
116
- });
117
- break;
118
- }
119
- }
72
+ super.materializeExtends();
73
+ if (this.content) {
74
+ for (const e of this.extends) {
75
+ if (e.content) {
76
+ this.content.extends.add(e.content);
120
77
  }
121
-
122
- continue;
123
78
  }
124
-
125
- const collection = this[attribute.name];
126
-
127
- if (typeof collection?.get === "function") {
128
- for (const [name, extending] of this.mapFromDirections(
129
- ["extends"],
130
- attribute.name
131
- )) {
132
- const present = collection.get(extending.name);
133
-
134
- if (present) {
135
- present.extends.add(extending);
136
- present.materializeExtends();
137
- } else {
138
- collection.set(extending.name, extending.forOwner(this));
139
- }
140
- }
141
- } /*else {
142
- if (Array.isArray(collection)) {
143
- // TODO
144
- } else {
145
- //console.log("EXTENDS", this.fullName, attribute.name);
146
-
147
- for (const extending of this.unionFromDirections(
148
- ["extends"],
149
- attribute.name
150
- )) {
151
- if (!collection.has(extending)) {
152
- //console.log("ADD", this.fullName, extending.fullName);
153
- collection.add(extending);
154
- }
155
- }
156
- }
157
- }*/
158
79
  }
159
80
  }
160
81
 
@@ -180,184 +101,6 @@ export class Base {
180
101
  }
181
102
  }
182
103
 
183
- /**
184
- * Deliver AggregatedMap of all property Maps.
185
- * @param {string[]} directions
186
- * @param {string} property
187
- * @returns {Map<any,any>}
188
- */
189
- mapFromDirections(directions, property) {
190
- return new AggregatedMap(
191
- [...this.walkDirections(directions)]
192
- .map(node => node[property])
193
- .filter(node => node !== undefined)
194
- );
195
- }
196
-
197
- /**
198
- * Deliver union set of all property values.
199
- * @param {string[]} directions
200
- * @param {string} property
201
- * @returns {Set<any>}
202
- */
203
- unionFromDirections(directions, property) {
204
- let collected = new Set();
205
- for (const node of this.walkDirections(directions)) {
206
- const value = node[property];
207
- if (value !== undefined) {
208
- if (!(value instanceof Set)) {
209
- console.log("NO SET", value, node.fullName, property);
210
- }
211
- collected = collected.union(value);
212
- }
213
- }
214
-
215
- return collected;
216
- }
217
-
218
- get children() {
219
- const all = [];
220
-
221
- for (const [path, attribute] of extendingAttributeIterator(
222
- this.constructor,
223
- attribute => attribute.backpointer?.name === "owner"
224
- )) {
225
- const value = this[path];
226
-
227
- if (value !== undefined) {
228
- if (attribute.collection) {
229
- if (typeof value.values === "function") {
230
- all.push(...value.values());
231
- } else {
232
- if (value instanceof Iterator) {
233
- all.push(...value);
234
- } else {
235
- if (value instanceof Base) {
236
- this.error(
237
- `Unexpected scalar value for "${attribute.name}"`,
238
- value.fullName
239
- );
240
- all.push(value); // TODO should not happen
241
- } else if (typeof value === "object") {
242
- all.push(...Object.values(value));
243
- }
244
- }
245
- }
246
- } else {
247
- all.push(value);
248
- }
249
- }
250
- }
251
-
252
- return all;
253
- }
254
-
255
- /**
256
- * Walk the object graph in some directions and deliver seen nodes.
257
- * @param {string[]} directions
258
- * @return {Iterable<Base>}
259
- */
260
- *walkDirections(directions = ["this", "extends", "owner"]) {
261
- if (directions.indexOf("this") >= 0) {
262
- yield this;
263
- directions = directions.filter(d => d !== "this");
264
- }
265
-
266
- yield* this._walkDirections(directions, new Set());
267
- }
268
-
269
- *_walkDirections(directions, seen) {
270
- if (!seen.has(this)) {
271
- seen.add(this);
272
-
273
- for (const direction of directions) {
274
- const value = this[direction];
275
-
276
- if (value) {
277
- if (value[Symbol.iterator]) {
278
- for (const node of value) {
279
- yield node;
280
- yield* node._walkDirections(directions, seen);
281
- }
282
- } else {
283
- yield value;
284
- yield* value._walkDirections(directions, seen);
285
- }
286
- }
287
- }
288
- }
289
- }
290
-
291
- get typeName() {
292
- return this.constructor.name;
293
- }
294
-
295
- /**
296
- *
297
- * @param {string} name
298
- * @returns {any}
299
- */
300
- attribute(name) {
301
- for (const node of this.walkDirections(["this", "extends"])) {
302
- const value = getAttribute(node, name);
303
- if (value !== undefined) {
304
- return this.expand(value);
305
- }
306
- }
307
- }
308
-
309
- /**
310
- * Retrive attribute values from an object.
311
- * @param {Function} [filter]
312
- * @return {Iterable<[string,any]>} values
313
- */
314
- *attributeIterator(filter) {
315
- for (const [path, attribute] of extendingAttributeIterator(
316
- this.constructor,
317
- filter
318
- )) {
319
- const name = path.join(".");
320
- const value = this.attribute(name);
321
-
322
- if (value !== undefined) {
323
- yield [
324
- attribute.externalName ?? name,
325
- toExternal(value, attribute),
326
- path,
327
- attribute
328
- ];
329
- }
330
- }
331
- }
332
-
333
- /**
334
- * Retrive attribute values from an object.
335
- * @param {Function} [filter]
336
- * @return {Object} values
337
- */
338
- getAttributes(filter = filterPublic) {
339
- return Object.fromEntries(this.attributeIterator(filter));
340
- }
341
-
342
- value(name) {
343
- return this.attribute(name) ?? this.property(name) ?? this.named(name);
344
- }
345
-
346
- /**
347
- *
348
- * @param {string} name
349
- * @returns {any}
350
- */
351
- property(name) {
352
- for (const node of this.walkDirections()) {
353
- const value = node.properties[name];
354
-
355
- if (value !== undefined) {
356
- return this.expand(value);
357
- }
358
- }
359
- }
360
-
361
104
  get root() {
362
105
  return this.owner?.root;
363
106
  }
@@ -442,22 +185,6 @@ export class Base {
442
185
  return this.expression("services[types[smtp]][0]");
443
186
  }
444
187
 
445
- /**
446
- *
447
- * @param {string} expression
448
- * @param {object} options
449
- * @returns {any}
450
- */
451
- expression(expression, options) {
452
- return parse(expression, {
453
- root: this.root,
454
- current: this,
455
- valueFor: (name, at) =>
456
- typeof at?.value === "function" ? at.value(name) : globals[name],
457
- ...options
458
- });
459
- }
460
-
461
188
  get services() {
462
189
  return this.owner?.services || new Map();
463
190
  }
@@ -479,28 +206,6 @@ export class Base {
479
206
  return this.owner ? join(this.owner.fullName, "/", this.name) : this.name;
480
207
  }
481
208
 
482
- get derivedPackaging() {
483
- return this.owner?.packaging;
484
- }
485
-
486
- set packaging(value) {
487
- this._packaging = union(value, this._packaging);
488
- }
489
-
490
- get packaging() {
491
- const dp = this.derivedPackaging;
492
-
493
- if (dp) {
494
- return this._packaging.union(dp);
495
- }
496
-
497
- return this._packaging;
498
- }
499
-
500
- get outputs() {
501
- return new Set(allOutputs.filter(o => this.packaging.has(o.name)));
502
- }
503
-
504
209
  get systemUserName() {
505
210
  return this.constructor.name;
506
211
  }
@@ -509,36 +214,16 @@ export class Base {
509
214
  return this.constructor.name;
510
215
  }
511
216
 
512
- get packageContentPermissions() {
513
- const owner = this.systemUserName;
514
- const group = this.systemGroupName;
515
- return [
516
- {
517
- mode: 0o644,
518
- owner,
519
- group
520
- },
521
- {
522
- mode: 0o755,
523
- owner,
524
- group
525
- }
526
- ];
527
- }
528
-
529
217
  get packageData() {
530
- const nameParts = [this.typeName, this.owner?.name, this.name];
531
- return {
532
- sources: [],
533
- outputs: this.outputs,
534
- properties: {
535
- name: nameParts.filter(n => n !== undefined && n.length > 0).join("-"),
536
- description: `${this.type} definitions for ${this.fullName}`,
537
- access: "private",
538
- dependencies: this.depends,
539
- groups: [this.typeName]
218
+ if (!this.content) {
219
+ for (const e of this.walkDirections(["extends"])) {
220
+ if (e.content) {
221
+ this.content = e.content.forOwner(this);
222
+ break;
223
+ }
540
224
  }
541
- };
225
+ }
226
+ return this.content?.packageData(this);
542
227
  }
543
228
 
544
229
  async *preparePackages(stagingDir) {}
@@ -600,32 +285,12 @@ export class Base {
600
285
  * @return {boolean}
601
286
  */
602
287
  get isTemplate() {
603
- //console.log("T", this.name, this.owner?.name, this.owner?.owner?.name);
604
288
  return (
605
289
  this.template ??
606
290
  (this.name?.indexOf("*") >= 0 || this.owner?.isTemplate || false)
607
291
  );
608
292
  }
609
293
 
610
- /**
611
- *
612
- * @param {any} object
613
- * @returns {any}
614
- */
615
- expand(object) {
616
- if (this.isTemplate || object instanceof Base) {
617
- return object;
618
- }
619
-
620
- return expand(object, {
621
- stopClass: Base,
622
- root: this.root,
623
- current: this,
624
- valueFor: (name, at) =>
625
- typeof at?.value === "function" ? at.value(name) : globals[name]
626
- });
627
- }
628
-
629
294
  error(...args) {
630
295
  console.error(`${this.toString()}:`, ...args);
631
296
  }
package/src/content.mjs CHANGED
@@ -3,18 +3,29 @@ import {
3
3
  string_set_attribute_writable,
4
4
  default_collection_attribute_writable
5
5
  } from "pacc";
6
- import { Base, addType } from "pmcf";
6
+ import { allOutputs } from "npm-pkgbuild";
7
+ import { Core, addType } from "pmcf";
8
+ import { union } from "./utils.mjs";
7
9
 
8
- export class permission extends Base {
10
+ export class permission extends Core {
11
+ static priority = 1.9;
9
12
  static attributes = {
10
13
  pattern: { ...string_attribute_writable, key: true, name: "pattern" },
11
14
  user: { ...string_attribute_writable, name: "user" },
12
15
  group: { ...string_attribute_writable, name: "group" },
13
16
  mode: { ...string_attribute_writable, name: "mode" }
14
17
  };
18
+
19
+ static {
20
+ addType(this);
21
+ }
22
+
23
+ get name() {
24
+ return this.pattern;
25
+ }
15
26
  }
16
27
 
17
- export class content extends Base {
28
+ export class content extends Core {
18
29
  static priority = 1.9;
19
30
  static attributes = {
20
31
  permissions: {
@@ -22,21 +33,63 @@ export class content extends Base {
22
33
  type: permission,
23
34
  name: "permissions"
24
35
  },
36
+ access: {
37
+ ...string_attribute_writable,
38
+ name: "access",
39
+ default: "private"
40
+ },
25
41
  replaces: { ...string_set_attribute_writable, name: "replaces" },
26
42
  depends: { ...string_set_attribute_writable, name: "depends" },
27
43
  provides: { ...string_set_attribute_writable, name: "provides" },
28
- optional: { ...string_set_attribute_writable, name: "optional" }
44
+ optional: { ...string_set_attribute_writable, name: "optional" },
45
+ groups: { ...string_set_attribute_writable, name: "groups" },
46
+ backup: { ...string_set_attribute_writable, name: "backup" },
47
+ packaging: { ...string_set_attribute_writable, name: "packaging" }
29
48
  };
30
49
 
31
50
  static {
32
51
  addType(this);
33
52
  }
34
53
 
35
- permissions = new Map();
54
+ _permissions = new Map();
55
+ _packaging = new Set();
36
56
  _provides = new Set();
37
57
  _replaces = new Set();
38
58
  _depends = new Set();
39
59
  _optional = new Set();
60
+ _groups = new Set();
61
+
62
+ get name() {
63
+ return "content";
64
+ }
65
+
66
+ value(name) {
67
+ // console.log("CONTENT VALUE", this.name, this.owner.fullName, name, this.owner.name);
68
+ return this.owner.value(name) ?? super.value(name);
69
+ }
70
+
71
+ /**
72
+ * @return {string}
73
+ */
74
+ get access() {
75
+ return this.attribute("_access");
76
+ }
77
+
78
+ set access(value) {
79
+ this._access = value;
80
+ }
81
+
82
+ set packaging(value) {
83
+ this._packaging = union(value, this._packaging);
84
+ }
85
+
86
+ get packaging() {
87
+ return this.unionFromDirections(["this", "extends"], "_packaging")
88
+ }
89
+
90
+ get outputs() {
91
+ return new Set(allOutputs.filter(o => this.packaging.has(o.name)));
92
+ }
40
93
 
41
94
  set provides(value) {
42
95
  this._provides = union(value, this._provides);
@@ -77,4 +130,67 @@ export class content extends Base {
77
130
  this.unionFromDirections(["this", "extends"], "_optional")
78
131
  );
79
132
  }
133
+
134
+ set groups(value) {
135
+ this._groups = union(value, this._groups);
136
+ }
137
+
138
+ get groups() {
139
+ return this.expand(
140
+ this.unionFromDirections(["this", "extends"], "_groups")
141
+ );
142
+ }
143
+
144
+ set backup(value) {
145
+ this._backup = union(value, this._backup);
146
+ }
147
+
148
+ get backup() {
149
+ return this.expand(
150
+ this.unionFromDirections(["this", "extends"], "_backup")
151
+ );
152
+ }
153
+
154
+ get permissions() {
155
+ const p = this.mapFromDirections(["this", "extends"], "_permissions");
156
+
157
+ return p;
158
+
159
+ /*
160
+ const owner = this.systemUserName;
161
+ const group = this.systemGroupName;
162
+ return [
163
+ {
164
+ mode: 0o644,
165
+ owner,
166
+ group
167
+ },
168
+ {
169
+ mode: 0o755,
170
+ owner,
171
+ group
172
+ }
173
+ ];
174
+ */
175
+ }
176
+
177
+ packageData(node) {
178
+ const nameParts = [node.typeName, node.owner?.name, node.name];
179
+
180
+ return {
181
+ sources: [],
182
+ outputs: this.outputs,
183
+ properties: {
184
+ name: nameParts.filter(n => n !== undefined && n.length > 0).join("-"),
185
+ description: `${node.type} definitions for ${node.fullName}`,
186
+ access: this.access,
187
+ groups: [node.typeName, ...this.groups],
188
+ depends: [...this.depends],
189
+ provides: [...this.provides],
190
+ replaces: [...this.replaces],
191
+ optional: [...this.optional],
192
+ backup: [...this.backup]
193
+ }
194
+ };
195
+ }
80
196
  }
@@ -282,8 +282,9 @@ export class CoreService extends Base {
282
282
  const pd = this.packageData;
283
283
 
284
284
  pd.sources = await Array.fromAsync(
285
- this.templateContent(...this.packageContentPermissions)
285
+ this.templateContent(this.content.permissions)
286
286
  );
287
+
287
288
  if (pd.sources.length) {
288
289
  yield pd;
289
290
  }