miolo-model 3.0.0-beta.226 → 3.0.0-beta.228

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": "miolo-model",
3
- "version": "3.0.0-beta.226",
3
+ "version": "3.0.0-beta.228",
4
4
  "description": "Data models for miolo world",
5
5
  "author": "Donato Lorenzo <donato@afialapis.com>",
6
6
  "contributors": [
@@ -23,10 +23,6 @@ export default class MioloArray extends Array {
23
23
 
24
24
  this.reset_cache()
25
25
 
26
- if (typeof items === "number") {
27
- return
28
- }
29
-
30
26
  // Check properties
31
27
  if (!itemClass) {
32
28
  console.error(`[${this.constructor.name}] MioloArray received no itemClass`)
@@ -35,6 +31,10 @@ export default class MioloArray extends Array {
35
31
  /** @type {new (...args: any[]) => T} */
36
32
  this.itemClass = itemClass
37
33
 
34
+ if (typeof items === "number") {
35
+ return
36
+ }
37
+
38
38
  items.forEach((r, index) => {
39
39
  this[index] =
40
40
  r !== undefined && r instanceof this.itemClass ? r : new this.itemClass(r || {}, ...extra)
@@ -178,7 +178,7 @@ export default class MioloArray extends Array {
178
178
  /**
179
179
  * Find the index of the first item in the array that has the given field and value.
180
180
  * @param {string} field - The field to search for.
181
- * @param {MioloModel} value - The value to search for.
181
+ * @param {any} value - The value to search for.
182
182
  * @returns {number} The index of the first item that has the given field and value, or -1 if not found.
183
183
  * @public
184
184
  */
@@ -311,4 +311,55 @@ export default class MioloArray extends Array {
311
311
  // Object.assign(clone, this)
312
312
  return clone
313
313
  }
314
+
315
+ /**
316
+ * @param {(value: T, index: number, array: Array<T>) => boolean} predicate
317
+ * @param {any} [thisArg]
318
+ * @returns {this}
319
+ */
320
+ filter(predicate, thisArg) {
321
+ // @ts-expect-error
322
+ return super.filter(predicate, thisArg)
323
+ }
324
+
325
+ /**
326
+ * @template U
327
+ * @param {(value: T, index: number, array: Array<T>) => U} callbackfn
328
+ * @param {any} [thisArg]
329
+ * @returns {Array<U>}
330
+ */
331
+ map(callbackfn, thisArg) {
332
+ return super.map(callbackfn, thisArg)
333
+ }
334
+
335
+ /**
336
+ * @param {number} [start]
337
+ * @param {number} [end]
338
+ * @returns {this}
339
+ */
340
+ slice(start, end) {
341
+ // @ts-expect-error
342
+ return super.slice(start, end)
343
+ }
344
+
345
+ /**
346
+ * @param {number} start
347
+ * @param {number} [deleteCount]
348
+ * @param {...T} items
349
+ * @returns {this}
350
+ */
351
+ // biome-ignore lint/correctness/noUnusedFunctionParameters: its ok
352
+ splice(start, deleteCount, ...items) {
353
+ // @ts-expect-error
354
+ // biome-ignore lint/complexity/noArguments: its ok
355
+ return super.splice.apply(this, arguments)
356
+ }
357
+
358
+ /**
359
+ * @returns {this}
360
+ */
361
+ reverse() {
362
+ // @ts-expect-error
363
+ return super.reverse()
364
+ }
314
365
  }
@@ -118,11 +118,11 @@ export default class MioloModel extends class {} {
118
118
  /**
119
119
  * Get a value from the model's data.
120
120
  * @param {string} field - The field to get the value from.
121
- * @param {any} def - The default value to return if the field is not found.
121
+ * @param {any} [def=undefined] - The default value to return if the field is not found.
122
122
  * @returns {any} The value from the model's data.
123
123
  * @public
124
124
  */
125
- get_value(field, def) {
125
+ get_value(field, def = undefined) {
126
126
  if (this.data !== undefined) {
127
127
  if (this.data[field] !== undefined && this.data[field] !== null) {
128
128
  return this.data[field]
@@ -134,12 +134,12 @@ export default class MioloModel extends class {} {
134
134
  /**
135
135
  * Get a value from the model's data.
136
136
  * @param {string} field - The field to get the value from.
137
- * @param {any} def - The default value to return if the field is not found.
137
+ * @param {any} [def=undefined] - The default value to return if the field is not found.
138
138
  * @returns {any} The value from the model's data.
139
139
  * @public
140
140
  * @deprecated Use get_value() instead.
141
141
  */
142
- _get(field, def) {
142
+ _get(field, def = undefined) {
143
143
  return this.get_value(field, def)
144
144
  }
145
145