pmcf 3.9.2 → 3.10.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": "3.9.2",
3
+ "version": "3.10.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -53,7 +53,7 @@
53
53
  "dependencies": {
54
54
  "ip-utilties": "^1.4.9",
55
55
  "npm-pkgbuild": "^18.2.30",
56
- "pacc": "^4.15.1",
56
+ "pacc": "^4.16.0",
57
57
  "package-directory": "^8.1.0"
58
58
  },
59
59
  "devDependencies": {
package/src/base.mjs CHANGED
@@ -2,6 +2,7 @@ import { join } from "node:path";
2
2
  import { allOutputs } from "npm-pkgbuild";
3
3
  import {
4
4
  getAttribute,
5
+ baseTypes,
5
6
  name_attribute_writable,
6
7
  string_attribute,
7
8
  string_attribute_writable,
@@ -10,7 +11,7 @@ import {
10
11
  description_attribute,
11
12
  boolean_attribute_writable
12
13
  } from "pacc";
13
- import { addType, primitives, typeFactory } from "./types.mjs";
14
+ import { addType, typeFactory } from "./types.mjs";
14
15
  import { asArray } from "./utils.mjs";
15
16
 
16
17
  const BaseTypeDefinition = {
@@ -90,24 +91,22 @@ export class Base {
90
91
  return this;
91
92
  }
92
93
 
93
- read(data, type=this.constructor.typeDefinition) {
94
- if(type.extends) {
94
+ read(data, type = this.constructor.typeDefinition) {
95
+ if (type.extends) {
95
96
  this.read(data, type.extends);
96
97
  }
97
98
 
98
- const assign = (name, property, value) => {
99
- if (value === undefined && property.default !== undefined) {
100
- value = property.default;
101
- }
99
+ const assign = (name, attribute, value) => {
100
+ value ??= attribute.default;
102
101
 
103
102
  if (value !== undefined) {
104
- if (property.values) {
105
- if (property.values.indexOf(value) < 0) {
106
- this.error(name, "unknown value", value, property.values);
103
+ if (attribute.values) {
104
+ if (attribute.values.indexOf(value) < 0) {
105
+ this.error(name, "unknown value", value, attribute.values);
107
106
  }
108
107
  }
109
108
 
110
- if (property.collection) {
109
+ if (attribute.collection) {
111
110
  const current = this[name];
112
111
 
113
112
  switch (typeof current) {
@@ -143,9 +142,9 @@ export class Base {
143
142
  }
144
143
  };
145
144
 
146
- const instantiateAndAssign = (name, property, value) => {
147
- if (primitives.has(property.type[0])) {
148
- assign(name, property, value);
145
+ const instantiateAndAssign = (name, attribute, value) => {
146
+ if (baseTypes.has(attribute.type[0])) {
147
+ assign(name, attribute, value);
149
148
  return;
150
149
  }
151
150
 
@@ -163,7 +162,7 @@ export class Base {
163
162
  {
164
163
  let object;
165
164
 
166
- for (const type of property.type) {
165
+ for (const type of attribute.type) {
167
166
  object = this.typeNamed(type.name, value);
168
167
  if (object) {
169
168
  break;
@@ -171,11 +170,11 @@ export class Base {
171
170
  }
172
171
 
173
172
  if (object) {
174
- assign(name, property, object);
173
+ assign(name, attribute, object);
175
174
  } else {
176
- if (property.type[0].constructWithIdentifierOnly) {
177
- object = new property.type[0].clazz(
178
- this.ownerFor(property, value),
175
+ if (attribute.type[0].constructWithIdentifierOnly) {
176
+ object = new attribute.type[0].clazz(
177
+ this.ownerFor(attribute, value),
179
178
  value
180
179
  );
181
180
  object.read(value);
@@ -184,14 +183,14 @@ export class Base {
184
183
  this.finalize(() => {
185
184
  value = this.expand(value);
186
185
 
187
- for (const type of property.type) {
186
+ for (const type of attribute.type) {
188
187
  const object =
189
188
  this.typeNamed(type.name, value) ||
190
189
  this.owner.typeNamed(type.name, value) ||
191
190
  this.root.typeNamed(type.name, value); // TODO
192
191
 
193
192
  if (object) {
194
- assign(name, property, object);
193
+ assign(name, attribute, object);
195
194
  return;
196
195
  }
197
196
  }
@@ -199,7 +198,7 @@ export class Base {
199
198
  this.error(
200
199
  "Not found",
201
200
  name,
202
- property.type.map(t => t.name),
201
+ attribute.type.map(t => t.name),
203
202
  value
204
203
  );
205
204
  });
@@ -208,15 +207,15 @@ export class Base {
208
207
  }
209
208
  break;
210
209
  case "object":
211
- if (value instanceof property.type[0].clazz) {
212
- assign(name, property, value);
210
+ if (value instanceof attribute.type[0].clazz) {
211
+ assign(name, attribute, value);
213
212
  } else {
214
213
  assign(
215
214
  name,
216
- property,
215
+ attribute,
217
216
  typeFactory(
218
- property.type[0],
219
- this.ownerFor(property, value),
217
+ attribute.type[0],
218
+ this.ownerFor(attribute, value),
220
219
  value
221
220
  )
222
221
  );
@@ -229,32 +228,32 @@ export class Base {
229
228
  this._properties = data.properties;
230
229
  }
231
230
 
232
- for (const [name, property] of Object.entries(type.properties)) {
233
- if (property.writable) {
231
+ for (const [name, attribute] of Object.entries(type.properties)) {
232
+ if (attribute.writable) {
234
233
  const value = this.expand(data[name]);
235
234
 
236
- if (property.collection) {
235
+ if (attribute.collection) {
237
236
  if (typeof value === "object") {
238
237
  if (Array.isArray(value)) {
239
238
  for (const v of value) {
240
- instantiateAndAssign(name, property, v);
239
+ instantiateAndAssign(name, attribute, v);
241
240
  }
242
241
  } else {
243
242
  if (value instanceof Base) {
244
- assign(name, property, value);
243
+ assign(name, attribute, value);
245
244
  } else {
246
245
  for (const [objectName, objectData] of Object.entries(value)) {
247
246
  if (typeof objectData === "object") {
248
247
  objectData[type.identifier.name] = objectName;
249
248
  }
250
- instantiateAndAssign(name, property, objectData);
249
+ instantiateAndAssign(name, attribute, objectData);
251
250
  }
252
251
  }
253
252
  }
254
253
  continue;
255
254
  }
256
255
  }
257
- instantiateAndAssign(name, property, value);
256
+ instantiateAndAssign(name, attribute, value);
258
257
  }
259
258
  }
260
259
  }
@@ -1,5 +1,6 @@
1
1
  import { addType } from "./types.mjs";
2
2
  import { Service, ServiceTypeDefinition } from "./service.mjs";
3
+ import { networkAddressType } from "pmcf";
3
4
 
4
5
  export const ExtraSourceServiceTypeDefinition = {
5
6
  name: "extra-source-service",
@@ -7,7 +8,7 @@ export const ExtraSourceServiceTypeDefinition = {
7
8
  extends: ServiceTypeDefinition,
8
9
  priority: 0.1,
9
10
  properties: {
10
- source: { type: "network", collection: true, writable: true }
11
+ source: { type: networkAddressType, collection: true, writable: true }
11
12
  }
12
13
  };
13
14
 
@@ -6,6 +6,8 @@ import {
6
6
  boolean_attribute_writable
7
7
  } from "pacc";
8
8
 
9
+ export const networkAddressType = ["network", "host", "network_interface"];
10
+
9
11
  export const networkProperties = {
10
12
  scope: {
11
13
  ...string_attribute_writable,
@@ -4,7 +4,6 @@ import { FileContentProvider } from "npm-pkgbuild";
4
4
  import { isLinkLocal, reverseArpa } from "ip-utilties";
5
5
  import {
6
6
  string_attribute_writable,
7
- string_collection_attribute,
8
7
  boolean_attribute_writable_true,
9
8
  boolean_attribute_writable_false,
10
9
  number_attribute,
@@ -17,14 +16,12 @@ import {
17
16
  dnsRecordTypeForAddressFamily,
18
17
  sortZoneRecords
19
18
  } from "../dns-utils.mjs";
20
- import { ExtraSourceService, serviceEndpoints, addresses } from "pmcf";
19
+ import { ExtraSourceService, serviceEndpoints, addresses, networkAddressType } from "pmcf";
21
20
  import { addType } from "../types.mjs";
22
21
  import { Service, ServiceTypeDefinition } from "../service.mjs";
23
22
  import { ExtraSourceServiceTypeDefinition } from "../extra-source-service.mjs";
24
23
  import { addHook } from "../hooks.mjs";
25
24
 
26
- const address_types = ["network", "host", "network_interface"];
27
-
28
25
  const BindServiceTypeDefinition = {
29
26
  name: "bind",
30
27
  specializationOf: ServiceTypeDefinition,
@@ -33,17 +30,17 @@ const BindServiceTypeDefinition = {
33
30
  priority: 0.1,
34
31
  properties: {
35
32
  addresses: {
36
- type: ["network", "host", "network_interface", "location", "owner"],
33
+ type: [...networkAddressType, "location", "owner"],
37
34
  collection: true,
38
35
  writable: true
39
36
  },
40
37
  trusted: {
41
- type: address_types,
38
+ type: networkAddressType,
42
39
  collection: true,
43
40
  writable: true
44
41
  },
45
- protected: { type: address_types, collection: true, writable: true },
46
- internal: { type: address_types, collection: true, writable: true },
42
+ protected: { type: networkAddressType, collection: true, writable: true },
43
+ internal: { type: networkAddressType, collection: true, writable: true },
47
44
  hasSVRRecords: boolean_attribute_writable_false,
48
45
  hasCatalog: boolean_attribute_writable_true,
49
46
  hasLinkLocalAdresses: boolean_attribute_writable_false,
@@ -51,7 +48,7 @@ const BindServiceTypeDefinition = {
51
48
  excludeInterfaceKinds: {
52
49
  ...string_collection_attribute_writable
53
50
  },
54
- exclude: { type: address_types, collection: true, writable: true },
51
+ exclude: { type: networkAddressType, collection: true, writable: true },
55
52
  notify: boolean_attribute_writable_false,
56
53
  recordTTL: { ...string_attribute_writable },
57
54
  serial: { ...number_attribute, writable: true },
package/src/types.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { baseTypes } from "pacc";
1
2
  import { asArray } from "./utils.mjs";
2
3
  import { addServiceTypes } from "./service-types.mjs";
3
4
 
@@ -19,8 +20,6 @@ export function addType(clazz) {
19
20
  type.clazz = clazz;
20
21
  }
21
22
 
22
- export const primitives = new Set(["string", "number", "boolean"]);
23
-
24
23
  export function resolveTypeLinks() {
25
24
  for (const type of Object.values(types)) {
26
25
  type.owners = type.owners.map(owner =>
@@ -37,7 +36,7 @@ export function resolveTypeLinks() {
37
36
 
38
37
  for (const type of asArray(property.type)) {
39
38
  if (typeof type === "string") {
40
- if (primitives.has(type)) {
39
+ if (baseTypes.has(type)) {
41
40
  ts.push(type);
42
41
  } else {
43
42
  const t = types[type];
@@ -60,7 +59,7 @@ export function resolveTypeLinks() {
60
59
 
61
60
  /*
62
61
  if (typeof property.type === "string") {
63
- if (!primitives.has(property.type)) {
62
+ if (!baseTypes.has(property.type)) {
64
63
  const type = types[property.type];
65
64
  if (type) {
66
65
  property.type = type;
@@ -5,9 +5,9 @@ export namespace ExtraSourceServiceTypeDefinition {
5
5
  export let priority: number;
6
6
  export namespace properties {
7
7
  namespace source {
8
- let type: string;
9
- let collection: boolean;
10
- let writable: boolean;
8
+ export { networkAddressType as type };
9
+ export let collection: boolean;
10
+ export let writable: boolean;
11
11
  }
12
12
  }
13
13
  }
@@ -216,7 +216,7 @@ export class ExtraSourceService extends Service {
216
216
  priority: number;
217
217
  properties: {
218
218
  source: {
219
- type: string;
219
+ type: string[];
220
220
  collection: boolean;
221
221
  writable: boolean;
222
222
  };
@@ -228,4 +228,5 @@ export class ExtraSourceService extends Service {
228
228
  get source(): any[];
229
229
  }
230
230
  import { ServiceTypeDefinition } from "./service.mjs";
231
+ import { networkAddressType } from "pmcf";
231
232
  import { Service } from "./service.mjs";
@@ -1,3 +1,4 @@
1
+ export const networkAddressType: string[];
1
2
  export namespace networkProperties {
2
3
  export let scope: {
3
4
  values: string[];
@@ -125,7 +125,7 @@ export class BindService extends ExtraSourceService {
125
125
  get?: Function;
126
126
  env?: string[] | string;
127
127
  };
128
- types: typeof string_collection_attribute;
128
+ types: typeof import("pacc").string_collection_attribute;
129
129
  tls: import("pacc").AttributeDefinition;
130
130
  hostName: {
131
131
  writable: boolean;
@@ -327,7 +327,7 @@ export class BindService extends ExtraSourceService {
327
327
  get?: Function;
328
328
  env?: string[] | string;
329
329
  };
330
- types: typeof string_collection_attribute;
330
+ types: typeof import("pacc").string_collection_attribute;
331
331
  tls: import("pacc").AttributeDefinition;
332
332
  hostName: {
333
333
  writable: boolean;
@@ -404,7 +404,7 @@ export class BindService extends ExtraSourceService {
404
404
  priority: number;
405
405
  properties: {
406
406
  source: {
407
- type: string;
407
+ type: string[];
408
408
  collection: boolean;
409
409
  writable: boolean;
410
410
  };
@@ -623,4 +623,3 @@ export class BindService extends ExtraSourceService {
623
623
  writeZones(packageData: any, configs: any): Promise<void>;
624
624
  }
625
625
  import { ExtraSourceService } from "pmcf";
626
- import { string_collection_attribute } from "pacc";
@@ -404,7 +404,7 @@ export class ChronyService extends ExtraSourceService {
404
404
  priority: number;
405
405
  properties: {
406
406
  source: {
407
- type: string;
407
+ type: string[];
408
408
  collection: boolean;
409
409
  writable: boolean;
410
410
  };
@@ -404,7 +404,7 @@ export class HeadscaleService extends ExtraSourceService {
404
404
  priority: number;
405
405
  properties: {
406
406
  source: {
407
- type: string;
407
+ type: string[];
408
408
  collection: boolean;
409
409
  writable: boolean;
410
410
  };
@@ -404,7 +404,7 @@ export class SystemdResolvedService extends ExtraSourceService {
404
404
  priority: number;
405
405
  properties: {
406
406
  source: {
407
- type: string;
407
+ type: string[];
408
408
  collection: boolean;
409
409
  writable: boolean;
410
410
  };
@@ -404,7 +404,7 @@ export class SystemdTimesyncdService extends ExtraSourceService {
404
404
  priority: number;
405
405
  properties: {
406
406
  source: {
407
- type: string;
407
+ type: string[];
408
408
  collection: boolean;
409
409
  writable: boolean;
410
410
  };
package/types/types.d.mts CHANGED
@@ -2,4 +2,3 @@ export function addType(clazz: any): void;
2
2
  export function resolveTypeLinks(): void;
3
3
  export function typeFactory(type: any, owner: any, data: any): any;
4
4
  export const types: {};
5
- export const primitives: Set<string>;