pacc 9.3.1 → 9.3.3

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
@@ -279,10 +279,10 @@ Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Globa
279
279
 
280
280
  * `type` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
281
281
  * `isKey` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** 
282
- * `isOwner` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** are we the owner of the value
283
282
  * `writable` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** 
284
283
  * `mandatory` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** 
285
- * `collection` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** 
284
+ * `collection` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** are we a collection (set, map, array, object)
285
+ * `owner` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** are we the owner of the value
286
286
  * `constructor` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** (collection) constructor
287
287
  * `private` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** should the value be shown
288
288
  * `credential` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** any type of credential
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "9.3.1",
3
+ "version": "9.3.3",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -7,7 +7,7 @@ import { types } from "./types.mjs";
7
7
  * @property {boolean} isKey
8
8
  * @property {boolean} writable
9
9
  * @property {boolean} mandatory
10
- * @property {boolean} collection are we a collection (set, map, array)
10
+ * @property {boolean} collection are we a collection (set, map, array, object)
11
11
  * @property {boolean} owner are we the owner of the value
12
12
  * @property {Function} [constructor] (collection) constructor
13
13
  * @property {boolean} [private] should the value be shown
package/src/types.mjs CHANGED
@@ -105,36 +105,34 @@ export const types = {
105
105
  };
106
106
 
107
107
  /**
108
- *
109
- * @param {string|undefined} type
108
+ * Throw if type is not known.
109
+ * @param {Type|string|undefined} type
110
110
  * @param {any} origin
111
111
  * @returns {Type}
112
112
  */
113
113
  function raiseOnUnknownType(type, origin) {
114
- switch (typeof type) {
115
- case "string":
116
- if (types[type]) {
117
- return types[type];
118
- }
119
- case "undefined":
120
- throw new Error(`Unknown type ${type} in '${origin}'`, { cause: type });
114
+ if (types[type]) {
115
+ return types[type];
121
116
  }
122
117
 
123
- return type;
118
+ if (types[type?.name] === type) {
119
+ return type;
120
+ }
121
+
122
+ throw new Error(`Unknown type ${type} in '${origin}'`, { cause: type });
124
123
  }
125
124
 
126
125
  export function addType(type) {
127
- switch (typeof type.extends) {
128
- case "undefined":
129
- const ex = Object.getPrototypeOf(type.clazz || type);
126
+ if (typeof type.extends === "string") {
127
+ type.extends = raiseOnUnknownType(type.extends, type);
128
+ } else {
129
+ if (type.extends === undefined || !type.hasOwnProperty("extends")) {
130
+ const ex = Object.getPrototypeOf(type);
131
+
130
132
  if (ex?.name) {
131
133
  type.extends = ex;
132
134
  }
133
- break;
134
-
135
- case "string":
136
- type.extends = raiseOnUnknownType(type.extends, type);
137
- break;
135
+ }
138
136
  }
139
137
 
140
138
  if (type.specializationOf) {
@@ -5,7 +5,7 @@
5
5
  * @property {boolean} isKey
6
6
  * @property {boolean} writable
7
7
  * @property {boolean} mandatory
8
- * @property {boolean} collection are we a collection (set, map, array)
8
+ * @property {boolean} collection are we a collection (set, map, array, object)
9
9
  * @property {boolean} owner are we the owner of the value
10
10
  * @property {Function} [constructor] (collection) constructor
11
11
  * @property {boolean} [private] should the value be shown
@@ -233,7 +233,7 @@ export type AttributeDefinition = {
233
233
  writable: boolean;
234
234
  mandatory: boolean;
235
235
  /**
236
- * are we a collection (set, map, array)
236
+ * are we a collection (set, map, array, object)
237
237
  */
238
238
  collection: boolean;
239
239
  /**