@cratis/arc 18.7.9 → 18.7.11
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/dist/cjs/queries/ObservableQueryFor.d.ts.map +1 -1
- package/dist/cjs/queries/ObservableQueryFor.js +3 -1
- package/dist/cjs/queries/ObservableQueryFor.js.map +1 -1
- package/dist/cjs/validation/RuleBuilderExtensions.d.ts +4 -0
- package/dist/cjs/validation/RuleBuilderExtensions.d.ts.map +1 -1
- package/dist/cjs/validation/RuleBuilderExtensions.js +14 -0
- package/dist/cjs/validation/RuleBuilderExtensions.js.map +1 -1
- package/dist/cjs/validation/index.js +2 -0
- package/dist/cjs/validation/index.js.map +1 -1
- package/dist/cjs/validation/rules/PhoneRule.d.ts +7 -0
- package/dist/cjs/validation/rules/PhoneRule.d.ts.map +1 -0
- package/dist/cjs/validation/rules/PhoneRule.js +19 -0
- package/dist/cjs/validation/rules/PhoneRule.js.map +1 -0
- package/dist/cjs/validation/rules/UrlRule.d.ts +7 -0
- package/dist/cjs/validation/rules/UrlRule.d.ts.map +1 -0
- package/dist/cjs/validation/rules/UrlRule.js +19 -0
- package/dist/cjs/validation/rules/UrlRule.js.map +1 -0
- package/dist/esm/queries/ObservableQueryFor.d.ts.map +1 -1
- package/dist/esm/queries/ObservableQueryFor.js +3 -1
- package/dist/esm/queries/ObservableQueryFor.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/validation/RuleBuilderExtensions.d.ts +4 -0
- package/dist/esm/validation/RuleBuilderExtensions.d.ts.map +1 -1
- package/dist/esm/validation/RuleBuilderExtensions.js +13 -1
- package/dist/esm/validation/RuleBuilderExtensions.js.map +1 -1
- package/dist/esm/validation/index.js +1 -1
- package/dist/esm/validation/rules/PhoneRule.d.ts +7 -0
- package/dist/esm/validation/rules/PhoneRule.d.ts.map +1 -0
- package/dist/esm/validation/rules/PhoneRule.js +17 -0
- package/dist/esm/validation/rules/PhoneRule.js.map +1 -0
- package/dist/esm/validation/rules/UrlRule.d.ts +7 -0
- package/dist/esm/validation/rules/UrlRule.d.ts.map +1 -0
- package/dist/esm/validation/rules/UrlRule.js +17 -0
- package/dist/esm/validation/rules/UrlRule.js.map +1 -0
- package/package.json +1 -1
- package/queries/ObservableQueryFor.ts +3 -1
- package/validation/RuleBuilderExtensions.ts +28 -0
- package/validation/rules/PhoneRule.ts +28 -0
- package/validation/rules/UrlRule.ts +28 -0
|
@@ -5,6 +5,8 @@ export declare function minLength<T>(this: RuleBuilder<T, string>, length: numbe
|
|
|
5
5
|
export declare function maxLength<T>(this: RuleBuilder<T, string>, length: number): RuleBuilder<T, string>;
|
|
6
6
|
export declare function length<T>(this: RuleBuilder<T, string>, min: number, max: number): RuleBuilder<T, string>;
|
|
7
7
|
export declare function emailAddress<T>(this: RuleBuilder<T, string>): RuleBuilder<T, string>;
|
|
8
|
+
export declare function phone<T>(this: RuleBuilder<T, string>): RuleBuilder<T, string>;
|
|
9
|
+
export declare function url<T>(this: RuleBuilder<T, string>): RuleBuilder<T, string>;
|
|
8
10
|
export declare function matches<T>(this: RuleBuilder<T, string>, pattern: RegExp, errorMessage?: string): RuleBuilder<T, string>;
|
|
9
11
|
export declare function greaterThan<T>(this: RuleBuilder<T, number>, threshold: number): RuleBuilder<T, number>;
|
|
10
12
|
export declare function greaterThanOrEqual<T>(this: RuleBuilder<T, number>, threshold: number): RuleBuilder<T, number>;
|
|
@@ -18,6 +20,8 @@ declare module './RuleBuilder' {
|
|
|
18
20
|
maxLength(length: number): RuleBuilder<T, TProperty>;
|
|
19
21
|
length(min: number, max: number): RuleBuilder<T, TProperty>;
|
|
20
22
|
emailAddress(): RuleBuilder<T, TProperty>;
|
|
23
|
+
phone(): RuleBuilder<T, TProperty>;
|
|
24
|
+
url(): RuleBuilder<T, TProperty>;
|
|
21
25
|
matches(pattern: RegExp, errorMessage?: string): RuleBuilder<T, TProperty>;
|
|
22
26
|
greaterThan(threshold: number): RuleBuilder<T, TProperty>;
|
|
23
27
|
greaterThanOrEqual(threshold: number): RuleBuilder<T, TProperty>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RuleBuilderExtensions.d.ts","sourceRoot":"","sources":["../../../validation/RuleBuilderExtensions.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"RuleBuilderExtensions.d.ts","sourceRoot":"","sources":["../../../validation/RuleBuilderExtensions.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAoB5C,wBAAgB,QAAQ,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAGjG;AASD,wBAAgB,OAAO,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAGhG;AASD,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,CAGjG;AASD,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,CAGjG;AAUD,wBAAgB,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,CAGxG;AAQD,wBAAgB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,WA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from './rules/LengthRules.js';
|
|
4
4
|
import { EmailRule } from './rules/EmailRule.js';
|
|
5
|
+
import { PhoneRule } from './rules/PhoneRule.js';
|
|
6
|
+
import { UrlRule } from './rules/UrlRule.js';
|
|
5
7
|
import { RegexRule } from './rules/RegexRule.js';
|
|
6
8
|
import { GreaterThanRule, GreaterThanOrEqualRule, LessThanRule, LessThanOrEqualRule } from './rules/ComparisonRules.js';
|
|
7
9
|
|
|
@@ -29,6 +31,14 @@ function emailAddress() {
|
|
|
29
31
|
const propertyAccessor = this._propertyAccessor;
|
|
30
32
|
return this.addRule(new EmailRule(propertyAccessor));
|
|
31
33
|
}
|
|
34
|
+
function phone() {
|
|
35
|
+
const propertyAccessor = this._propertyAccessor;
|
|
36
|
+
return this.addRule(new PhoneRule(propertyAccessor));
|
|
37
|
+
}
|
|
38
|
+
function url() {
|
|
39
|
+
const propertyAccessor = this._propertyAccessor;
|
|
40
|
+
return this.addRule(new UrlRule(propertyAccessor));
|
|
41
|
+
}
|
|
32
42
|
function matches(pattern, errorMessage) {
|
|
33
43
|
const propertyAccessor = this._propertyAccessor;
|
|
34
44
|
return this.addRule(new RegexRule(propertyAccessor, pattern, errorMessage));
|
|
@@ -55,11 +65,13 @@ RuleBuilder.prototype.minLength = minLength;
|
|
|
55
65
|
RuleBuilder.prototype.maxLength = maxLength;
|
|
56
66
|
RuleBuilder.prototype.length = length;
|
|
57
67
|
RuleBuilder.prototype.emailAddress = emailAddress;
|
|
68
|
+
RuleBuilder.prototype.phone = phone;
|
|
69
|
+
RuleBuilder.prototype.url = url;
|
|
58
70
|
RuleBuilder.prototype.matches = matches;
|
|
59
71
|
RuleBuilder.prototype.greaterThan = greaterThan;
|
|
60
72
|
RuleBuilder.prototype.greaterThanOrEqual = greaterThanOrEqual;
|
|
61
73
|
RuleBuilder.prototype.lessThan = lessThan;
|
|
62
74
|
RuleBuilder.prototype.lessThanOrEqual = lessThanOrEqual;
|
|
63
75
|
|
|
64
|
-
export { emailAddress, greaterThan, greaterThanOrEqual, length, lessThan, lessThanOrEqual, matches, maxLength, minLength, notEmpty, notNull };
|
|
76
|
+
export { emailAddress, greaterThan, greaterThanOrEqual, length, lessThan, lessThanOrEqual, matches, maxLength, minLength, notEmpty, notNull, phone, url };
|
|
65
77
|
//# sourceMappingURL=RuleBuilderExtensions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RuleBuilderExtensions.js","sources":["../../../validation/RuleBuilderExtensions.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { RuleBuilder } from './RuleBuilder';\nimport { NotEmptyRule, NotNullRule } from './rules/NotEmptyRule';\nimport { MinLengthRule, MaxLengthRule, LengthRule } from './rules/LengthRules';\nimport { EmailRule } from './rules/EmailRule';\nimport { RegexRule } from './rules/RegexRule';\nimport { GreaterThanRule, GreaterThanOrEqualRule, LessThanRule, LessThanOrEqualRule } from './rules/ComparisonRules';\n\n/**\n * Extension methods for {@link RuleBuilder} to add validation rules in a fluent manner.\n */\n\n/**\n * Add a rule that the property must not be empty (not null, undefined, empty string, or empty array).\n * @template T The type being validated.\n * @template TProperty The type of the property.\n * @param this The rule builder instance.\n * @returns The rule builder for chaining.\n */\nexport function notEmpty<T, TProperty>(this: RuleBuilder<T, TProperty>): RuleBuilder<T, TProperty> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => TProperty })._propertyAccessor;\n return this.addRule(new NotEmptyRule<T>(propertyAccessor));\n}\n\n/**\n * Add a rule that the property must not be null or undefined.\n * @template T The type being validated.\n * @template TProperty The type of the property.\n * @param this The rule builder instance.\n * @returns The rule builder for chaining.\n */\nexport function notNull<T, TProperty>(this: RuleBuilder<T, TProperty>): RuleBuilder<T, TProperty> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => TProperty })._propertyAccessor;\n return this.addRule(new NotNullRule<T>(propertyAccessor));\n}\n\n/**\n * Add a rule that the string property must have at least the specified length.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param length The minimum length.\n * @returns The rule builder for chaining.\n */\nexport function minLength<T>(this: RuleBuilder<T, string>, length: number): RuleBuilder<T, string> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;\n return this.addRule(new MinLengthRule<T>(propertyAccessor, length));\n}\n\n/**\n * Add a rule that the string property must have at most the specified length.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param length The maximum length.\n * @returns The rule builder for chaining.\n */\nexport function maxLength<T>(this: RuleBuilder<T, string>, length: number): RuleBuilder<T, string> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;\n return this.addRule(new MaxLengthRule<T>(propertyAccessor, length));\n}\n\n/**\n * Add a rule that the string property must have a length between min and max.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param min The minimum length.\n * @param max The maximum length.\n * @returns The rule builder for chaining.\n */\nexport function length<T>(this: RuleBuilder<T, string>, min: number, max: number): RuleBuilder<T, string> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;\n return this.addRule(new LengthRule<T>(propertyAccessor, min, max));\n}\n\n/**\n * Add a rule that the string property must be a valid email address.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @returns The rule builder for chaining.\n */\nexport function emailAddress<T>(this: RuleBuilder<T, string>): RuleBuilder<T, string> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;\n return this.addRule(new EmailRule<T>(propertyAccessor));\n}\n\n/**\n * Add a rule that the string property must match the specified regular expression.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param pattern The regular expression pattern.\n * @param errorMessage Optional error message.\n * @returns The rule builder for chaining.\n */\nexport function matches<T>(this: RuleBuilder<T, string>, pattern: RegExp, errorMessage?: string): RuleBuilder<T, string> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;\n return this.addRule(new RegexRule<T>(propertyAccessor, pattern, errorMessage));\n}\n\n/**\n * Add a rule that the number property must be greater than the specified value.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param threshold The value to compare against.\n * @returns The rule builder for chaining.\n */\nexport function greaterThan<T>(this: RuleBuilder<T, number>, threshold: number): RuleBuilder<T, number> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => number })._propertyAccessor;\n return this.addRule(new GreaterThanRule<T>(propertyAccessor, threshold));\n}\n\n/**\n * Add a rule that the number property must be greater than or equal to the specified value.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param threshold The value to compare against.\n * @returns The rule builder for chaining.\n */\nexport function greaterThanOrEqual<T>(this: RuleBuilder<T, number>, threshold: number): RuleBuilder<T, number> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => number })._propertyAccessor;\n return this.addRule(new GreaterThanOrEqualRule<T>(propertyAccessor, threshold));\n}\n\n/**\n * Add a rule that the number property must be less than the specified value.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param threshold The value to compare against.\n * @returns The rule builder for chaining.\n */\nexport function lessThan<T>(this: RuleBuilder<T, number>, threshold: number): RuleBuilder<T, number> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => number })._propertyAccessor;\n return this.addRule(new LessThanRule<T>(propertyAccessor, threshold));\n}\n\n/**\n * Add a rule that the number property must be less than or equal to the specified value.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param threshold The value to compare against.\n * @returns The rule builder for chaining.\n */\nexport function lessThanOrEqual<T>(this: RuleBuilder<T, number>, threshold: number): RuleBuilder<T, number> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => number })._propertyAccessor;\n return this.addRule(new LessThanOrEqualRule<T>(propertyAccessor, threshold));\n}\n\n// Add the extension methods to the RuleBuilder prototype\nRuleBuilder.prototype.notEmpty = notEmpty;\nRuleBuilder.prototype.notNull = notNull;\n(RuleBuilder.prototype as unknown as { minLength: typeof minLength }).minLength = minLength;\n(RuleBuilder.prototype as unknown as { maxLength: typeof maxLength }).maxLength = maxLength;\n(RuleBuilder.prototype as unknown as { length: typeof length }).length = length;\n(RuleBuilder.prototype as unknown as { emailAddress: typeof emailAddress }).emailAddress = emailAddress;\n(RuleBuilder.prototype as unknown as { matches: typeof matches }).matches = matches;\n(RuleBuilder.prototype as unknown as { greaterThan: typeof greaterThan }).greaterThan = greaterThan;\n(RuleBuilder.prototype as unknown as { greaterThanOrEqual: typeof greaterThanOrEqual }).greaterThanOrEqual = greaterThanOrEqual;\n(RuleBuilder.prototype as unknown as { lessThan: typeof lessThan }).lessThan = lessThan;\n(RuleBuilder.prototype as unknown as { lessThanOrEqual: typeof lessThanOrEqual }).lessThanOrEqual = lessThanOrEqual;\n\n// Extend the RuleBuilder interface to include these methods\ndeclare module './RuleBuilder' {\n interface RuleBuilder<T, TProperty> {\n notEmpty(): RuleBuilder<T, TProperty>;\n notNull(): RuleBuilder<T, TProperty>;\n minLength(length: number): RuleBuilder<T, TProperty>;\n maxLength(length: number): RuleBuilder<T, TProperty>;\n length(min: number, max: number): RuleBuilder<T, TProperty>;\n emailAddress(): RuleBuilder<T, TProperty>;\n matches(pattern: RegExp, errorMessage?: string): RuleBuilder<T, TProperty>;\n greaterThan(threshold: number): RuleBuilder<T, TProperty>;\n greaterThanOrEqual(threshold: number): RuleBuilder<T, TProperty>;\n lessThan(threshold: number): RuleBuilder<T, TProperty>;\n lessThanOrEqual(threshold: number): RuleBuilder<T, TProperty>;\n }\n}\n"],"names":[],"mappings":";;;;;;;SAqBgB,QAAQ,GAAA;AACpB,IAAA,MAAM,gBAAgB,GAAI,IAAqE,CAAC,iBAAiB;IACjH,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,YAAY,CAAI,gBAAgB,CAAC,CAAC;AAC9D;SASgB,OAAO,GAAA;AACnB,IAAA,MAAM,gBAAgB,GAAI,IAAqE,CAAC,iBAAiB;IACjH,OAAO,IAAI,CAAC,OAAO,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reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { RuleBuilder } from './RuleBuilder';\nimport { NotEmptyRule, NotNullRule } from './rules/NotEmptyRule';\nimport { MinLengthRule, MaxLengthRule, LengthRule } from './rules/LengthRules';\nimport { EmailRule } from './rules/EmailRule';\nimport { PhoneRule } from './rules/PhoneRule';\nimport { UrlRule } from './rules/UrlRule';\nimport { RegexRule } from './rules/RegexRule';\nimport { GreaterThanRule, GreaterThanOrEqualRule, LessThanRule, LessThanOrEqualRule } from './rules/ComparisonRules';\n\n/**\n * Extension methods for {@link RuleBuilder} to add validation rules in a fluent manner.\n */\n\n/**\n * Add a rule that the property must not be empty (not null, undefined, empty string, or empty array).\n * @template T The type being validated.\n * @template TProperty The type of the property.\n * @param this The rule builder instance.\n * @returns The rule builder for chaining.\n */\nexport function notEmpty<T, TProperty>(this: RuleBuilder<T, TProperty>): RuleBuilder<T, TProperty> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => TProperty })._propertyAccessor;\n return this.addRule(new NotEmptyRule<T>(propertyAccessor));\n}\n\n/**\n * Add a rule that the property must not be null or undefined.\n * @template T The type being validated.\n * @template TProperty The type of the property.\n * @param this The rule builder instance.\n * @returns The rule builder for chaining.\n */\nexport function notNull<T, TProperty>(this: RuleBuilder<T, TProperty>): RuleBuilder<T, TProperty> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => TProperty })._propertyAccessor;\n return this.addRule(new NotNullRule<T>(propertyAccessor));\n}\n\n/**\n * Add a rule that the string property must have at least the specified length.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param length The minimum length.\n * @returns The rule builder for chaining.\n */\nexport function minLength<T>(this: RuleBuilder<T, string>, length: number): RuleBuilder<T, string> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;\n return this.addRule(new MinLengthRule<T>(propertyAccessor, length));\n}\n\n/**\n * Add a rule that the string property must have at most the specified length.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param length The maximum length.\n * @returns The rule builder for chaining.\n */\nexport function maxLength<T>(this: RuleBuilder<T, string>, length: number): RuleBuilder<T, string> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;\n return this.addRule(new MaxLengthRule<T>(propertyAccessor, length));\n}\n\n/**\n * Add a rule that the string property must have a length between min and max.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param min The minimum length.\n * @param max The maximum length.\n * @returns The rule builder for chaining.\n */\nexport function length<T>(this: RuleBuilder<T, string>, min: number, max: number): RuleBuilder<T, string> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;\n return this.addRule(new LengthRule<T>(propertyAccessor, min, max));\n}\n\n/**\n * Add a rule that the string property must be a valid email address.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @returns The rule builder for chaining.\n */\nexport function emailAddress<T>(this: RuleBuilder<T, string>): RuleBuilder<T, string> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;\n return this.addRule(new EmailRule<T>(propertyAccessor));\n}\n\n/**\n * Add a rule that the string property must be a valid phone number.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @returns The rule builder for chaining.\n */\nexport function phone<T>(this: RuleBuilder<T, string>): RuleBuilder<T, string> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;\n return this.addRule(new PhoneRule<T>(propertyAccessor));\n}\n\n/**\n * Add a rule that the string property must be a valid URL.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @returns The rule builder for chaining.\n */\nexport function url<T>(this: RuleBuilder<T, string>): RuleBuilder<T, string> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;\n return this.addRule(new UrlRule<T>(propertyAccessor));\n}\n\n/**\n * Add a rule that the string property must match the specified regular expression.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param pattern The regular expression pattern.\n * @param errorMessage Optional error message.\n * @returns The rule builder for chaining.\n */\nexport function matches<T>(this: RuleBuilder<T, string>, pattern: RegExp, errorMessage?: string): RuleBuilder<T, string> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;\n return this.addRule(new RegexRule<T>(propertyAccessor, pattern, errorMessage));\n}\n\n/**\n * Add a rule that the number property must be greater than the specified value.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param threshold The value to compare against.\n * @returns The rule builder for chaining.\n */\nexport function greaterThan<T>(this: RuleBuilder<T, number>, threshold: number): RuleBuilder<T, number> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => number })._propertyAccessor;\n return this.addRule(new GreaterThanRule<T>(propertyAccessor, threshold));\n}\n\n/**\n * Add a rule that the number property must be greater than or equal to the specified value.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param threshold The value to compare against.\n * @returns The rule builder for chaining.\n */\nexport function greaterThanOrEqual<T>(this: RuleBuilder<T, number>, threshold: number): RuleBuilder<T, number> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => number })._propertyAccessor;\n return this.addRule(new GreaterThanOrEqualRule<T>(propertyAccessor, threshold));\n}\n\n/**\n * Add a rule that the number property must be less than the specified value.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param threshold The value to compare against.\n * @returns The rule builder for chaining.\n */\nexport function lessThan<T>(this: RuleBuilder<T, number>, threshold: number): RuleBuilder<T, number> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => number })._propertyAccessor;\n return this.addRule(new LessThanRule<T>(propertyAccessor, threshold));\n}\n\n/**\n * Add a rule that the number property must be less than or equal to the specified value.\n * @template T The type being validated.\n * @param this The rule builder instance.\n * @param threshold The value to compare against.\n * @returns The rule builder for chaining.\n */\nexport function lessThanOrEqual<T>(this: RuleBuilder<T, number>, threshold: number): RuleBuilder<T, number> {\n const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => number })._propertyAccessor;\n return this.addRule(new LessThanOrEqualRule<T>(propertyAccessor, threshold));\n}\n\n// Add the extension methods to the RuleBuilder prototype\nRuleBuilder.prototype.notEmpty = notEmpty;\nRuleBuilder.prototype.notNull = notNull;\n(RuleBuilder.prototype as unknown as { minLength: typeof minLength }).minLength = minLength;\n(RuleBuilder.prototype as unknown as { maxLength: typeof maxLength }).maxLength = maxLength;\n(RuleBuilder.prototype as unknown as { length: typeof length }).length = length;\n(RuleBuilder.prototype as unknown as { emailAddress: typeof emailAddress }).emailAddress = emailAddress;\n(RuleBuilder.prototype as unknown as { phone: typeof phone }).phone = phone;\n(RuleBuilder.prototype as unknown as { url: typeof url }).url = url;\n(RuleBuilder.prototype as unknown as { matches: typeof matches }).matches = matches;\n(RuleBuilder.prototype as unknown as { greaterThan: typeof greaterThan }).greaterThan = greaterThan;\n(RuleBuilder.prototype as unknown as { greaterThanOrEqual: typeof greaterThanOrEqual }).greaterThanOrEqual = greaterThanOrEqual;\n(RuleBuilder.prototype as unknown as { lessThan: typeof lessThan }).lessThan = lessThan;\n(RuleBuilder.prototype as unknown as { lessThanOrEqual: typeof lessThanOrEqual }).lessThanOrEqual = lessThanOrEqual;\n\n// Extend the RuleBuilder interface to include these methods\ndeclare module './RuleBuilder' {\n interface RuleBuilder<T, TProperty> {\n notEmpty(): RuleBuilder<T, TProperty>;\n notNull(): RuleBuilder<T, TProperty>;\n minLength(length: number): RuleBuilder<T, TProperty>;\n maxLength(length: number): RuleBuilder<T, TProperty>;\n length(min: number, max: number): RuleBuilder<T, TProperty>;\n emailAddress(): RuleBuilder<T, TProperty>;\n phone(): RuleBuilder<T, TProperty>;\n url(): RuleBuilder<T, TProperty>;\n matches(pattern: RegExp, errorMessage?: string): RuleBuilder<T, TProperty>;\n greaterThan(threshold: number): RuleBuilder<T, TProperty>;\n greaterThanOrEqual(threshold: number): RuleBuilder<T, TProperty>;\n lessThan(threshold: number): RuleBuilder<T, TProperty>;\n lessThanOrEqual(threshold: number):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AG,QAAQ;AACzC,WAAW,CAAC,SAAS,CAAC,OAAO,GAAG,OAAO;AACtC,WAAW,CAAC,SAAwD,CAAC,SAAS,GAAG,SAAS;AAC1F,WAAW,CAAC,SAAwD,CAAC,SAAS,GAAG,SAAS;AAC1F,WAAW,CAAC,SAAkD,CAAC,MAAM,GAAG,MAAM;AAC9E,WAAW,CAAC,SAA8D,CAAC,YAAY,GAAG,YAAY;AACtG,WAAW,CAAC,SAAgD,CAAC,KAAK,GAAG,KAAK;AAC1E,WAAW,CAAC,SAA4C,CAAC,GAAG,GAAG,GAAG;AAClE,WAAW,CAAC,SAAoD,CAAC,OAAO,GAAG,OAAO;AAClF,WAAW,CAAC,SAA4D,CAAC,WAAW,GAAG,WAAW;AAClG,WAAW,CAAC,SAA0E,CAAC,kBAAkB,GAAG,kBAAkB;AAC9H,WAAW,CAAC,SAAsD,CAAC,QAAQ,GAAG,QAAQ;AACtF,WAAW,CAAC,SAAoE,CAAC,eAAe,GAAG,eAAe;;;;"}
|
|
@@ -4,7 +4,7 @@ export { ValidationResultSeverity } from './ValidationResultSeverity.js';
|
|
|
4
4
|
export { PropertyValidator } from './PropertyValidator.js';
|
|
5
5
|
export { PropertyRule } from './PropertyRule.js';
|
|
6
6
|
export { RuleBuilder } from './RuleBuilder.js';
|
|
7
|
-
export { emailAddress, greaterThan, greaterThanOrEqual, length, lessThan, lessThanOrEqual, matches, maxLength, minLength, notEmpty, notNull } from './RuleBuilderExtensions.js';
|
|
7
|
+
export { emailAddress, greaterThan, greaterThanOrEqual, length, lessThan, lessThanOrEqual, matches, maxLength, minLength, notEmpty, notNull, phone, url } from './RuleBuilderExtensions.js';
|
|
8
8
|
export { NotEmptyRule, NotNullRule } from './rules/NotEmptyRule.js';
|
|
9
9
|
export { LengthRule, MaxLengthRule, MinLengthRule } from './rules/LengthRules.js';
|
|
10
10
|
export { EmailRule } from './rules/EmailRule.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PropertyRule } from '../PropertyRule';
|
|
2
|
+
export declare class PhoneRule<T> extends PropertyRule<T, string> {
|
|
3
|
+
private static readonly phoneRegex;
|
|
4
|
+
constructor(propertyAccessor: (instance: T) => string);
|
|
5
|
+
protected isValid(value: string): boolean;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=PhoneRule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PhoneRule.d.ts","sourceRoot":"","sources":["../../../../validation/rules/PhoneRule.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAM/C,qBAAa,SAAS,CAAC,CAAC,CAAE,SAAQ,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC;IACrD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAmB;gBAMzC,gBAAgB,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,MAAM;IAKrD,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAM5C"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PropertyRule } from '../PropertyRule.js';
|
|
2
|
+
|
|
3
|
+
class PhoneRule extends PropertyRule {
|
|
4
|
+
static phoneRegex = /^[\d\s()+-]+$/;
|
|
5
|
+
constructor(propertyAccessor) {
|
|
6
|
+
super(propertyAccessor, "'{PropertyName}' is not a valid phone number.");
|
|
7
|
+
}
|
|
8
|
+
isValid(value) {
|
|
9
|
+
if (value === null || value === undefined || value === '') {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
return PhoneRule.phoneRegex.test(value);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { PhoneRule };
|
|
17
|
+
//# sourceMappingURL=PhoneRule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PhoneRule.js","sources":["../../../../validation/rules/PhoneRule.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { PropertyRule } from '../PropertyRule';\n\n/**\n * Validation rule that checks if a string matches a phone number pattern.\n * @template T The type being validated.\n */\nexport class PhoneRule<T> extends PropertyRule<T, string> {\n private static readonly phoneRegex = /^[\\d\\s()+-]+$/;\n\n /**\n * Initializes a new instance of the {@link PhoneRule} class.\n * @param propertyAccessor Function to access the property value from the instance.\n */\n constructor(propertyAccessor: (instance: T) => string) {\n super(propertyAccessor, \"'{PropertyName}' is not a valid phone number.\");\n }\n\n /** @inheritdoc */\n protected isValid(value: string): boolean {\n if (value === null || value === undefined || value === '') {\n return true; // Use NotNull/NotEmpty for null checks\n }\n return PhoneRule.phoneRegex.test(value);\n }\n}\n"],"names":[],"mappings":";;AASM,MAAO,SAAa,SAAQ,YAAuB,CAAA;AAC7C,IAAA,OAAgB,UAAU,GAAG,eAAe;AAMpD,IAAA,WAAA,CAAY,gBAAyC,EAAA;AACjD,QAAA,KAAK,CAAC,gBAAgB,EAAE,+CAA+C,CAAC;IAC5E;AAGU,IAAA,OAAO,CAAC,KAAa,EAAA;AAC3B,QAAA,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,EAAE;AACvD,YAAA,OAAO,IAAI;QACf;QACA,OAAO,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC;IAC3C;;;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PropertyRule } from '../PropertyRule';
|
|
2
|
+
export declare class UrlRule<T> extends PropertyRule<T, string> {
|
|
3
|
+
private static readonly urlRegex;
|
|
4
|
+
constructor(propertyAccessor: (instance: T) => string);
|
|
5
|
+
protected isValid(value: string): boolean;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=UrlRule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UrlRule.d.ts","sourceRoot":"","sources":["../../../../validation/rules/UrlRule.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAM/C,qBAAa,OAAO,CAAC,CAAC,CAAE,SAAQ,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC;IACnD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAqB;gBAMzC,gBAAgB,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,MAAM;IAKrD,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAM5C"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PropertyRule } from '../PropertyRule.js';
|
|
2
|
+
|
|
3
|
+
class UrlRule extends PropertyRule {
|
|
4
|
+
static urlRegex = /^https?:\/\/.+/i;
|
|
5
|
+
constructor(propertyAccessor) {
|
|
6
|
+
super(propertyAccessor, "'{PropertyName}' is not a valid URL.");
|
|
7
|
+
}
|
|
8
|
+
isValid(value) {
|
|
9
|
+
if (value === null || value === undefined || value === '') {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
return UrlRule.urlRegex.test(value);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { UrlRule };
|
|
17
|
+
//# sourceMappingURL=UrlRule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UrlRule.js","sources":["../../../../validation/rules/UrlRule.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { PropertyRule } from '../PropertyRule';\n\n/**\n * Validation rule that checks if a string is a valid URL.\n * @template T The type being validated.\n */\nexport class UrlRule<T> extends PropertyRule<T, string> {\n private static readonly urlRegex = /^https?:\\/\\/.+/i;\n\n /**\n * Initializes a new instance of the {@link UrlRule} class.\n * @param propertyAccessor Function to access the property value from the instance.\n */\n constructor(propertyAccessor: (instance: T) => string) {\n super(propertyAccessor, \"'{PropertyName}' is not a valid URL.\");\n }\n\n /** @inheritdoc */\n protected isValid(value: string): boolean {\n if (value === null || value === undefined || value === '') {\n return true; // Use NotNull/NotEmpty for null checks\n }\n return UrlRule.urlRegex.test(value);\n }\n}\n"],"names":[],"mappings":";;AASM,MAAO,OAAW,SAAQ,YAAuB,CAAA;AAC3C,IAAA,OAAgB,QAAQ,GAAG,iBAAiB;AAMpD,IAAA,WAAA,CAAY,gBAAyC,EAAA;AACjD,QAAA,KAAK,CAAC,gBAAgB,EAAE,sCAAsC,CAAC;IACnE;AAGU,IAAA,OAAO,CAAC,KAAa,EAAA;AAC3B,QAAA,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,EAAE;AACvD,YAAA,OAAO,IAAI;QACf;QACA,OAAO,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;IACvC;;;;;"}
|
package/package.json
CHANGED
|
@@ -177,7 +177,9 @@ export abstract class ObservableQueryFor<TDataType, TParameters = object> implem
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
private validateArguments(args?: TParameters): boolean {
|
|
180
|
-
|
|
180
|
+
const parameterValues = ParametersHelper.collectParameterValues(this);
|
|
181
|
+
const combinedArgs = { ...(args as object || {}), ...parameterValues };
|
|
182
|
+
return ValidateRequestArguments(this.constructor.name, this.requiredRequestParameters, combinedArgs as object);
|
|
181
183
|
}
|
|
182
184
|
|
|
183
185
|
private buildRoute(args?: TParameters): string {
|
|
@@ -5,6 +5,8 @@ import { RuleBuilder } from './RuleBuilder';
|
|
|
5
5
|
import { NotEmptyRule, NotNullRule } from './rules/NotEmptyRule';
|
|
6
6
|
import { MinLengthRule, MaxLengthRule, LengthRule } from './rules/LengthRules';
|
|
7
7
|
import { EmailRule } from './rules/EmailRule';
|
|
8
|
+
import { PhoneRule } from './rules/PhoneRule';
|
|
9
|
+
import { UrlRule } from './rules/UrlRule';
|
|
8
10
|
import { RegexRule } from './rules/RegexRule';
|
|
9
11
|
import { GreaterThanRule, GreaterThanOrEqualRule, LessThanRule, LessThanOrEqualRule } from './rules/ComparisonRules';
|
|
10
12
|
|
|
@@ -84,6 +86,28 @@ export function emailAddress<T>(this: RuleBuilder<T, string>): RuleBuilder<T, st
|
|
|
84
86
|
return this.addRule(new EmailRule<T>(propertyAccessor));
|
|
85
87
|
}
|
|
86
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Add a rule that the string property must be a valid phone number.
|
|
91
|
+
* @template T The type being validated.
|
|
92
|
+
* @param this The rule builder instance.
|
|
93
|
+
* @returns The rule builder for chaining.
|
|
94
|
+
*/
|
|
95
|
+
export function phone<T>(this: RuleBuilder<T, string>): RuleBuilder<T, string> {
|
|
96
|
+
const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;
|
|
97
|
+
return this.addRule(new PhoneRule<T>(propertyAccessor));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Add a rule that the string property must be a valid URL.
|
|
102
|
+
* @template T The type being validated.
|
|
103
|
+
* @param this The rule builder instance.
|
|
104
|
+
* @returns The rule builder for chaining.
|
|
105
|
+
*/
|
|
106
|
+
export function url<T>(this: RuleBuilder<T, string>): RuleBuilder<T, string> {
|
|
107
|
+
const propertyAccessor = (this as unknown as { _propertyAccessor: (instance: T) => string })._propertyAccessor;
|
|
108
|
+
return this.addRule(new UrlRule<T>(propertyAccessor));
|
|
109
|
+
}
|
|
110
|
+
|
|
87
111
|
/**
|
|
88
112
|
* Add a rule that the string property must match the specified regular expression.
|
|
89
113
|
* @template T The type being validated.
|
|
@@ -152,6 +176,8 @@ RuleBuilder.prototype.notNull = notNull;
|
|
|
152
176
|
(RuleBuilder.prototype as unknown as { maxLength: typeof maxLength }).maxLength = maxLength;
|
|
153
177
|
(RuleBuilder.prototype as unknown as { length: typeof length }).length = length;
|
|
154
178
|
(RuleBuilder.prototype as unknown as { emailAddress: typeof emailAddress }).emailAddress = emailAddress;
|
|
179
|
+
(RuleBuilder.prototype as unknown as { phone: typeof phone }).phone = phone;
|
|
180
|
+
(RuleBuilder.prototype as unknown as { url: typeof url }).url = url;
|
|
155
181
|
(RuleBuilder.prototype as unknown as { matches: typeof matches }).matches = matches;
|
|
156
182
|
(RuleBuilder.prototype as unknown as { greaterThan: typeof greaterThan }).greaterThan = greaterThan;
|
|
157
183
|
(RuleBuilder.prototype as unknown as { greaterThanOrEqual: typeof greaterThanOrEqual }).greaterThanOrEqual = greaterThanOrEqual;
|
|
@@ -167,6 +193,8 @@ declare module './RuleBuilder' {
|
|
|
167
193
|
maxLength(length: number): RuleBuilder<T, TProperty>;
|
|
168
194
|
length(min: number, max: number): RuleBuilder<T, TProperty>;
|
|
169
195
|
emailAddress(): RuleBuilder<T, TProperty>;
|
|
196
|
+
phone(): RuleBuilder<T, TProperty>;
|
|
197
|
+
url(): RuleBuilder<T, TProperty>;
|
|
170
198
|
matches(pattern: RegExp, errorMessage?: string): RuleBuilder<T, TProperty>;
|
|
171
199
|
greaterThan(threshold: number): RuleBuilder<T, TProperty>;
|
|
172
200
|
greaterThanOrEqual(threshold: number): RuleBuilder<T, TProperty>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { PropertyRule } from '../PropertyRule';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Validation rule that checks if a string matches a phone number pattern.
|
|
8
|
+
* @template T The type being validated.
|
|
9
|
+
*/
|
|
10
|
+
export class PhoneRule<T> extends PropertyRule<T, string> {
|
|
11
|
+
private static readonly phoneRegex = /^[\d\s()+-]+$/;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Initializes a new instance of the {@link PhoneRule} class.
|
|
15
|
+
* @param propertyAccessor Function to access the property value from the instance.
|
|
16
|
+
*/
|
|
17
|
+
constructor(propertyAccessor: (instance: T) => string) {
|
|
18
|
+
super(propertyAccessor, "'{PropertyName}' is not a valid phone number.");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** @inheritdoc */
|
|
22
|
+
protected isValid(value: string): boolean {
|
|
23
|
+
if (value === null || value === undefined || value === '') {
|
|
24
|
+
return true; // Use NotNull/NotEmpty for null checks
|
|
25
|
+
}
|
|
26
|
+
return PhoneRule.phoneRegex.test(value);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { PropertyRule } from '../PropertyRule';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Validation rule that checks if a string is a valid URL.
|
|
8
|
+
* @template T The type being validated.
|
|
9
|
+
*/
|
|
10
|
+
export class UrlRule<T> extends PropertyRule<T, string> {
|
|
11
|
+
private static readonly urlRegex = /^https?:\/\/.+/i;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Initializes a new instance of the {@link UrlRule} class.
|
|
15
|
+
* @param propertyAccessor Function to access the property value from the instance.
|
|
16
|
+
*/
|
|
17
|
+
constructor(propertyAccessor: (instance: T) => string) {
|
|
18
|
+
super(propertyAccessor, "'{PropertyName}' is not a valid URL.");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** @inheritdoc */
|
|
22
|
+
protected isValid(value: string): boolean {
|
|
23
|
+
if (value === null || value === undefined || value === '') {
|
|
24
|
+
return true; // Use NotNull/NotEmpty for null checks
|
|
25
|
+
}
|
|
26
|
+
return UrlRule.urlRegex.test(value);
|
|
27
|
+
}
|
|
28
|
+
}
|