@onehat/data 1.17.0 → 1.17.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.
Files changed (37) hide show
  1. package/cypress/{integration/Config.spec.js → e2e/Config.cy.js} +1 -1
  2. package/cypress/{integration/Entity.spec.js → e2e/Entity.cy.js} +84 -2
  3. package/cypress/{integration/Repository/Ajax.spec.js → e2e/Repository/Ajax.cy.js} +1 -1
  4. package/cypress/{integration/Repository/Memory.spec.js → e2e/Repository/Memory.cy.js} +1 -1
  5. package/cypress/{integration/Repository/OneBuild.spec.js → e2e/Repository/OneBuild.cy.js} +12 -3
  6. package/cypress/{integration/Repository/Repository.spec.js → e2e/Repository/Repository.cy.js} +225 -4
  7. package/cypress/plugins/index.js +2 -32
  8. package/cypress.config.js +42 -0
  9. package/package.json +22 -22
  10. package/src/Entity/Entity.js +357 -3
  11. package/src/Repository/Ajax.js +13 -3
  12. package/src/Repository/Memory.js +2 -6
  13. package/src/Repository/OneBuild.js +80 -0
  14. package/src/Repository/Repository.js +126 -34
  15. package/src/Schema/Schema.js +33 -0
  16. package/cypress/cypress.json +0 -177
  17. package/cypress.json +0 -1
  18. package/src/Entity/TreeNode.js +0 -190
  19. /package/cypress/{integration/Async.spec.js → e2e/Async.cy.js} +0 -0
  20. /package/cypress/{integration/OneHatData.spec.js → e2e/OneHatData.cy.js} +0 -0
  21. /package/cypress/{integration/Property/Base64.spec.js → e2e/Property/Base64.cy.js} +0 -0
  22. /package/cypress/{integration/Property/Boolean.spec.js → e2e/Property/Boolean.cy.js} +0 -0
  23. /package/cypress/{integration/Property/Currency.spec.js → e2e/Property/Currency.cy.js} +0 -0
  24. /package/cypress/{integration/Property/Date.spec.js → e2e/Property/Date.cy.js} +0 -0
  25. /package/cypress/{integration/Property/DateTime.spec.js → e2e/Property/DateTime.cy.js} +0 -0
  26. /package/cypress/{integration/Property/Float.spec.js → e2e/Property/Float.cy.js} +0 -0
  27. /package/cypress/{integration/Property/Integer.spec.js → e2e/Property/Integer.cy.js} +0 -0
  28. /package/cypress/{integration/Property/Json.spec.js → e2e/Property/Json.cy.js} +0 -0
  29. /package/cypress/{integration/Property/Percent.spec.js → e2e/Property/Percent.cy.js} +0 -0
  30. /package/cypress/{integration/Property/PercentInt.spec.js → e2e/Property/PercentInt.cy.js} +0 -0
  31. /package/cypress/{integration/Property/Property.spec.js → e2e/Property/Property.cy.js} +0 -0
  32. /package/cypress/{integration/Property/String.spec.js → e2e/Property/String.cy.js} +0 -0
  33. /package/cypress/{integration/Property/Time.spec.js → e2e/Property/Time.cy.js} +0 -0
  34. /package/cypress/{integration/Property/Uuid.spec.js → e2e/Property/Uuid.cy.js} +0 -0
  35. /package/cypress/{integration/Repository/LocalFromRemote.spec.js → e2e/Repository/LocalFromRemote.cy.js} +0 -0
  36. /package/cypress/{integration/Schema.spec.js → e2e/Schema.cy.js} +0 -0
  37. /package/cypress/support/{index.js → e2e.js} +0 -0
@@ -155,7 +155,7 @@ describe('Config options', function() {
155
155
 
156
156
  });
157
157
 
