@commercelayer/demo-store-types 2.2.0 → 2.3.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 CHANGED
@@ -10,7 +10,7 @@ By using this package, that operation will be much easier to do and error-proof.
10
10
 
11
11
  <img width="1158" alt="IntelliSense in Visual Studio Code" src="https://user-images.githubusercontent.com/1681269/208510718-23cd21e1-e602-41f7-8748-440bbb07d5ea.png">
12
12
 
13
- ## Data
13
+ ## Create data
14
14
 
15
15
  The Demo Store data are composed of a set of 8 JSON files usually located at `/data/json`.
16
16
 
@@ -82,9 +82,29 @@ The Demo Store data are composed of a set of 8 JSON files usually located at `/d
82
82
  )
83
83
  ```
84
84
 
85
+ ## Test data
86
+
87
+ This package is shipped with built-in tests.
88
+
89
+ You can use it inside a JavaScript file like so:
90
+
91
+ ```js
92
+ //= runTestData.js
93
+
94
+ const { testJsonData } = require('@commercelayer/demo-store-types/dist/test')
95
+
96
+ testJsonData('./data/json/')
97
+ ```
98
+
99
+ ```sh
100
+ node runTestData.js
101
+ ```
102
+
85
103
  ## Example
86
104
 
87
- Here below you can find a working example with Node.js 18 that converts a list of products coming from an external service, to the Demo Store `products.json`:
105
+ Here below you can find a working example with Node.js 18 that converts a list of products coming from an external service, to the Demo Store `products.json`.
106
+
107
+ Setup a new project from scratch:
88
108
 
89
109
  ```sh
90
110
  mkdir demo
@@ -93,6 +113,8 @@ npm init -y
93
113
  npm install typescript @types/node tsm @commercelayer/demo-store-types
94
114
  ```
95
115
 
116
+ Create a new file `index.ts`:
117
+
96
118
  ```ts
97
119
  //= index.ts
98
120
 
@@ -128,7 +150,16 @@ import { writeFile } from 'fs/promises'
128
150
  console.log(demoStoreProducts)
129
151
 
130
152
  })()
153
+ ```
154
+
155
+ Just run:
131
156
 
157
+ ```sh
158
+ node -r tsm index.ts
159
+ ```
160
+
161
+ ```ts
162
+ //= output
132
163
 
133
164
  // [
134
165
  // {
@@ -178,7 +209,3 @@ import { writeFile } from 'fs/promises'
178
209
  // }
179
210
  // ]
180
211
  ```
181
-
182
- ```sh
183
- node -r tsm index.ts
184
- ```
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs_1 = require("fs");
4
+ const data_1 = require("./data");
5
+ const path = process.argv[2];
6
+ if (!path || !(0, fs_1.existsSync)(path)) {
7
+ throw new Error(`Folder "${path}" doesn't exist!`);
8
+ }
9
+ (0, data_1.testJsonData)(path);
@@ -0,0 +1 @@
1
+ export declare function testJsonData(path: string): void;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.testJsonData = void 0;
39
+ const at_1 = __importDefault(require("lodash/at"));
40
+ const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
41
+ const set_1 = __importDefault(require("lodash/set"));
42
+ const path_1 = require("path");
43
+ const uvu_1 = require("uvu");
44
+ const assert_1 = require("uvu/assert");
45
+ const __1 = require("..");
46
+ function importJson(...paths) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ var _a;
49
+ return (yield (_a = (0, path_1.resolve)(...paths), Promise.resolve().then(() => __importStar(require(_a))))).default;
50
+ });
51
+ }
52
+ function green(test) {
53
+ test('', () => {
54
+ (0, assert_1.is)(true, true);
55
+ });
56
+ }
57
+ function testJsonData(path) {
58
+ test('catalogs.json', __1.rawDataCatalogs_schema);
59
+ test('countries.json', __1.rawDataCountries_schema);
60
+ test('languages.json', __1.rawDataLanguages_schema);
61
+ test('organization.json', __1.rawDataOrganization_schema);
62
+ test('pages.json', __1.rawDataPages_schema);
63
+ test('products.json', __1.rawDataProducts_schema);
64
+ test('taxonomies.json', __1.rawDataTaxonomies_schema);
65
+ test('taxons.json', __1.rawDataTaxons_schema);
66
+ function test(filename, schema) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ const suiteName = filename;
69
+ // const suiteName = `'${filename}' should be properly defined.`
70
+ const json = yield importJson(path, filename);
71
+ const result = schema.safeParse(json);
72
+ const test = (0, uvu_1.suite)(suiteName);
73
+ if (result.success === true) {
74
+ green(test);
75
+ }
76
+ else {
77
+ result.error.issues.forEach(issue => {
78
+ // @ts-expect-error
79
+ const expectedType = issue.expected ? ` - Expected type '${issue.expected}'` : '';
80
+ const testName = `Path '${issue.path.join('.')}' - ${issue.message}${expectedType}`;
81
+ test(testName, () => {
82
+ const actual = (0, at_1.default)(json, [issue.path[0]])[0];
83
+ const expected = (0, cloneDeep_1.default)(actual);
84
+ (0, set_1.default)(expected, issue.path.slice(1), `ERROR - ${issue.message}${expectedType}`);
85
+ (0, assert_1.equal)(actual, expected, ' ');
86
+ });
87
+ });
88
+ }
89
+ test.run();
90
+ });
91
+ }
92
+ }
93
+ exports.testJsonData = testJsonData;
@@ -0,0 +1 @@
1
+ export * from './data';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./data"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercelayer/demo-store-types",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Demo Store types",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,6 +8,9 @@
8
8
  "dist"
9
9
  ],
10
10
  "dependencies": {
11
+ "@types/lodash": "^4.14.191",
12
+ "lodash": "^4.17.21",
13
+ "uvu": "^0.5.6",
11
14
  "zod": "^3.20.6"
12
15
  },
13
16
  "devDependencies": {
@@ -22,5 +25,5 @@
22
25
  "publishConfig": {
23
26
  "access": "public"
24
27
  },
25
- "gitHead": "b0c40b8bf993413e7c97b237426e51ba436e612d"
28
+ "gitHead": "a340ec094fa518d09bda1fccbb0ae9f2265800ed"
26
29
  }