@onehat/data 1.22.3 → 1.22.5

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.
@@ -44,6 +44,7 @@ describe('Property', function() {
44
44
  title: null,
45
45
  tooltip: null,
46
46
  viewerType: null,
47
+ formatter: null,
47
48
  };
48
49
  // console.log(defaults);
49
50
  // console.log(expected);
@@ -81,9 +82,14 @@ describe('Property', function() {
81
82
 
82
83
  it('getDisplayValue & displayValue', function() {
83
84
  this.property.setValue('12');
84
- const value = this.property.getDisplayValue();
85
+ let value = this.property.getDisplayValue();
85
86
  expect(value).to.be.eq(12);
86
87
  expect(value).to.be.eq(this.property.displayValue);
88
+
89
+ this.property.setFormatter('FormatInt');
90
+ this.property.setValue('12345');
91
+ value = this.property.getDisplayValue();
92
+ expect(value).to.be.eq('12,345');
87
93
  });
88
94
 
89
95
  it('hasMapping', function() {
@@ -1,2 +1,3 @@
1
1
  // https://on.cypress.io/configuration
2
2
  import './commands.js';
3
+ import 'cypress-localstorage-commands';
@@ -0,0 +1,20 @@
1
+ // ***********************************************************
2
+ // This example support/index.js is processed and
3
+ // loaded automatically before your test files.
4
+ //
5
+ // This is a great place to put global configuration and
6
+ // behavior that modifies Cypress.
7
+ //
8
+ // You can change the location of this file or turn off
9
+ // automatically serving support files with the
10
+ // 'supportFile' configuration option.
11
+ //
12
+ // You can read more here:
13
+ // https://on.cypress.io/configuration
14
+ // ***********************************************************
15
+
16
+ // Import commands.js using ES2015 syntax:
17
+ import './commands'
18
+
19
+ // Alternatively you can use CommonJS syntax:
20
+ // require('./commands')
package/cypress.config.js CHANGED
@@ -1,16 +1,17 @@
1
1
  import { defineConfig } from "cypress";
2
2
  import webpackPreprocessor from "@cypress/webpack-preprocessor";
3
+ import localstoragePlugin from 'cypress-localstorage-commands/plugin.js';
3
4
 
4
5
  export default defineConfig({
5
6
  e2e: {
6
7
  experimentalRunAllSpecs: true,
7
8
  chromeWebSecurity: false,
8
- setupNodeEvents(on) {
9
+ setupNodeEvents(on, config) {
9
10
  const options = webpackPreprocessor.defaultOptions;
10
11
  if (!options.module) {
11
12
  options.module = {
12
13
  rules: [],
13
- }
14
+ };
14
15
  }
15
16
  if (!options.module.rules) {
16
17
  options.module.rules = [];
@@ -18,24 +19,25 @@ export default defineConfig({
18
19
  options.module.rules.push({
19
20
  test: /\.(js|jsx|mjs)$/,
20
21
  exclude: [/node_modules\/(?!(@onehat)\/).*/],
21
- use: [{
22
- loader: 'babel-loader',
23
- options: {
24
- cacheDirectory: false,
25
- presets: [
26
- '@babel/preset-env'
27
- ],
28
- plugins: [
29
- '@babel/plugin-transform-class-properties',
30
- '@babel/plugin-transform-runtime'
31
- ],
32
- sourceType: 'unambiguous',
22
+ use: [
23
+ {
24
+ loader: 'babel-loader',
25
+ options: {
26
+ cacheDirectory: false,
27
+ presets: ['@babel/preset-env'],
28
+ plugins: [
29
+ '@babel/plugin-transform-class-properties',
30
+ '@babel/plugin-transform-runtime',
31
+ ],
32
+ sourceType: 'unambiguous',
33
+ },
33
34
  },
34
- }],
35
-
35
+ ],
36
36
  });
37
37
 
38
38
  on('file:preprocessor', webpackPreprocessor(options));
39
+
40
+ localstoragePlugin(on, config);
39
41
  },
40
42
  }
41
43
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/data",
3
- "version": "1.22.3",
3
+ "version": "1.22.5",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -37,8 +37,8 @@
37
37
  "homepage": "https://github.com/OneHatRepo/data#readme",
38
38
  "dependencies": {
39
39
  "@onehat/events": "^1.6.6",
40
- "async-wait-until": "^2.0.12",
41
40
  "accounting-js": "^1.1.1",
41
+ "async-wait-until": "^2.0.12",
42
42
  "axios": "^1.6.2",
43
43
  "chrono-node": "^2.7.3",
44
44
  "he": "^1.2.0",
@@ -57,20 +57,18 @@
57
57
  "store2": "^2.14.3"
58
58
  },
59
59
  "devDependencies": {
60
- "@babel/core": "^7.22.1",
61
- "@babel/node": "^7.22.1",
62
- "@babel/plugin-transform-class-properties": "^7.22.3",
63
- "@babel/plugin-transform-runtime": "^7.22.4",
64
- "@babel/preset-env": "^7.22.4",
65
- "@babel/register": "^7.21.0",
66
- "@babel/runtime": "^7.22.3",
60
+ "@babel/core": "^7.24.5",
61
+ "@babel/plugin-transform-class-properties": "^7.24.1",
62
+ "@babel/plugin-transform-export-namespace-from": "^7.24.1",
63
+ "@babel/plugin-transform-runtime": "^7.24.3",
64
+ "@babel/preset-env": "^7.24.5",
65
+ "@babel/runtime": "^7.24.5",
67
66
  "@cypress/webpack-preprocessor": "^5.17.1",
68
- "babel-loader": "^9.1.2",
69
- "cypress": "12.15.0",
67
+ "cypress": "^13.15.2",
68
+ "cypress-localstorage-commands": "^2.2.7",
70
69
  "ink-docstrap": "^1.3.2",
71
70
  "joi": "^17.9.2",
72
71
  "jsdoc": "^4.0.2",
73
- "webpack": "^5.85.0",
74
72
  "yup": "^1.2.0"
75
73
  }
76
74
  }
@@ -1,6 +1,7 @@
1
1
  /** @module Property */
2
2
 
3
3
  import EventEmitter from '@onehat/events';
4
+ import Formatters from '../Util/Formatters.js';
4
5
  import _ from 'lodash';
5
6
 
6
7
  /**
@@ -137,6 +138,12 @@ export default class Property extends EventEmitter {
137
138
  */
138
139
  defaultValue: null,
139
140
 
141
+ /**
142
+ * @member {string} formatter - The name of the formatter to use for this property
143
+ * @private
144
+ */
145
+ formatter: null,
146
+
140
147
  };
141
148
 
142
149
  /**
@@ -278,6 +285,9 @@ export default class Property extends EventEmitter {
278
285
  if (this.isDestroyed) {
279
286
  throw Error('this.getDisplayValue is no longer valid. Property has been destroyed.');
280
287
  }
288
+ if (this.formatter) {
289
+ return Formatters[this.formatter](this.parsedValue);
290
+ }
281
291
  return this.parsedValue;
282
292
  }
283
293
 
@@ -428,6 +438,17 @@ export default class Property extends EventEmitter {
428
438
  return value;
429
439
  }
430
440
 
441
+ /**
442
+ * Sets the formatter for this Property.
443
+ * @param {*} formatter
444
+ */
445
+ setFormatter(formatter) {
446
+ if (this.isDestroyed) {
447
+ throw Error('this.setFormatter is no longer valid. Property has been destroyed.');
448
+ }
449
+ this.formatter = formatter;
450
+ }
451
+
431
452
 
432
453
 
433
454
 
@@ -186,26 +186,31 @@ class TreeRepository extends OneBuildRepository {
186
186
  this.throwError(message);
187
187
  return;
188
188
  }
189
+
189
190
 
190
191
  // Set the current entities
191
- const oThis = this;
192
- const children = _.map(root, (data) => {
193
- const entity = Repository._createEntity(oThis.schema, data, this, true);
194
- oThis._relayEntityEvents(entity);
195
- return entity;
192
+ const children = [];
193
+ _.each(root, (data) => {
194
+ if (data.id === treeNode.id) {
195
+ // This is the node we're loading, so update it directly
196
+ treeNode.loadOriginalData(data);
197
+ return null;
198
+ }
199
+ const entity = Repository._createEntity(this.schema, data, this, true);
200
+ this._relayEntityEvents(entity);
201
+ children.push(entity);
196
202
  });
197
-
198
- this.entities = this.entities.concat(children);
199
-
200
- this.assembleTreeNodes();
201
-
202
- this._setPaginationVars();
203
+ if (children.length) {
204
+ this.entities = this.entities.concat(children);
205
+ this.assembleTreeNodes();
206
+ this._setPaginationVars();
207
+ }
203
208
 
204
209
  this.rehash();
205
210
  // this.emit('changeData', this.entities);
206
211
  this.emit('load', this);
207
212
 
208
- return children;
213
+ return treeNode;
209
214
  })
210
215
  .finally(() => {
211
216
  this.markLoading(false);