158
- it.only('Replace this.method with config.method', function() {
158
+ it('Replace this.method with config.method', function() {
159
159
 
160
160
  class Base {
161
161
  constructor(config = {}) {
@@ -471,11 +471,11 @@ describe('Entity', function() {
471
471
  });
472
472
 
473
473
  it('hash', function() {
474
- expect(this.entity.hash).to.be.eq(4635951664292355);
474
+ expect(this.entity.hash).to.be.eq(5365087438356619);
475
475
 
476
476
  // change a property & check again
477
477
  this.entity.foo = 3;
478
- expect(this.entity.hash).to.be.eq(1510366977941323);
478
+ expect(this.entity.hash).to.be.eq(358445507972157);
479
479
  });
480
480
 
481
481
  });
@@ -900,4 +900,86 @@ describe('Entity', function() {
900
900
  });
901
901
  });
902
902
 
903
+ describe('tree', function() {
904
+
905
+ // Needed for all tree tests...
906
+ const
907
+ schema = new Schema({
908
+ name: 'nodes',
909
+ model: {
910
+ idProperty: 'id',
911
+ displayProperty: 'display',
912
+ parentIdProperty: 'parent_id',
913
+ depthProperty: 'depth',
914
+ hasChildrenProperty: 'hasChildren',
915
+ isTree: true,
916
+ isClosureTable: true,
917
+ properties: [
918
+ { name: 'id', type: 'int' },
919
+ { name: 'display' },
920
+ { name: 'parent_id', type: 'int' },
921
+ { name: 'depth', type: 'int' },
922
+ { name: 'hasChildren', type: 'bool' },
923
+ ],
924
+ },
925
+ }),
926
+ data = {
927
+ id: 2,
928
+ display: 'Child 1',
929
+ parent_id: 1,
930
+ depth: 1,
931
+ hasChildren: true,
932
+ },
933
+ creatEntity = async () => {
934
+ const entity = new Entity(schema, data);
935
+ entity.initialize();
936
+ return entity;
937
+ },
938
+ destoryEntity = (entity) => {
939
+ entity.destroy();
940
+ };
941
+
942
+ it('magic properties', function() {
943
+ (async () => {
944
+ const entity = await creatEntity();
945
+
946
+ expect(entity.parentId).to.be.eq(1);
947
+ expect(entity.depth).to.be.eq(1);
948
+ expect(entity.hasChildren).to.be.true;
949
+
950
+ destoryEntity(entity);
951
+ })();
952
+ });
953
+
954
+ it('parents/children', function() {
955
+ (async () => {
956
+ const entity = await creatEntity();
957
+
958
+ const parent = this.entity;
959
+ entity.parent = parent;
960
+ expect(entity.parent).to.be.eq(parent);
961
+
962
+ const children = [this.entity];
963
+ entity.children = children;
964
+ expect(entity.children).to.be.eq(children);
965
+
966
+ destoryEntity(entity);
967
+ })();
968
+ });
969
+
970
+ it('ensureTree', function() {
971
+ (async () => {
972
+ const entity = await creatEntity();
973
+
974
+ expect(entity.ensureTree()).to.be.true;
975
+
976
+ entity.isTree = false;
977
+ expect(entity.ensureTree()).to.be.false;
978
+
979
+ destoryEntity(entity);
980
+ })();
981
+ });
982
+
983
+ });
984
+
903
985
  });
@@ -91,7 +91,7 @@ describe('OneBuildRepository', function() {
91
91
  r.setValuelessParam('conditions[field IS NOT NULL]');
92
92
 
93
93
  expect(r._params.conditions.field).to.be.eq(1);
94
- expect(r._params.conditions[0]).to.be.eq('field IS NOT NULL');
94
+ expect(r._params.conditions.undefined).to.be.eq('field IS NOT NULL');
95
95
  });
96
96
 
