pacc 9.2.13 → 9.3.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/README.md CHANGED
@@ -831,6 +831,9 @@ Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Globa
831
831
 
832
832
  * `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 
833
833
  * `primitive` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** 
834
+ * `extends` **[Type](#type)?** 
835
+ * `members` **[Set](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set)<[Type](#type)>?**&#x20;
836
+ * `clazz` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?**&#x20;
834
837
  * `toInternal` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?**&#x20;
835
838
  * `toExternal` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?**&#x20;
836
839
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "9.2.13",
3
+ "version": "9.3.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -43,13 +43,13 @@
43
43
  },
44
44
  "devDependencies": {
45
45
  "@mitata/counters": "^0.0.8",
46
- "aggregated-map": "^1.0.3",
46
+ "aggregated-map": "^1.0.4",
47
47
  "ava": "^8.0.1",
48
48
  "browser-ava": "^2.3.61",
49
49
  "c8": "^11.0.0",
50
50
  "documentation": "^14.0.3",
51
51
  "mitata": "^1.0.34",
52
- "semantic-release": "^25.0.3",
52
+ "semantic-release": "^25.0.5",
53
53
  "typescript": "^6.0.3"
54
54
  },
55
55
  "overrides": {
@@ -45,17 +45,17 @@ function mergeAttributeDefinitions(dest, atts) {
45
45
  }
46
46
 
47
47
  /**
48
- * Iterate over all attributes.
49
- * @param {Object} definition
48
+ * Iterate over attributes.
49
+ * @param {Object} attribute definition
50
50
  * @param {Function} [filter]
51
- * @param {string[]} path
51
+ * @param {string[]} [path]
52
52
  * @return {Iterable<[string[],object]>}
53
53
  */
54
54
  export function* attributeIterator(definition, filter, path = []) {
55
55
  if (definition) {
56
56
  for (const [name, def] of Object.entries(definition)) {
57
57
  const path2 = [...path, name];
58
- if (typeof filter !== 'function' || filter(name, def)) {
58
+ if (typeof filter !== "function" || filter(name, def)) {
59
59
  yield [path2, def];
60
60
  }
61
61
 
@@ -64,6 +64,20 @@ export function* attributeIterator(definition, filter, path = []) {
64
64
  }
65
65
  }
66
66
 
67
+ /**
68
+ * Iterate over all attributes of a type.
69
+ * @param {Type} type definition
70
+ * @param {Function} [filter]
71
+ * @param {string[]} [path]
72
+ * @return {Iterable<[string[],object]>}
73
+ */
74
+ export function* extendingAttributeIterator(type, filter, path) {
75
+ if (type.extends) {
76
+ yield* extendingAttributeIterator(type.extends, filter, path);
77
+ }
78
+ yield* attributeIterator(type.attributes, filter, path);
79
+ }
80
+
67
81
  export const filterWritable = (name, attribute) => attribute.writable;
68
82
  export const filterPublic = (name, attribute) => !attribute.private;
69
83
 
@@ -5,6 +5,7 @@ import { types } from "./types.mjs";
5
5
  *
6
6
  * @property {object} type
7
7
  * @property {boolean} isKey
8
+ * @property {boolean} isOwner are we the owner of the value
8
9
  * @property {boolean} writable
9
10
  * @property {boolean} mandatory
10
11
  * @property {boolean} collection
@@ -19,11 +20,11 @@ import { types } from "./types.mjs";
19
20
  * @property {Function} [get] get the value can be used to calculate default values
20
21
  * @property {Function} [toInternal]
21
22
  * @property {Function} [toExternal]
22
- * @property {Set<any>} [values] allowed values
23
23
  * @property {string} [externalName] attribute name used by external system
24
+ * @property {Set<any>} [values] allowed values
24
25
  * @property {string[]|string} [env] environment variable(s) used to provide the value
25
26
  * @property {object} [additionalValues] other values to be set in case our attribute is set
26
- * @property {string} [separator] separator for collections
27
+ * @property {string} [separator] separator for collections
27
28
  */
28
29
 
29
30
  /**
@@ -38,7 +39,8 @@ export const default_attribute = {
38
39
  persistent: false,
39
40
  private: false,
40
41
  credential: false,
41
- isKey: false
42
+ isKey: false,
43
+ isOwner: true
42
44
  };
43
45
 
44
46
  /**
package/src/types.mjs CHANGED
@@ -6,6 +6,9 @@ import { parseBytes } from "./bytes.mjs";
6
6
  * @typedef {Object} Type
7
7
  * @property {string} name
8
8
  * @property {boolean} [primitive]
9
+ * @property {Type} [extends]
10
+ * @property {Set<Type>} [members]
11
+ * @property {Function} [clazz]
9
12
  * @property {Function} [toInternal]
10
13
  * @property {Function} [toExternal]
11
14
  */
@@ -121,28 +124,11 @@ function raiseOnUnknownType(type, origin) {
121
124
  }
122
125
 
123
126
  export function addType(type) {
124
- if (type.typeDefinition) {
125
- const clazz = type;
126
- type = type.typeDefinition;
127
- type.clazz = clazz;
128
- } else {
129
- if (!!type?.constructor.name) {
130
- const clazz = type;
131
- type.clazz = clazz;
132
- }
133
- }
134
-
135
- if (type.specializationOf) {
136
- type.specializationOf.specializations[type.name] = type;
137
- }
138
-
139
- type.owners ||= [];
140
-
141
127
  switch (typeof type.extends) {
142
128
  case "undefined":
143
- const ex = Object.getPrototypeOf(type.clazz);
129
+ const ex = Object.getPrototypeOf(type.clazz || type);
144
130
  if (ex?.name) {
145
- type.extends = ex.typeDefinition || ex;
131
+ type.extends = ex;
146
132
  }
147
133
  break;
148
134
 
@@ -151,14 +137,19 @@ export function addType(type) {
151
137
  break;
152
138
  }
153
139
 
154
- if (!types[type.name]) {
155
- types[type.name] = type;
140
+ if (type.specializationOf) {
141
+ type.specializationOf.specializations[type.name] = type;
156
142
  }
157
143
 
158
- if (types[type.name] !== type) {
159
- return Object.assign(types[type.name], type);
160
- }
144
+ type.owners ||= [];
161
145
 
146
+ if (!types[type.name]) {
147
+ types[type.name] = type;
148
+ } else {
149
+ if (types[type.name] !== type) {
150
+ return Object.assign(types[type.name], type);
151
+ }
152
+ }
162
153
  return type;
163
154
  }
164
155
 
@@ -213,7 +204,7 @@ export function resolveTypeLinks() {
213
204
  }
214
205
 
215
206
  export function typeFactory(type, owner, data) {
216
- const factory = type.factoryFor?.(owner, data) || type.clazz;
207
+ const factory = type.factoryFor?.(owner, data) || type.clazz || type;
217
208
  const object = new factory(owner);
218
209
 
219
210
  object.read(data);
@@ -6,13 +6,21 @@
6
6
  */
7
7
  export function prepareAttributesDefinitions(newDefinitions: Object, presentDefinitions?: Object): Object;
8
8
  /**
9
- * Iterate over all attributes.
10
- * @param {Object} definition
9
+ * Iterate over attributes.
10
+ * @param {Object} attribute definition
11
11
  * @param {Function} [filter]
12
- * @param {string[]} path
12
+ * @param {string[]} [path]
13
13
  * @return {Iterable<[string[],object]>}
14
14
  */
15
- export function attributeIterator(definition: Object, filter?: Function, path?: string[]): Iterable<[string[], object]>;
15
+ export function attributeIterator(definition: any, filter?: Function, path?: string[]): Iterable<[string[], object]>;
16
+ /**
17
+ * Iterate over all attributes of a type.
18
+ * @param {Type} type definition
19
+ * @param {Function} [filter]
20
+ * @param {string[]} [path]
21
+ * @return {Iterable<[string[],object]>}
22
+ */
23
+ export function extendingAttributeIterator(type: Type, filter?: Function, path?: string[]): Iterable<[string[], object]>;
16
24
  export function writableAttributeIterator(definition: any): Generator<[string[], object], void, any>;
17
25
  export function toInternal(value: any, attribute: any): any;
18
26
  export function toExternal(value: any, attribute: any): any;
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * @property {object} type
5
5
  * @property {boolean} isKey
6
+ * @property {boolean} isOwner are we the owner of the value
6
7
  * @property {boolean} writable
7
8
  * @property {boolean} mandatory
8
9
  * @property {boolean} collection
@@ -17,11 +18,11 @@
17
18
  * @property {Function} [get] get the value can be used to calculate default values
18
19
  * @property {Function} [toInternal]
19
20
  * @property {Function} [toExternal]
20
- * @property {Set<any>} [values] allowed values
21
21
  * @property {string} [externalName] attribute name used by external system
22
+ * @property {Set<any>} [values] allowed values
22
23
  * @property {string[]|string} [env] environment variable(s) used to provide the value
23
24
  * @property {object} [additionalValues] other values to be set in case our attribute is set
24
- * @property {string} [separator] separator for collections
25
+ * @property {string} [separator] separator for collections
25
26
  */
26
27
  /**
27
28
  * Common attribute properties.
@@ -101,6 +102,7 @@ export namespace yesno_attribute_writable {
101
102
  export let writable: boolean;
102
103
  export let type: object;
103
104
  export let isKey: boolean;
105
+ export let isOwner: boolean;
104
106
  export let mandatory: boolean;
105
107
  export let collection: boolean;
106
108
  export let constructor: Function | undefined;
@@ -116,8 +118,8 @@ export namespace yesno_attribute_writable {
116
118
  export let get: Function | undefined;
117
119
  export let toInternal: Function | undefined;
118
120
  export let toExternal: Function | undefined;
119
- export let values: Set<any> | undefined;
120
121
  export let externalName: string | undefined;
122
+ export let values: Set<any> | undefined;
121
123
  export let env: string | string[] | undefined;
122
124
  export let additionalValues: object | undefined;
123
125
  export let separator: string | undefined;
@@ -228,6 +230,10 @@ export const language_attribute: AttributeDefinition;
228
230
  export type AttributeDefinition = {
229
231
  type: object;
230
232
  isKey: boolean;
233
+ /**
234
+ * are we the owner of the value
235
+ */
236
+ isOwner: boolean;
231
237
  writable: boolean;
232
238
  mandatory: boolean;
233
239
  collection: boolean;
@@ -269,14 +275,14 @@ export type AttributeDefinition = {
269
275
  get?: Function | undefined;
270
276
  toInternal?: Function | undefined;
271
277
  toExternal?: Function | undefined;
272
- /**
273
- * allowed values
274
- */
275
- values?: Set<any> | undefined;
276
278
  /**
277
279
  * attribute name used by external system
278
280
  */
279
281
  externalName?: string | undefined;
282
+ /**
283
+ * allowed values
284
+ */
285
+ values?: Set<any> | undefined;
280
286
  /**
281
287
  * environment variable(s) used to provide the value
282
288
  */
package/types/types.d.mts CHANGED
@@ -64,6 +64,9 @@ export const types: {
64
64
  export type Type = {
65
65
  name: string;
66
66
  primitive?: boolean | undefined;
67
+ extends?: Type | undefined;
68
+ members?: Set<Type> | undefined;
69
+ clazz?: Function | undefined;
67
70
  toInternal?: Function | undefined;
68
71
  toExternal?: Function | undefined;
69
72
  };