pacc 4.13.0 → 4.14.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 +5 -0
- package/package.json +1 -1
- package/src/attributes.mjs +12 -6
- package/src/properties.mjs +15 -12
- package/src/tokens.mjs +18 -7
- package/types/attributes.d.mts +1 -1
package/README.md
CHANGED
|
@@ -44,6 +44,7 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
|
|
|
44
44
|
* [default\_attribute\_writable](#default_attribute_writable-3)
|
|
45
45
|
* [string\_collection\_attribute\_writable](#string_collection_attribute_writable)
|
|
46
46
|
* [name\_attribute](#name_attribute)
|
|
47
|
+
* [name\_attribute\_writable](#name_attribute_writable)
|
|
47
48
|
* [email\_attribute](#email_attribute)
|
|
48
49
|
* [version\_attribute\_writable](#version_attribute_writable)
|
|
49
50
|
* [description\_attribute](#description_attribute)
|
|
@@ -216,6 +217,10 @@ Type: [AttributeDefinition](#attributedefinition)
|
|
|
216
217
|
|
|
217
218
|
Type: [AttributeDefinition](#attributedefinition)
|
|
218
219
|
|
|
220
|
+
## name\_attribute\_writable
|
|
221
|
+
|
|
222
|
+
Type: [AttributeDefinition](#attributedefinition)
|
|
223
|
+
|
|
219
224
|
## email\_attribute
|
|
220
225
|
|
|
221
226
|
Type: [AttributeDefinition](#attributedefinition)
|
package/package.json
CHANGED
package/src/attributes.mjs
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
const types = {
|
|
2
2
|
base: { name: "base" },
|
|
3
3
|
string: { name: "string", extends: "base" },
|
|
4
|
-
number: {
|
|
4
|
+
number: {
|
|
5
|
+
name: "number",
|
|
6
|
+
extends: "base",
|
|
7
|
+
convertValue: (value, attribute) =>
|
|
8
|
+
typeof value === "string" ? parseFloat(value) : value
|
|
9
|
+
},
|
|
5
10
|
integer: {
|
|
6
11
|
name: "integer",
|
|
7
12
|
extends: "base",
|
|
8
|
-
convertValue:
|
|
13
|
+
convertValue: (value, attribute) =>
|
|
14
|
+
typeof value === "string" ? parseInt(value) : value
|
|
9
15
|
},
|
|
10
16
|
"unsigned-integer": { name: "unsigned-integer", extends: "integer" },
|
|
11
17
|
boolean: {
|
|
12
18
|
name: "boolean",
|
|
13
19
|
extends: "base",
|
|
14
|
-
convertValue: value => (!value || value === "0" ? false : true)
|
|
20
|
+
convertValue: (value, attribute) => (!value || value === "0" ? false : true)
|
|
15
21
|
},
|
|
16
22
|
url: { name: "url", extends: "string" },
|
|
17
23
|
object: { name: "object", extends: "base" }
|
|
@@ -79,9 +85,9 @@ export function* attributeIterator(definition, path = []) {
|
|
|
79
85
|
}
|
|
80
86
|
}
|
|
81
87
|
|
|
82
|
-
export function convertValue(value,
|
|
83
|
-
if (
|
|
84
|
-
return
|
|
88
|
+
export function convertValue(value, attribute) {
|
|
89
|
+
if (attribute?.type?.convertValue) {
|
|
90
|
+
return attribute.type.convertValue(value, attribute);
|
|
85
91
|
}
|
|
86
92
|
return value;
|
|
87
93
|
}
|
package/src/properties.mjs
CHANGED
|
@@ -15,22 +15,25 @@ export function definePropertiesFromAttributes(
|
|
|
15
15
|
|
|
16
16
|
let value = getAttribute(values, name, attribute) ?? values?.[name];
|
|
17
17
|
|
|
18
|
-
if (value !== undefined
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
if (value !== undefined) {
|
|
19
|
+
if (path.length === 1) {
|
|
20
|
+
const op = Object.getOwnPropertyDescriptor(
|
|
21
|
+
object.constructor.prototype,
|
|
22
|
+
name
|
|
23
|
+
);
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
const property = properties[name];
|
|
25
|
+
value = convertValue(value, attribute);
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const property = properties[name];
|
|
28
|
+
|
|
29
|
+
if (op?.set || property?.set) {
|
|
30
|
+
applyLater[name] = value;
|
|
31
|
+
} else {
|
|
32
|
+
properties[name] = Object.assign({ ...attribute, value }, property);
|
|
33
|
+
}
|
|
29
34
|
} else {
|
|
30
|
-
|
|
35
|
+
setAttribute(object, name, value, attribute);
|
|
31
36
|
}
|
|
32
|
-
} else {
|
|
33
|
-
setAttribute(object, name, value, attribute);
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
39
|
|
package/src/tokens.mjs
CHANGED
|
@@ -34,7 +34,7 @@ export /** @type {Token} */ const GREATER_EQUAL = createToken(
|
|
|
34
34
|
export /** @type {Token} */ const LESS = createToken("<", 40, "infixr");
|
|
35
35
|
export /** @type {Token} */ const LESS_EQUAL = createToken("<=", 40, "infixr");
|
|
36
36
|
export /** @type {Token} */ const EQUAL = createToken("=", 40);
|
|
37
|
-
export /** @type {Token} */ const OPEN_ROUND = createToken("(",
|
|
37
|
+
export /** @type {Token} */ const OPEN_ROUND = createToken("(", 0, "prefix");
|
|
38
38
|
export /** @type {Token} */ const CLOSE_ROUND = createToken(")", 0, "infix");
|
|
39
39
|
export /** @type {Token} */ const OPEN_BRACKET = createToken("[", 10, "prefix");
|
|
40
40
|
export /** @type {Token} */ const CLOSE_BRACKET = createToken("]", 0, "infix");
|
|
@@ -64,6 +64,17 @@ export /** @type {Token} */ const EOF = createToken("EOF", -1, "eof");
|
|
|
64
64
|
export function* tokens(string) {
|
|
65
65
|
let state, value, hex, divider;
|
|
66
66
|
|
|
67
|
+
function maybeKeyword() {
|
|
68
|
+
switch (value) {
|
|
69
|
+
case "true":
|
|
70
|
+
return true;
|
|
71
|
+
case "false":
|
|
72
|
+
return false;
|
|
73
|
+
default:
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
67
78
|
for (const c of string) {
|
|
68
79
|
switch (state) {
|
|
69
80
|
case "string-escaping-hex":
|
|
@@ -105,7 +116,7 @@ export function* tokens(string) {
|
|
|
105
116
|
case "number-fraction":
|
|
106
117
|
case "number":
|
|
107
118
|
case "identifier":
|
|
108
|
-
yield
|
|
119
|
+
yield maybeKeyword();
|
|
109
120
|
value = undefined;
|
|
110
121
|
state = undefined;
|
|
111
122
|
break;
|
|
@@ -132,7 +143,7 @@ export function* tokens(string) {
|
|
|
132
143
|
case "number-fraction":
|
|
133
144
|
case "number":
|
|
134
145
|
case "identifier":
|
|
135
|
-
yield
|
|
146
|
+
yield maybeKeyword();
|
|
136
147
|
value = "";
|
|
137
148
|
state = "string";
|
|
138
149
|
break;
|
|
@@ -171,7 +182,7 @@ export function* tokens(string) {
|
|
|
171
182
|
case "number-fraction":
|
|
172
183
|
case "number":
|
|
173
184
|
case "identifier":
|
|
174
|
-
yield
|
|
185
|
+
yield maybeKeyword();
|
|
175
186
|
state = c;
|
|
176
187
|
break;
|
|
177
188
|
default:
|
|
@@ -191,7 +202,7 @@ export function* tokens(string) {
|
|
|
191
202
|
case "number-fraction":
|
|
192
203
|
case "number":
|
|
193
204
|
case "identifier":
|
|
194
|
-
yield
|
|
205
|
+
yield maybeKeyword();
|
|
195
206
|
state = c;
|
|
196
207
|
break;
|
|
197
208
|
default:
|
|
@@ -224,7 +235,7 @@ export function* tokens(string) {
|
|
|
224
235
|
case "number":
|
|
225
236
|
case "number-fraction":
|
|
226
237
|
case "identifier":
|
|
227
|
-
yield
|
|
238
|
+
yield maybeKeyword();
|
|
228
239
|
state = c;
|
|
229
240
|
break;
|
|
230
241
|
default:
|
|
@@ -297,7 +308,7 @@ export function* tokens(string) {
|
|
|
297
308
|
case "number-fraction":
|
|
298
309
|
case "number":
|
|
299
310
|
case "identifier":
|
|
300
|
-
yield
|
|
311
|
+
yield maybeKeyword();
|
|
301
312
|
break;
|
|
302
313
|
default:
|
|
303
314
|
yield lookup[state];
|
package/types/attributes.d.mts
CHANGED
|
@@ -11,4 +11,4 @@ export function prepareAttributesDefinitions(newDefinitions: any, presentDefinit
|
|
|
11
11
|
* @param {string[]} path
|
|
12
12
|
*/
|
|
13
13
|
export function attributeIterator(definition: any, path?: string[]): any;
|
|
14
|
-
export function convertValue(value: any,
|
|
14
|
+
export function convertValue(value: any, attribute: any): any;
|