ember-headless-form-yup 1.0.0-beta.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/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # ember-headless-form-yup
2
+
3
+ Integrates [`yup`](https://github.com/jquense/yup) based schemas seamlessly with the validation support of [ember-headless-form](https://github.com/CrowdStrike/ember-headless-form).
4
+
5
+ ## Compatibility
6
+
7
+ - Ember.js v4.4 or above
8
+ - Embroider or ember-auto-import v2
9
+
10
+ ## Installation
11
+
12
+ ```
13
+ ember install ember-headless-form-yup
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ Visit our [documentation website](https://ember-headless-form.pages.dev/).
19
+
20
+ ## Contributing
21
+
22
+ See the [Contributing](CONTRIBUTING.md) guide for details.
23
+
24
+ ## License
25
+
26
+ This project is licensed under the [MIT License](LICENSE.md).
package/addon-main.cjs ADDED
@@ -0,0 +1,4 @@
1
+ 'use strict';
2
+
3
+ const { addonV1Shim } = require('@embroider/addon-shim');
4
+ module.exports = addonV1Shim(__dirname);
@@ -0,0 +1 @@
1
+ export { default } from "ember-headless-form-yup/helpers/validate-yup";
@@ -0,0 +1,10 @@
1
+ import { FormValidateCallback } from 'ember-headless-form';
2
+ import { ObjectSchema } from 'yup';
3
+ /**
4
+ * Validation helper for integrating `yup` based validations into headless forms.
5
+ *
6
+ * Pass this to the `@validate` hook, supplying the `yup` schema as the only argument: `@validate={{validateYup schema}}`.
7
+ */
8
+ declare function validateChangeset<DATA extends object>(schema: ObjectSchema<DATA>): FormValidateCallback<Partial<DATA>>;
9
+ export { validateChangeset as default };
10
+ //# sourceMappingURL=helpers/validate-yup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers/validate-yup.d.ts","sourceRoot":"","sources":["../src/helpers/validate-yup.ts"],"names":[],"mappings":"AAAA,OAAO,wBAIN,MAAM,qBAAqB,CAAC;AAG7B,OAAO,gBAAsC,MAAM,KAAK,CAAC;AAEzD;;;;GAIG;AACH,iBAAwB,iBAAiB,CAAC,IAAI,SAAS,MAAM,EAC3D,MAAM,EAAE,YAAY,CAAC,IAAI,CAAC,GACzB,oBAAoB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAkCrC"}
@@ -0,0 +1,45 @@
1
+ import { assert } from '@ember/debug';
2
+
3
+ /**
4
+ * Validation helper for integrating `yup` based validations into headless forms.
5
+ *
6
+ * Pass this to the `@validate` hook, supplying the `yup` schema as the only argument: `@validate={{validateYup schema}}`.
7
+ */
8
+ function validateChangeset(schema) {
9
+ return async formData => {
10
+ try {
11
+ await schema.validate(formData, {
12
+ abortEarly: false
13
+ });
14
+ } catch (e) {
15
+ const validationError = e;
16
+ const errorRecord = {};
17
+ for (const {
18
+ path,
19
+ type,
20
+ value,
21
+ message
22
+ } of validationError.inner) {
23
+ assert('Received undefined path for yup validation error. If you see this, please report it as a bug to ember-headless-form!', path !== undefined);
24
+ const key = path; // yup maybe could have stricter types here, as path will always refer to a key of its schema
25
+
26
+ if (!errorRecord[key]) {
27
+ errorRecord[key] = [];
28
+ }
29
+ const errors = errorRecord[key];
30
+ assert('Expected errorRecord to have array', errors); // TS does not understand errors cannot be undefined at this point
31
+
32
+ errors.push({
33
+ type: type ?? 'unknown',
34
+ value,
35
+ message
36
+ });
37
+ }
38
+ return errorRecord;
39
+ }
40
+ return undefined;
41
+ };
42
+ }
43
+
44
+ export { validateChangeset as default };
45
+ //# sourceMappingURL=validate-yup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-yup.js","sources":["../../src/helpers/validate-yup.ts"],"sourcesContent":["import type {\n ErrorRecord,\n FormKey,\n FormValidateCallback,\n} from 'ember-headless-form';\nimport { assert } from '@ember/debug';\n\nimport type { ObjectSchema, ValidationError } from 'yup';\n\n/**\n * Validation helper for integrating `yup` based validations into headless forms.\n *\n * Pass this to the `@validate` hook, supplying the `yup` schema as the only argument: `@validate={{validateYup schema}}`.\n */\nexport default function validateChangeset<DATA extends object>(\n schema: ObjectSchema<DATA>\n): FormValidateCallback<Partial<DATA>> {\n return async (formData) => {\n try {\n await schema.validate(formData, { abortEarly: false });\n } catch (e) {\n const validationError = e as ValidationError;\n const errorRecord: ErrorRecord<DATA> = {};\n\n for (const { path, type, value, message } of validationError.inner) {\n assert(\n 'Received undefined path for yup validation error. If you see this, please report it as a bug to ember-headless-form!',\n path !== undefined\n );\n const key = path as FormKey<DATA>; // yup maybe could have stricter types here, as path will always refer to a key of its schema\n\n if (!errorRecord[key]) {\n errorRecord[key] = [];\n }\n\n const errors = errorRecord[key];\n assert('Expected errorRecord to have array', errors); // TS does not understand errors cannot be undefined at this point\n\n errors.push({\n type: type ?? 'unknown',\n value,\n message,\n });\n }\n\n return errorRecord;\n }\n\n return undefined;\n };\n}\n"],"names":["validateChangeset","schema","formData","validate","abortEarly","e","validationError","errorRecord","path","type","value","message","inner","assert","undefined","key","errors","push"],"mappings":";;AASA;AACA;AACA;AACA;AACA;AACe,SAASA,iBAAiB,CACvCC,MAA0B,EACW;EACrC,OAAO,MAAOC,QAAQ,IAAK;IACzB,IAAI;AACF,MAAA,MAAMD,MAAM,CAACE,QAAQ,CAACD,QAAQ,EAAE;AAAEE,QAAAA,UAAU,EAAE,KAAA;AAAM,OAAC,CAAC,CAAA;KACvD,CAAC,OAAOC,CAAC,EAAE;MACV,MAAMC,eAAe,GAAGD,CAAoB,CAAA;MAC5C,MAAME,WAA8B,GAAG,EAAE,CAAA;AAEzC,MAAA,KAAK,MAAM;QAAEC,IAAI;QAAEC,IAAI;QAAEC,KAAK;AAAEC,QAAAA,OAAAA;AAAQ,OAAC,IAAIL,eAAe,CAACM,KAAK,EAAE;AAClEC,QAAAA,MAAM,CACJ,sHAAsH,EACtHL,IAAI,KAAKM,SAAS,CACnB,CAAA;AACD,QAAA,MAAMC,GAAG,GAAGP,IAAqB,CAAC;;AAElC,QAAA,IAAI,CAACD,WAAW,CAACQ,GAAG,CAAC,EAAE;AACrBR,UAAAA,WAAW,CAACQ,GAAG,CAAC,GAAG,EAAE,CAAA;AACvB,SAAA;AAEA,QAAA,MAAMC,MAAM,GAAGT,WAAW,CAACQ,GAAG,CAAC,CAAA;AAC/BF,QAAAA,MAAM,CAAC,oCAAoC,EAAEG,MAAM,CAAC,CAAC;;QAErDA,MAAM,CAACC,IAAI,CAAC;UACVR,IAAI,EAAEA,IAAI,IAAI,SAAS;UACvBC,KAAK;AACLC,UAAAA,OAAAA;AACF,SAAC,CAAC,CAAA;AACJ,OAAA;AAEA,MAAA,OAAOJ,WAAW,CAAA;AACpB,KAAA;AAEA,IAAA,OAAOO,SAAS,CAAA;GACjB,CAAA;AACH;;;;"}
@@ -0,0 +1 @@
1
+ export { default as validateYup } from "./helpers/validate-yup.js";
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { default as validateYup } from './helpers/validate-yup.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import validateYup from "./helpers/validate-yup.js";
2
+ interface Registry {
3
+ validateYup: typeof validateYup;
4
+ 'validate-yup': typeof validateYup;
5
+ }
6
+ export { Registry as default };
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=template-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-registry.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,113 @@
1
+ {
2
+ "name": "ember-headless-form-yup",
3
+ "version": "1.0.0-beta.0",
4
+ "description": "Integrates yup-based validations with ember-headless-form",
5
+ "keywords": [
6
+ "ember-addon"
7
+ ],
8
+ "repository": "https://github.com/CrowdStrike/ember-headless-form.git",
9
+ "license": "MIT",
10
+ "author": "CrowdStrike UX Team",
11
+ "files": [
12
+ "addon-main.cjs",
13
+ "dist"
14
+ ],
15
+ "dependencies": {
16
+ "@embroider/addon-shim": "^1.0.0",
17
+ "ember-functions-as-helper-polyfill": "^2.1.1"
18
+ },
19
+ "peerDependencies": {
20
+ "yup": "^1.0.0",
21
+ "ember-headless-form": "^1.0.0-beta.0",
22
+ "ember-source": ">=4.4.0"
23
+ },
24
+ "devDependencies": {
25
+ "@babel/core": "^7.17.0",
26
+ "@babel/preset-typescript": "^7.18.6",
27
+ "@babel/plugin-proposal-class-properties": "^7.16.7",
28
+ "@babel/plugin-proposal-decorators": "^7.17.0",
29
+ "@babel/plugin-syntax-decorators": "^7.17.0",
30
+ "ember-headless-form": "^1.0.0-beta.0",
31
+ "@embroider/addon-dev": "^3.0.0",
32
+ "@glimmer/component": "^1.1.2",
33
+ "@glint/core": "^1.0.0-beta.3",
34
+ "@glint/environment-ember-loose": "^1.0.0-beta.3",
35
+ "@glint/template": "^1.0.0-beta.3",
36
+ "@tsconfig/ember": "^1.0.0",
37
+ "@types/ember": "^4.0.0",
38
+ "@types/ember__object": "^4.0.0",
39
+ "@types/ember__service": "^4.0.0",
40
+ "@types/ember__controller": "^4.0.0",
41
+ "@types/ember__string": "^3.16.0",
42
+ "@types/ember__template": "^4.0.0",
43
+ "@types/ember__polyfills": "^4.0.0",
44
+ "@types/ember__utils": "^4.0.0",
45
+ "@types/ember__runloop": "^4.0.0",
46
+ "@types/ember__debug": "^4.0.0",
47
+ "@types/ember__engine": "^4.0.0",
48
+ "@types/ember__application": "^4.0.0",
49
+ "@types/ember__test": "^4.0.0",
50
+ "@types/ember__array": "^4.0.0",
51
+ "@types/ember__error": "^4.0.0",
52
+ "@types/ember__component": "^4.0.0",
53
+ "@types/ember__routing": "^4.0.0",
54
+ "@typescript-eslint/eslint-plugin": "^5.30.5",
55
+ "@typescript-eslint/parser": "^5.30.5",
56
+ "concurrently": "^7.2.1",
57
+ "ember-template-lint": "^4.0.0",
58
+ "ember-source": "~4.10.0",
59
+ "eslint": "^7.32.0",
60
+ "eslint-config-prettier": "^8.3.0",
61
+ "eslint-plugin-ember": "^10.5.8",
62
+ "eslint-plugin-node": "^11.1.0",
63
+ "eslint-plugin-prettier": "^4.0.0",
64
+ "prettier": "^2.5.1",
65
+ "rollup": "^2.67.0",
66
+ "rollup-plugin-copy": "^3.4.0",
67
+ "rollup-plugin-ts": "^3.0.2",
68
+ "typescript": "^4.7.4",
69
+ "yup": "^1.0.0",
70
+ "webpack": "^5.75.0"
71
+ },
72
+ "publishConfig": {
73
+ "registry": "https://registry.npmjs.org"
74
+ },
75
+ "ember": {
76
+ "edition": "octane"
77
+ },
78
+ "ember-addon": {
79
+ "version": 2,
80
+ "type": "addon",
81
+ "main": "addon-main.cjs",
82
+ "app-js": {
83
+ "./helpers/validate-yup.js": "./dist/_app_/helpers/validate-yup.js"
84
+ }
85
+ },
86
+ "exports": {
87
+ ".": "./dist/index.js",
88
+ "./*": {
89
+ "types": "./dist/*.d.ts",
90
+ "default": "./dist/*.js"
91
+ },
92
+ "./addon-main.js": "./addon-main.cjs"
93
+ },
94
+ "typesVersions": {
95
+ "*": {
96
+ "*": [
97
+ "dist/*"
98
+ ]
99
+ }
100
+ },
101
+ "scripts": {
102
+ "build": "rollup --config",
103
+ "lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
104
+ "lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
105
+ "lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
106
+ "lint:js": "eslint . --cache",
107
+ "lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
108
+ "lint:js:fix": "eslint . --fix",
109
+ "lint:types": "glint",
110
+ "start": "rollup --config --watch",
111
+ "test": "echo 'A v2 addon does not have tests, run tests in test-app'"
112
+ }
113
+ }