97
97
  it('clearParams', function() {
@@ -281,7 +281,7 @@ describe('MemoryRepository', function() {
281
281
  expect(_.size(this.repository.getRawValues())).to.be.eq(5);
282
282
  expect(_.size(this.repository.getOriginalData())).to.be.eq(5);
283
283
  expect(_.size(this.repository.getParsedValues())).to.be.eq(5);
284
- expect(this.repository.getByIx(2).value).to.be.eq('five');
284
+ expect(this.repository.getByIx(4).value).to.be.eq('five');
285
285
  expect(_.size(this.repository.getNonPersisted())).to.be.eq(0);
286
286
  expect(_.size(this.repository.getPhantom())).to.be.eq(0);
287
287
  expect(_.size(this.repository.getDirty())).to.be.eq(0);
@@ -66,12 +66,21 @@ describe('OneBuildRepository', function() {
66
66
  it('401', function() {
67
67
  cy.wrap((async () => {
68
68
 
69
- let loggedOut = false;
69
+ let loggedOut = false,
70
+ isError = false;
70
71
  this.oneHatData.on('logout', function() { // NOTE: We are listening to the global oneHatData object, not just the individual repository
71
72
  loggedOut = true;
72
73
  });
73
- await this.repository.load();
74
- expect(loggedOut).to.be.true;
74
+ try {
75
+ await this.repository.load();
76
+ } catch(e) {
77
+ isError = true;
78
+ }
79
+ if (!isError) {
80
+ expect(loggedOut).to.be.true;
81
+ } else {
82
+ throw Error('404 error! Maybe set baseUrl?')
83
+ }
75
84
 
76
85
  })());
77
86
  });
@@ -1050,7 +1050,7 @@ describe('Repository Base', function() {
1050
1050
 
1051
1051
  });
1052
1052
 
1053
- describe('options', function() {
1053
+ describe('misc', function() {
1054
1054
  it('setOptions', function() {
1055
1055
 
1056
1056
  this.repository.setOptions({
@@ -1061,11 +1061,232 @@ describe('Repository Base', function() {
1061
1061
 
1062
1062
  expect(this.repository.api.baseURL).to.be.eq('test123');
1063
1063
  });
1064
+
1065
+ it('toString', function() {
1066
+ const str = this.repository.toString();
1067
+ expect(str).to.be.eq('NullRepository {bar} - foo');
1068
+ });
1064
1069
  });
1065
1070
 
1066
- it('toString', function() {
1067
- const str = this.repository.toString();
1068
- expect(str).to.be.eq('NullRepository {bar} - foo');
1071
+ describe('tree', function() {
1072
+
1073
+ // Needed for all tree tests...
1074
+ const
1075
+ schema = new Schema({
1076
+ name: 'nodes',
1077
+ model: {
1078
+ idProperty: 'id',
1079
+ displayProperty: 'display',
1080
+ parentIdProperty: 'parent_id',
1081
+ depthProperty: 'depth',
1082
+ hasChildrenProperty: 'hasChildren',
1083
+ isTree: true,
1084
+ isClosureTable: true,
1085
+ properties: [
1086
+ { name: 'id', type: 'int', },
1087
+ { name: 'display', },
1088
+ { name: 'parent_id', type: 'int', },
1089
+ { name: 'depth', type: 'int', },
1090
+ { name: 'hasChildren', type: 'bool', },
1091
+ ],
1092
+ },
1093
+ repository: 'memory',
1094
+ }),
1095
+ Repository = RepositoryTypes.memory,
1096
+ data = [
1097
+ {
1098
+ id: 1,
1099
+ display: 'Root',
1100
+ parent_id: null,
1101
+ depth: 0,
1102
+ hasChildren: true,
1103
+ isChildrenLoaded: true,
1104
+ },
1105
+ {
1106
+ id: 2,
1107
+ display: 'Child 1',
1108
+ parent_id: 1,
1109
+ depth: 1,
1110
+ hasChildren: true,
1111
+ isChildrenLoaded: true,
1112
+ },
1113
+ {
1114
+ id: 3,
1115
+ display: 'Child 2',
1116
+ parent_id: 1,
1117
+ depth: 1,
1118
+ isChildrenLoaded: true,
1119
+ },
1120
+ {
1121
+ id: 4,
1122
+ display: 'Grandchild',
1123
+ parent_id: 2,
1124
+ depth: 2,
1125
+ isChildrenLoaded: true,
1126
+ },
1127
+ ],
1128
+ creatRepository = async () => {
1129
+ const repository = new Repository({
1130
+ id: 'tree',
1131
+ schema,
1132
+ isAutoLoad: true,
1133
+ isAutoSave: true,
1134
+ isPaginated: true,
1135
+ data,
1136
+ });
1137
+ await repository.initialize();
1138
+ return repository;
1139
+ },
1140
+ destoryRepository = (repository) => {
1141
+ repository.destroy();
1142
+ };
1143
+
1144
+ it('TreeNode (Entity) tests', function() {
1145
+ (async () => {
1146
+ const repository = await creatRepository();
1147
+ repository.assembleTreeNodes();
1148
+
1149
+ const
1150
+ id1 = repository.getById(1),
1151
+ id2 = repository.getById(2),
1152
+ id3 = repository.getById(3),
1153
+ id4 = repository.getById(4);
1154
+
1155
+ // hasChildren
1156
+ expect(id2.hasChildren).to.be.true;
1157
+ expect(id4.hasChildren).to.be.false;
1158
+
1159
+ // getParent
1160
+ expect(id2.getParent()).to.be.eq(id1);
1161
+ expect(id1.getParent()).to.be.null;
1162
+
1163
+ // getChildren
1164
+ let children = await id2.getChildren();
1165
+ expect(children).to.be.eql([id4]);
1166
+
1167
+ children = await id3.getChildren();
1168
+ expect(children).to.be.empty;
1169
+
1170
+ // hasThisChild
1171
+ let hasThisChild = await id2.hasThisChild(id3);
1172
+ expect(hasThisChild).to.be.false;
1173
+
1174
+ hasThisChild = await id2.hasThisChild(id4);
1175
+ expect(hasThisChild).to.be.true;
1176
+
1177
+ // loadChildren (& reloadChildren)
1178
+ // this needs to be on OneBuild spec
1179
+
1180
+ // getPrevousSibling
1181
+ let sibling = await id2.getPrevousSibling();
1182
+ expect(sibling).to.be.null;
1183
+
1184
+ sibling = await id3.getPrevousSibling();
1185
+ expect(sibling).to.be.eq(id2);
1186
+
1187
+ sibling = await id3.getNextSibling();
1188
+ expect(sibling).to.be.null;
1189
+
1190
+ sibling = await id2.getNextSibling();
1191
+ expect(sibling).to.be.eq(id3);
1192
+
1193
+ // getChildAt
1194
+ let child = await id1.getChildAt(0);
1195
+ expect(child).to.be.eq(id2);
1196
+
1197
+ child = await id1.getChildAt(1);
1198
+ expect(child).to.be.eq(id3);
1199
+
1200
+ child = await id1.getChildAt(2);
1201
+ expect(child).to.be.null;
1202
+
1203
+ // getFirstChild
1204
+ child = await id1.getFirstChild();
1205
+ expect(child).to.be.eq(id2);
1206
+
1207
+ child = await id4.getFirstChild();
1208
+ expect(child).to.be.null;
1209
+
1210
+ // getLastChild
1211
+ child = await id1.getLastChild();
1212
+ expect(child).to.be.eq(id3);
1213
+
1214
+ child = await id4.getLastChild();
1215
+ expect(child).to.be.null;
1216
+
1217
+ destoryRepository(repository);
1218
+ })();
1219
+ });
1220
+
1221
+ it('getRootNodes', function() {
1222
+ (async () => {
1223
+ const repository = await creatRepository();
1224
+ repository.assembleTreeNodes();
1225
+
1226
+ const
1227
+ id1 = repository.getById(1);
1228
+
1229
+ const rootNodes = repository.getRootNodes();
1230
+ expect(rootNodes).to.be.eql([id1]);
1231
+
1232
+ destoryRepository(repository);
1233
+ })();
1234
+ });
1235
+
1236
+ it('assembleTreeNodes', function() {
1237
+ (async () => {
1238
+ const repository = await creatRepository();
1239
+
1240
+ const
1241
+ id1 = repository.getById(1),
1242
+ id2 = repository.getById(2),
1243
+ id3 = repository.getById(3),
1244
+ id4 = repository.getById(4);
1245
+
1246
+ // Verify no children or parents
1247
+ expect(id2.parent).to.be.null;
1248
+ expect(id2.children).to.be.empty;
1249
+
1250
+ repository.assembleTreeNodes();
1251
+
1252
+ // Now check that they are populated
1253
+ expect(id2.parent).to.be.eq(id1);
1254
+ expect(id2.children).to.be.eql([id4]);
1255
+
1256
+ // Re-assemble them
1257
+ repository.assembleTreeNodes();
1258
+
1259
+ // check them again
1260
+ expect(id2.parent).to.be.eq(id1);
1261
+ expect(id2.children).to.be.eql([id4]);
1262
+
1263
+ destoryRepository(repository);
1264
+ })();
1265
+ });
1266
+
1267
+ it('removeTreeNode', function() {
1268
+ (async () => {
1269
+ const repository = await creatRepository();
1270
+ repository.assembleTreeNodes();
1271
+
1272
+ const
1273
+ id1 = repository.getById(1),
1274
+ id2 = repository.getById(2),
1275
+ id3 = repository.getById(3),
1276
+ id4 = repository.getById(4);
1277
+
1278
+ const before = repository.getEntities();
1279
+ expect(before.length).to.be.eq(4);
1280
+
1281
+ repository.removeTreeNode(id2);
1282
+
1283
+ const after = repository.getEntities();
1284
+ expect(after.length).to.be.eq(2);
1285
+
1286
+ destoryRepository(repository);
1287
+ })();
1288
+ });
1289
+
1069
1290
  });
1070
1291
 
1071
1292
  });
@@ -1,32 +1,2 @@
1
- const webpack = require('@cypress/webpack-preprocessor'),
2
- webpackOptions = {
3
- mode: 'development',
4
- devtool: 'cheap-module-source-map', // See https://survivejs.com/webpack/building/source-maps/
5
- module: {
6
- rules: [
7
- {
8
- test: /\.(js|jsx|mjs)$/,
9
- exclude: /node_modules\/(?!(@onehat)\/).*/,
10
- loader: 'babel-loader',
11
- options: {
12
- cacheDirectory: false,
13
- presets: [
14
- '@babel/preset-env'
15
- ],
16
- plugins: [
17
- '@babel/plugin-proposal-class-properties',
18
- '@babel/plugin-transform-runtime'
19
- ],
20
- sourceType: 'unambiguous',
21
- },
22
- }
23
- ]
24
- }
25
- };
26
-
27
- module.exports = (on, config) => {
28
- on('file:preprocessor', webpack({
29
- webpackOptions,
30
- watchOptions: {},
31
- }));
32
- };
1
+ module.exports = (on) => {
2
+ }
@@ -0,0 +1,42 @@
1
+ import { defineConfig } from "cypress";
2
+ import webpackPreprocessor from "@cypress/webpack-preprocessor";
3
+ import Webpack from "webpack";
4
+
5
+ export default defineConfig({
6
+ e2e: {
7
+ experimentalRunAllSpecs: true,
8
+ chromeWebSecurity: false,
9
+ setupNodeEvents(on) {
10
+ const options = webpackPreprocessor.defaultOptions;
11
+ if (!options.module) {
12
+ options.module = {
13
+ rules: [],
14
+ }
15
+ }
16
+ if (!options.module.rules) {
17
+ options.module.rules = [];
18
+ }
19
+ options.module.rules.push({
20
+ test: /\.(js|jsx|mjs)$/,
21
+ exclude: [/node_modules\/(?!(@onehat)\/).*/],
22
+ use: [{
23
+ loader: 'babel-loader',
24
+ options: {
25
+ cacheDirectory: false,
26
+ presets: [
27
+ '@babel/preset-env'
28
+ ],
29
+ plugins: [
30
+ '@babel/plugin-transform-class-properties',
31
+ '@babel/plugin-transform-runtime'
32
+ ],
33
+ sourceType: 'unambiguous',
34
+ },
35
+ }],
36
+
37
+ });
38
+
39
+ on('file:preprocessor', webpackPreprocessor(options));
40
+ },
41
+ }
42
+ });
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@onehat/data",
3
- "version": "1.17.0",
3
+ "version": "1.17.3",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
- "test": "npx cypress open --config-file ../cypress.json",
8
+ "test": "npx cypress open",
9
+ "test2": "DEBUG=cypress:* npx cypress open",
9
10
  "docs": "jsdoc -c ./jsdoc.json -t ./node_modules/ink-docstrap/template -R README.md"
10
11
  },
11
12
  "repository": {
@@ -35,37 +36,36 @@
35
36
  },
36
37
  "homepage": "https://github.com/OneHatRepo/data#readme",
37
38
  "dependencies": {
38
- "@onehat/events": "^1.6.5",
39
+ "@onehat/events": "^1.6.6",
39
40
  "accounting-js": "^1.1.1",
40
- "axios": "^1.2.1",
41
- "chrono-node": "^2.4.2",
42
- "fast-xml-parser": "^4.0.12",
41
+ "axios": "^1.4.0",
42
+ "chrono-node": "^2.6.3",
43
+ "fast-xml-parser": "^4.2.2",
43
44
  "he": "^1.2.0",
44
- "js-base64": "^3.7.3",
45
+ "js-base64": "^3.7.5",
45
46
  "lodash": "^4.17.21",
46
47
  "moment": "^2.29.4",
47
48
  "natsort": "^2.0.3",
48
49
  "numeral": "^2.0.6",
49
- "qs": "^6.11.0",
50
+ "qs": "^6.11.2",
50
51
  "relative-time-parser": "^1.0.15",
51
52
  "uuid": "^9.0.0"
52
53
  },
53
54
  "devDependencies": {
54
- "@babel/core": "^7.20.5",
55
- "@babel/node": "^7.20.5",
56
- "@babel/plugin-proposal-class-properties": "^7.18.6",
55
+ "@babel/core": "^7.22.1",
56
+ "@babel/node": "^7.22.1",
57
+ "@babel/plugin-transform-class-properties": "^7.22.3",
57
58
  "@babel/plugin-transform-runtime": "^7.19.6",
58
- "@babel/preset-env": "^7.20.2",
59
- "@babel/register": "^7.18.9",
60
- "@babel/runtime": "^7.20.6",
61
- "@cypress/webpack-preprocessor": "^5.16.0",
62
- "babel-loader": "^8.0.2",
63
- "cypress": "5.2.0",
59
+ "@babel/preset-env": "^7.22.4",
60
+ "@babel/register": "^7.21.0",
61
+ "@babel/runtime": "^7.22.3",
62
+ "@cypress/webpack-preprocessor": "^5.17.1",
63
+ "babel-loader": "^9.1.2",
64
+ "cypress": "12.13.0",
64
65
  "ink-docstrap": "^1.3.2",
65
- "jsdoc": "^4.0.0",
66
- "webpack": "^5.76.0",
67
- "joi": "^17.7.0",
68
- "yup": "^0.32.11"
69
-
66
+ "joi": "^17.9.2",
67
+ "jsdoc": "^4.0.2",
68
+ "webpack": "^5.85.0",
69
+ "yup": "^1.2.0"
70
70
  }
71
71
  }