@thisisagile/easy 15.12.12 → 15.13.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/dist/types/Uri.d.ts +1 -1
- package/dist/types/Uri.js.map +1 -1
- package/dist/types/Uri.mjs.map +1 -1
- package/dist/validation/Contraints.d.ts +1 -0
- package/dist/validation/Contraints.js +3 -0
- package/dist/validation/Contraints.js.map +1 -1
- package/dist/validation/Contraints.mjs +2 -0
- package/dist/validation/Contraints.mjs.map +1 -1
- package/package.json +2 -2
- package/src/types/Uri.ts +3 -3
- package/src/validation/Contraints.ts +3 -0
package/dist/types/Uri.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ export declare class EasyUri<Props = UriExpandProps> implements Uri {
|
|
|
48
48
|
static readonly skip: Segment;
|
|
49
49
|
static readonly take: Segment;
|
|
50
50
|
readonly host: Segment;
|
|
51
|
-
|
|
51
|
+
protected resource: Segment;
|
|
52
52
|
protected state: any;
|
|
53
53
|
constructor(segments?: Segment[]);
|
|
54
54
|
get path(): string;
|
package/dist/types/Uri.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/Uri.ts"],"sourcesContent":["import { isBoolean, isDefined, isNotEmpty, isTrue } from './Is';\nimport { asString, Text } from './Text';\nimport { toName } from './Constructor';\nimport { ctx } from './Context';\nimport { List, toList } from './List';\nimport { entries, meta } from
|
|
1
|
+
{"version":3,"sources":["../../src/types/Uri.ts"],"sourcesContent":["import { isBoolean, isDefined, isNotEmpty, isTrue } from './Is';\nimport { asString, Text } from './Text';\nimport { toName } from './Constructor';\nimport { ctx } from './Context';\nimport { List, toList } from './List';\nimport { entries, meta } from './Meta';\nimport { tryTo } from './Try';\nimport { Optional } from './Types';\nimport { OneOrMore, toArray } from './Array';\n\nexport type Segment = Text & { key?: string; segment?: string; query?: (value: unknown) => string };\n\nexport const toSegment = (\n key?: Text,\n {\n segment,\n query,\n }: {\n segment?: string;\n query?: (value: unknown) => string;\n } = {}\n): Segment => ({\n key: key as string,\n segment,\n query,\n toString: () => asString(key),\n});\n\nexport const uri = {\n host: (key?: string): Segment => toSegment(key, { segment: key ?? ctx.env.host ?? '$host' }),\n resource: (resource: Uri): Segment => toSegment(toName(resource, 'Uri'), { segment: toName(resource, 'Uri') }),\n segment: (key?: Text): Segment => toSegment(key, { segment: key as string }),\n path: (key: Text): Segment => toSegment(key, { segment: `:${key}` }),\n query: (key: Text): Segment => toSegment(key, { query: (value: unknown): string => (isDefined(value) ? `${key}=${value}` : '') }),\n boolean: (key: Text): Segment => toSegment(key, { query: (value: unknown): string => (isTrue(value) ? `${key}` : '') }),\n};\n\ntype Prop = { segment: Segment; value: any };\n\nconst toRoute = (...segments: Segment[]): string =>\n toList(segments)\n .mapDefined(s => s.segment)\n .join('/');\n\nexport type Uri = {\n id: (id?: unknown) => Uri;\n ids: (ids: OneOrMore<unknown>) => Uri;\n query: (q?: unknown) => Uri;\n sort: (q?: any) => Uri;\n skip: (n?: number) => Uri;\n take: (n?: number) => Uri;\n path: string;\n route: (resource: string) => string;\n isInternal: boolean;\n toString: () => string;\n};\n\nexport type UriExpandProps = { q: string; s: string };\n\nexport class EasyUri<Props = UriExpandProps> implements Uri {\n static readonly id = uri.path('id');\n static readonly ids = uri.query('ids');\n static readonly query = uri.query('q');\n static readonly sort = uri.query('s');\n static readonly skip = uri.query('skip');\n static readonly take = uri.query('take');\n\n readonly host = uri.host();\n protected resource = uri.resource(this);\n\n protected state: any = {};\n\n constructor(readonly segments: Segment[] = []) {}\n\n get path(): string {\n return toRoute(uri.segment(''), this.resource, ...this.segments);\n }\n\n get complete(): string {\n return toRoute(this.host, this.resource, ...this.segments);\n }\n\n get isInternal(): boolean {\n return toRoute(this.host) === (ctx.env.host ?? '$host');\n }\n\n protected get props(): List<Prop> {\n return meta(this.state).values<Prop>();\n }\n\n route = (resource: Optional<string> = this.resource.key): string => toRoute(uri.segment(''), uri.segment(resource?.toLowerCase()), ...this.segments);\n\n set = (segment: Segment, value?: unknown): this => {\n tryTo(value)\n .is.defined()\n .accept(value => (this.state[segment.key ?? ''] = { segment, value }));\n return this;\n };\n\n toString(): string {\n return tryTo(() => this.props)\n .map(ps => ps.filter(p => p.segment?.segment))\n .map(ps => ps.reduce((r: string, p: Prop) => r.replace(asString(p.segment.segment), asString(p.value)), this.complete))\n .map(route => ({\n route,\n query: this.props.mapDefined(p => (p.segment?.query ? p.segment?.query(p.value) : undefined))?.join('&'),\n }))\n .map(({ route, query }) => (isNotEmpty(query) ? `${route}?${query}` : route)).value;\n }\n\n id = (id?: unknown): this => this.set(EasyUri.id, id);\n ids = (ids: OneOrMore<unknown>): this => this.set(EasyUri.ids, toArray(ids).join(','));\n query = (q?: unknown): this => this.set(EasyUri.query, q);\n sort = (s?: any): this => this.set(EasyUri.sort, asString(s));\n\n skip = (index?: number): this => this.set(EasyUri.skip, index);\n take = (items?: number): this => this.set(EasyUri.take, items);\n\n expand(props: Partial<Props>): this {\n return entries(props)\n .filter(([_, v]) => isNotEmpty(v))\n .reduce((u, [k, v]) => (isBoolean(v) ? u.set(uri.boolean(k), v) : u.set(uri.query(k), toArray(v).join(','))), this);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAyD;AACzD,kBAA+B;AAC/B,yBAAuB;AACvB,qBAAoB;AACpB,kBAA6B;AAC7B,kBAA8B;AAC9B,iBAAsB;AAEtB,mBAAmC;AAI5B,MAAM,YAAY,CACvB,KACA;AAAA,EACE;AAAA,EACA;AACF,IAGI,CAAC,OACQ;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU,UAAM,sBAAS,GAAG;AAC9B;AAEO,MAAM,MAAM;AAAA,EACjB,MAAM,CAAC,QAA0B,UAAU,KAAK,EAAE,SAAS,OAAO,mBAAI,IAAI,QAAQ,QAAQ,CAAC;AAAA,EAC3F,UAAU,CAAC,aAA2B,cAA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AK,IAAI,QAAQ,OAAO,CAAC;AAAA,EACxD,OAAO,CAAC,MAAkB,KAAK,IAAI,QAAQ,UAAM,sBAAS,CAAC,CAAC;AAAA,EAE5D,OAAO,CAAC,UAAyB,KAAK,IAAI,QAAQ,MAAM,KAAK;AAAA,EAC7D,OAAO,CAAC,UAAyB,KAAK,IAAI,QAAQ,MAAM,KAAK;AAAA,EAE7D,OAAO,OAA6B;AAClC,eAAO,qBAAQ,KAAK,EACjB,OAAO,CAAC,CAAC,GAAG,CAAC,UAAM,sBAAW,CAAC,CAAC,EAChC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,UAAO,qBAAU,CAAC,IAAI,EAAE,IAAI,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,IAAI,MAAM,CAAC,OAAG,sBAAQ,CAAC,EAAE,KAAK,GAAG,CAAC,GAAI,IAAI;AAAA,EACtH;AACF;","names":["value"]}
|
package/dist/types/Uri.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/Uri.ts"],"sourcesContent":["import { isBoolean, isDefined, isNotEmpty, isTrue } from './Is';\nimport { asString, Text } from './Text';\nimport { toName } from './Constructor';\nimport { ctx } from './Context';\nimport { List, toList } from './List';\nimport { entries, meta } from
|
|
1
|
+
{"version":3,"sources":["../../src/types/Uri.ts"],"sourcesContent":["import { isBoolean, isDefined, isNotEmpty, isTrue } from './Is';\nimport { asString, Text } from './Text';\nimport { toName } from './Constructor';\nimport { ctx } from './Context';\nimport { List, toList } from './List';\nimport { entries, meta } from './Meta';\nimport { tryTo } from './Try';\nimport { Optional } from './Types';\nimport { OneOrMore, toArray } from './Array';\n\nexport type Segment = Text & { key?: string; segment?: string; query?: (value: unknown) => string };\n\nexport const toSegment = (\n key?: Text,\n {\n segment,\n query,\n }: {\n segment?: string;\n query?: (value: unknown) => string;\n } = {}\n): Segment => ({\n key: key as string,\n segment,\n query,\n toString: () => asString(key),\n});\n\nexport const uri = {\n host: (key?: string): Segment => toSegment(key, { segment: key ?? ctx.env.host ?? '$host' }),\n resource: (resource: Uri): Segment => toSegment(toName(resource, 'Uri'), { segment: toName(resource, 'Uri') }),\n segment: (key?: Text): Segment => toSegment(key, { segment: key as string }),\n path: (key: Text): Segment => toSegment(key, { segment: `:${key}` }),\n query: (key: Text): Segment => toSegment(key, { query: (value: unknown): string => (isDefined(value) ? `${key}=${value}` : '') }),\n boolean: (key: Text): Segment => toSegment(key, { query: (value: unknown): string => (isTrue(value) ? `${key}` : '') }),\n};\n\ntype Prop = { segment: Segment; value: any };\n\nconst toRoute = (...segments: Segment[]): string =>\n toList(segments)\n .mapDefined(s => s.segment)\n .join('/');\n\nexport type Uri = {\n id: (id?: unknown) => Uri;\n ids: (ids: OneOrMore<unknown>) => Uri;\n query: (q?: unknown) => Uri;\n sort: (q?: any) => Uri;\n skip: (n?: number) => Uri;\n take: (n?: number) => Uri;\n path: string;\n route: (resource: string) => string;\n isInternal: boolean;\n toString: () => string;\n};\n\nexport type UriExpandProps = { q: string; s: string };\n\nexport class EasyUri<Props = UriExpandProps> implements Uri {\n static readonly id = uri.path('id');\n static readonly ids = uri.query('ids');\n static readonly query = uri.query('q');\n static readonly sort = uri.query('s');\n static readonly skip = uri.query('skip');\n static readonly take = uri.query('take');\n\n readonly host = uri.host();\n protected resource = uri.resource(this);\n\n protected state: any = {};\n\n constructor(readonly segments: Segment[] = []) {}\n\n get path(): string {\n return toRoute(uri.segment(''), this.resource, ...this.segments);\n }\n\n get complete(): string {\n return toRoute(this.host, this.resource, ...this.segments);\n }\n\n get isInternal(): boolean {\n return toRoute(this.host) === (ctx.env.host ?? '$host');\n }\n\n protected get props(): List<Prop> {\n return meta(this.state).values<Prop>();\n }\n\n route = (resource: Optional<string> = this.resource.key): string => toRoute(uri.segment(''), uri.segment(resource?.toLowerCase()), ...this.segments);\n\n set = (segment: Segment, value?: unknown): this => {\n tryTo(value)\n .is.defined()\n .accept(value => (this.state[segment.key ?? ''] = { segment, value }));\n return this;\n };\n\n toString(): string {\n return tryTo(() => this.props)\n .map(ps => ps.filter(p => p.segment?.segment))\n .map(ps => ps.reduce((r: string, p: Prop) => r.replace(asString(p.segment.segment), asString(p.value)), this.complete))\n .map(route => ({\n route,\n query: this.props.mapDefined(p => (p.segment?.query ? p.segment?.query(p.value) : undefined))?.join('&'),\n }))\n .map(({ route, query }) => (isNotEmpty(query) ? `${route}?${query}` : route)).value;\n }\n\n id = (id?: unknown): this => this.set(EasyUri.id, id);\n ids = (ids: OneOrMore<unknown>): this => this.set(EasyUri.ids, toArray(ids).join(','));\n query = (q?: unknown): this => this.set(EasyUri.query, q);\n sort = (s?: any): this => this.set(EasyUri.sort, asString(s));\n\n skip = (index?: number): this => this.set(EasyUri.skip, index);\n take = (items?: number): this => this.set(EasyUri.take, items);\n\n expand(props: Partial<Props>): this {\n return entries(props)\n .filter(([_, v]) => isNotEmpty(v))\n .reduce((u, [k, v]) => (isBoolean(v) ? u.set(uri.boolean(k), v) : u.set(uri.query(k), toArray(v).join(','))), this);\n }\n}\n"],"mappings":";AAAA,SAAS,WAAW,WAAW,YAAY,cAAc;AACzD,SAAS,gBAAsB;AAC/B,SAAS,cAAc;AACvB,SAAS,WAAW;AACpB,SAAe,cAAc;AAC7B,SAAS,SAAS,YAAY;AAC9B,SAAS,aAAa;AAEtB,SAAoB,eAAe;AAI5B,MAAM,YAAY,CACvB,KACA;AAAA,EACE;AAAA,EACA;AACF,IAGI,CAAC,OACQ;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU,MAAM,SAAS,GAAG;AAC9B;AAEO,MAAM,MAAM;AAAA,EACjB,MAAM,CAAC,QAA0B,UAAU,KAAK,EAAE,SAAS,OAAO,IAAI,IAAI,QAAQ,QAAQ,CAAC;AAAA,EAC3F,UAAU,CAAC,aAA2B,UAAU,OAAO,UAAU,KAAK,GAAG,EAAE,SAAS,OAAO,UAAU,KAAK,EAAE,CAAC;AAAA,EAC7G,SAAS,C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AA,EAE5D,OAAO,CAAC,UAAyB,KAAK,IAAI,QAAQ,MAAM,KAAK;AAAA,EAC7D,OAAO,CAAC,UAAyB,KAAK,IAAI,QAAQ,MAAM,KAAK;AAAA,EAE7D,OAAO,OAA6B;AAClC,WAAO,QAAQ,KAAK,EACjB,OAAO,CAAC,CAAC,GAAG,CAAC,MAAM,WAAW,CAAC,CAAC,EAChC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAO,UAAU,CAAC,IAAI,EAAE,IAAI,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,IAAI,MAAM,CAAC,GAAG,QAAQ,CAAC,EAAE,KAAK,GAAG,CAAC,GAAI,IAAI;AAAA,EACtH;AACF;","names":["value"]}
|
|
@@ -8,6 +8,7 @@ export declare const valid: () => PropertyDecorator;
|
|
|
8
8
|
export declare const optional: () => PropertyDecorator;
|
|
9
9
|
export declare const includes: (sub: string, message?: string) => PropertyDecorator;
|
|
10
10
|
export declare const inList: (values: unknown[], message?: Text) => PropertyDecorator;
|
|
11
|
+
export declare const inOptionalList: (values: unknown[], message?: Text) => PropertyDecorator;
|
|
11
12
|
export declare const gt: (limit: number, message?: Text) => PropertyDecorator;
|
|
12
13
|
export declare const gte: (limit: number, message?: Text) => PropertyDecorator;
|
|
13
14
|
export declare const lt: (limit: number, message?: Text) => PropertyDecorator;
|
|
@@ -24,6 +24,7 @@ __export(Contraints_exports, {
|
|
|
24
24
|
gt: () => gt,
|
|
25
25
|
gte: () => gte,
|
|
26
26
|
inList: () => inList,
|
|
27
|
+
inOptionalList: () => inOptionalList,
|
|
27
28
|
includes: () => includes,
|
|
28
29
|
lt: () => lt,
|
|
29
30
|
lte: () => lte,
|
|
@@ -50,6 +51,7 @@ const valid = () => constraint((v) => (0, import_Validate.validate)(v), "");
|
|
|
50
51
|
const optional = () => constraint((v) => !(0, import_types.isDefined)(v) || (0, import_Validate.validate)(v), "");
|
|
51
52
|
const includes = (sub, message) => constraint((s) => (0, import_types.isDefined)(s) && (0, import_types.isString)(s) && s.includes(sub), message ?? `Value {actual} must include '${sub}'.`);
|
|
52
53
|
const inList = (values, message) => constraint((v) => (0, import_types.isDefined)(v) && (0, import_types.isIn)(v, values), message ?? "Value {actual} must appear in list.");
|
|
54
|
+
const inOptionalList = (values, message) => constraint((v) => !(0, import_types.isDefined)(v) || (0, import_types.isIn)(v, values), message ?? "Value {actual} must appear in list.");
|
|
53
55
|
const gt = (limit, message) => constraint((v) => v > limit, message ?? `Value {actual} must be larger than '${limit}'.`);
|
|
54
56
|
const gte = (limit, message) => constraint((v) => v >= limit, message ?? `Value {actual} must be larger than or equal to ${limit}.`);
|
|
55
57
|
const lt = (limit, message) => constraint((v) => v < limit, message ?? `Value {actual} must be smaller than ${limit}.`);
|
|
@@ -73,6 +75,7 @@ const rule = (message) => constraint((v) => (0, import_types.isFunction)(v) ? v(
|
|
|
73
75
|
gt,
|
|
74
76
|
gte,
|
|
75
77
|
inList,
|
|
78
|
+
inOptionalList,
|
|
76
79
|
includes,
|
|
77
80
|
lt,
|
|
78
81
|
lte,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/validation/Contraints.ts"],"sourcesContent":["import { Func, inFuture, inPast, isBoolean, isDefined, isFunction, isIn, isNotEmpty, isString, List, meta, Results, text, Text, toList, tryTo } from '../types';\nimport { validate, Validator } from './Validate';\n\nexport type Constraint = Func<boolean | Results, any>;\n\nexport const constraint =\n <T>(c: Constraint, message: Text): PropertyDecorator =>\n (subject: unknown, property: string | symbol): void => {\n const cs = meta(subject).property(property).get<List<Validator>>('constraint') ?? toList<Validator>();\n meta(subject)\n .property(property)\n .set('constraint', cs.add({ property, constraint: c, text: message }));\n };\n\nexport const defined = (message?: Text): PropertyDecorator => constraint(v => isDefined(v), message ?? 'Property {property} must be defined.');\n\nexport const required = (message?: Text): PropertyDecorator =>\n constraint(v => isNotEmpty(v), message ?? 'Property {property} is required, and may not be empty.');\n\nexport const notEmpty = (message?: Text): PropertyDecorator => constraint(v => isNotEmpty(v), message ?? 'Property {property} may not be empty.');\n\nexport const valid = (): PropertyDecorator => constraint(v => validate(v), '');\n\nexport const optional = (): PropertyDecorator => constraint(v => !isDefined(v) || validate(v), '');\n\nexport const includes = (sub: string, message?: string): PropertyDecorator =>\n constraint(s => isDefined(s) && isString(s) && s.includes(sub), message ?? `Value {actual} must include '${sub}'.`);\n\nexport const inList = (values: unknown[], message?: Text): PropertyDecorator =>\n constraint(v => isDefined(v) && isIn(v, values), message ?? 'Value {actual} must appear in list.');\n\nexport const gt = (limit: number, message?: Text): PropertyDecorator => constraint(v => v > limit, message ?? `Value {actual} must be larger than '${limit}'.`);\n\nexport const gte = (limit: number, message?: Text): PropertyDecorator =>\n constraint(v => v >= limit, message ?? `Value {actual} must be larger than or equal to ${limit}.`);\n\nexport const lt = (limit: number, message?: Text): PropertyDecorator => constraint(v => v < limit, message ?? `Value {actual} must be smaller than ${limit}.`);\n\nexport const lte = (limit: number, message?: Text): PropertyDecorator =>\n constraint(v => v <= limit, message ?? `Value {actual} must be smaller than or equal to ${limit}.`);\n\nexport const past = (message?: Text): PropertyDecorator => constraint(v => inPast(v), message ?? 'Value {actual} must lay in the past.');\n\nexport const future = (message?: Text): PropertyDecorator => constraint(v => inFuture(v), message ?? 'Value {actual} must lay in the future.');\n\nexport const minLength = (length: number, message?: Text): PropertyDecorator =>\n constraint(\n v =>\n tryTo(() => v)\n .is.defined()\n .map(v => text(v).toString().length >= length)\n .orElse(true) as boolean,\n message ?? `Value {actual} must be at least '${length}' characters long.`\n );\n\nexport const maxLength = (length: number, message?: Text): PropertyDecorator =>\n constraint(\n v =>\n tryTo(() => v)\n .is.defined()\n .map(v => text(v).toString().length <= length)\n .orElse(true) as boolean,\n message ?? `Value {actual} cannot be longer than '${length}' characters.`\n );\n\nexport const rule = (message?: Text): PropertyDecorator =>\n constraint(v => (isFunction(v) ? (v() as boolean | Results) : isBoolean(v) ? v : false), message ?? `Value {actual} must be true`);\n"],"m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WAAW,kDAAkD,KAAK,GAAG;AAE5F,MAAM,KAAK,CAAC,OAAe,YAAsC,WAAW,OAAK,IAAI,OAAO,WAAW,uCAAuC,KAAK,GAAG;AAEtJ,MAAM,MAAM,CAAC,OAAe,YACjC,WAAW,OAAK,KAAK,OAAO,WAAW,mDAAmD,KAAK,GAAG;AAE7F,MAAM,OAAO,CAAC,YAAsC,WAAW,WAAK,qBAAO,CAAC,GAAG,WAAW,sCAAsC;AAEhI,MAAM,SAAS,CAAC,YAAsC,WAAW,WAAK,uBAAS,CAAC,GAAG,WAAW,wCAAwC;AAEtI,MAAM,YAAY,CAAC,QAAgB,YACxC;AAAA,EACE,WACE,oBAAM,MAAM,CAAC,EACV,GAAG,QAAQ,EACX,IAAI,CAAAA,WAAK,mBAAKA,EAAC,EAAE,SAAS,EAAE,UAAU,MAAM,EAC5C,OAAO,IAAI;AAAA,EAChB,WAAW,oCAAoC,MAAM;AACvD;AAEK,MAAM,YAAY,CAAC,QAAgB,YACxC;AAAA,EACE,WACE,oBAAM,MAAM,CAAC,EACV,GAAG,QAAQ,EACX,IAAI,CAAAA,WAAK,mBAAKA,EAAC,EAAE,SAAS,EAAE,UAAU,MAAM,EAC5C,OAAO,IAAI;AAAA,EAChB,WAAW,yCAAyC,MAAM;AAC5D;AAEK,MAAM,OAAO,CAAC,YACnB,WAAW,WAAM,yBAAW,CAAC,IAAK,EAAE,QAA0B,wBAAU,CAAC,IAAI,IAAI,OAAQ,WAAW,6BAA6B;","names":["v"]}
|
|
1
|
+
{"version":3,"sources":["../../src/validation/Contraints.ts"],"sourcesContent":["import { Func, inFuture, inPast, isBoolean, isDefined, isFunction, isIn, isNotEmpty, isString, List, meta, Results, text, Text, toList, tryTo } from '../types';\nimport { validate, Validator } from './Validate';\n\nexport type Constraint = Func<boolean | Results, any>;\n\nexport const constraint =\n <T>(c: Constraint, message: Text): PropertyDecorator =>\n (subject: unknown, property: string | symbol): void => {\n const cs = meta(subject).property(property).get<List<Validator>>('constraint') ?? toList<Validator>();\n meta(subject)\n .property(property)\n .set('constraint', cs.add({ property, constraint: c, text: message }));\n };\n\nexport const defined = (message?: Text): PropertyDecorator => constraint(v => isDefined(v), message ?? 'Property {property} must be defined.');\n\nexport const required = (message?: Text): PropertyDecorator =>\n constraint(v => isNotEmpty(v), message ?? 'Property {property} is required, and may not be empty.');\n\nexport const notEmpty = (message?: Text): PropertyDecorator => constraint(v => isNotEmpty(v), message ?? 'Property {property} may not be empty.');\n\nexport const valid = (): PropertyDecorator => constraint(v => validate(v), '');\n\nexport const optional = (): PropertyDecorator => constraint(v => !isDefined(v) || validate(v), '');\n\nexport const includes = (sub: string, message?: string): PropertyDecorator =>\n constraint(s => isDefined(s) && isString(s) && s.includes(sub), message ?? `Value {actual} must include '${sub}'.`);\n\nexport const inList = (values: unknown[], message?: Text): PropertyDecorator =>\n constraint(v => isDefined(v) && isIn(v, values), message ?? 'Value {actual} must appear in list.');\n\nexport const inOptionalList = (values: unknown[], message?: Text): PropertyDecorator =>\n constraint(v => !isDefined(v) || isIn(v, values), message ?? 'Value {actual} must appear in list.');\n\nexport const gt = (limit: number, message?: Text): PropertyDecorator => constraint(v => v > limit, message ?? `Value {actual} must be larger than '${limit}'.`);\n\nexport const gte = (limit: number, message?: Text): PropertyDecorator =>\n constraint(v => v >= limit, message ?? `Value {actual} must be larger than or equal to ${limit}.`);\n\nexport const lt = (limit: number, message?: Text): PropertyDecorator => constraint(v => v < limit, message ?? `Value {actual} must be smaller than ${limit}.`);\n\nexport const lte = (limit: number, message?: Text): PropertyDecorator =>\n constraint(v => v <= limit, message ?? `Value {actual} must be smaller than or equal to ${limit}.`);\n\nexport const past = (message?: Text): PropertyDecorator => constraint(v => inPast(v), message ?? 'Value {actual} must lay in the past.');\n\nexport const future = (message?: Text): PropertyDecorator => constraint(v => inFuture(v), message ?? 'Value {actual} must lay in the future.');\n\nexport const minLength = (length: number, message?: Text): PropertyDecorator =>\n constraint(\n v =>\n tryTo(() => v)\n .is.defined()\n .map(v => text(v).toString().length >= length)\n .orElse(true) as boolean,\n message ?? `Value {actual} must be at least '${length}' characters long.`\n );\n\nexport const maxLength = (length: number, message?: Text): PropertyDecorator =>\n constraint(\n v =>\n tryTo(() => v)\n .is.defined()\n .map(v => text(v).toString().length <= length)\n .orElse(true) as boolean,\n message ?? `Value {actual} cannot be longer than '${length}' characters.`\n );\n\nexport const rule = (message?: Text): PropertyDecorator =>\n constraint(v => (isFunction(v) ? (v() as boolean | Results) : isBoolean(v) ? v : false), message ?? `Value {actual} must be true`);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqJ;AACrJ,sBAAoC;AAI7B,MAAM,aACX,CAAI,GAAe,YACnB,CAAC,SAAkB,aAAoC;AACrD,QAAM,SAAK,mBAAK,OAAO,EAAE,SAAS,QAAQ,EAAE,IAAqB,YAAY,SAAK,qBAAkB;AACpG,yBAAK,OAAO,EACT,SAAS,QAAQ,EACjB,IAAI,cAAc,GAAG,IAAI,EAAE,UAAU,YAAY,GAAG,MAAM,QAAQ,CAAC,CAAC;AACzE;AAEK,MAAM,UAAU,CAAC,YAAsC,WAAW,WAAK,wBAAU,CAAC,GAAG,WAAW,sCAAsC;AAEtI,MAAM,WAAW,CAAC,YACvB,WAAW,WAAK,yBAAW,CAAC,GAAG,WAAW,wDAAwD;AAE7F,MAAM,WAAW,CAAC,YAAsC,WAAW,WAAK,yBAAW,CAAC,GAAG,WAAW,uCAAuC;AAEzI,MAAM,QAAQ,MAAyB,WAAW,WAAK,0BAAS,CAAC,GAAG,EAAE;AAEtE,MAAM,WAAW,MAAyB,WAAW,OAAK,KAAC,wBAAU,CAAC,SAAK,0BAAS,CAAC,GAAG,EAAE;AAE1F,MAAM,WAAW,CAAC,KAAa,YACpC,WAAW,WAAK,wBAAU,C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W,yCAAyC,MAAM;AAC5D;AAEK,MAAM,OAAO,CAAC,YACnB,WAAW,WAAM,yBAAW,CAAC,IAAK,EAAE,QAA0B,wBAAU,CAAC,IAAI,IAAI,OAAQ,WAAW,6BAA6B;","names":["v"]}
|
|
@@ -12,6 +12,7 @@ const valid = () => constraint((v) => validate(v), "");
|
|
|
12
12
|
const optional = () => constraint((v) => !isDefined(v) || validate(v), "");
|
|
13
13
|
const includes = (sub, message) => constraint((s) => isDefined(s) && isString(s) && s.includes(sub), message ?? `Value {actual} must include '${sub}'.`);
|
|
14
14
|
const inList = (values, message) => constraint((v) => isDefined(v) && isIn(v, values), message ?? "Value {actual} must appear in list.");
|
|
15
|
+
const inOptionalList = (values, message) => constraint((v) => !isDefined(v) || isIn(v, values), message ?? "Value {actual} must appear in list.");
|
|
15
16
|
const gt = (limit, message) => constraint((v) => v > limit, message ?? `Value {actual} must be larger than '${limit}'.`);
|
|
16
17
|
const gte = (limit, message) => constraint((v) => v >= limit, message ?? `Value {actual} must be larger than or equal to ${limit}.`);
|
|
17
18
|
const lt = (limit, message) => constraint((v) => v < limit, message ?? `Value {actual} must be smaller than ${limit}.`);
|
|
@@ -34,6 +35,7 @@ export {
|
|
|
34
35
|
gt,
|
|
35
36
|
gte,
|
|
36
37
|
inList,
|
|
38
|
+
inOptionalList,
|
|
37
39
|
includes,
|
|
38
40
|
lt,
|
|
39
41
|
lte,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/validation/Contraints.ts"],"sourcesContent":["import { Func, inFuture, inPast, isBoolean, isDefined, isFunction, isIn, isNotEmpty, isString, List, meta, Results, text, Text, toList, tryTo } from '../types';\nimport { validate, Validator } from './Validate';\n\nexport type Constraint = Func<boolean | Results, any>;\n\nexport const constraint =\n <T>(c: Constraint, message: Text): PropertyDecorator =>\n (subject: unknown, property: string | symbol): void => {\n const cs = meta(subject).property(property).get<List<Validator>>('constraint') ?? toList<Validator>();\n meta(subject)\n .property(property)\n .set('constraint', cs.add({ property, constraint: c, text: message }));\n };\n\nexport const defined = (message?: Text): PropertyDecorator => constraint(v => isDefined(v), message ?? 'Property {property} must be defined.');\n\nexport const required = (message?: Text): PropertyDecorator =>\n constraint(v => isNotEmpty(v), message ?? 'Property {property} is required, and may not be empty.');\n\nexport const notEmpty = (message?: Text): PropertyDecorator => constraint(v => isNotEmpty(v), message ?? 'Property {property} may not be empty.');\n\nexport const valid = (): PropertyDecorator => constraint(v => validate(v), '');\n\nexport const optional = (): PropertyDecorator => constraint(v => !isDefined(v) || validate(v), '');\n\nexport const includes = (sub: string, message?: string): PropertyDecorator =>\n constraint(s => isDefined(s) && isString(s) && s.includes(sub), message ?? `Value {actual} must include '${sub}'.`);\n\nexport const inList = (values: unknown[], message?: Text): PropertyDecorator =>\n constraint(v => isDefined(v) && isIn(v, values), message ?? 'Value {actual} must appear in list.');\n\nexport const gt = (limit: number, message?: Text): PropertyDecorator => constraint(v => v > limit, message ?? `Value {actual} must be larger than '${limit}'.`);\n\nexport const gte = (limit: number, message?: Text): PropertyDecorator =>\n constraint(v => v >= limit, message ?? `Value {actual} must be larger than or equal to ${limit}.`);\n\nexport const lt = (limit: number, message?: Text): PropertyDecorator => constraint(v => v < limit, message ?? `Value {actual} must be smaller than ${limit}.`);\n\nexport const lte = (limit: number, message?: Text): PropertyDecorator =>\n constraint(v => v <= limit, message ?? `Value {actual} must be smaller than or equal to ${limit}.`);\n\nexport const past = (message?: Text): PropertyDecorator => constraint(v => inPast(v), message ?? 'Value {actual} must lay in the past.');\n\nexport const future = (message?: Text): PropertyDecorator => constraint(v => inFuture(v), message ?? 'Value {actual} must lay in the future.');\n\nexport const minLength = (length: number, message?: Text): PropertyDecorator =>\n constraint(\n v =>\n tryTo(() => v)\n .is.defined()\n .map(v => text(v).toString().length >= length)\n .orElse(true) as boolean,\n message ?? `Value {actual} must be at least '${length}' characters long.`\n );\n\nexport const maxLength = (length: number, message?: Text): PropertyDecorator =>\n constraint(\n v =>\n tryTo(() => v)\n .is.defined()\n .map(v => text(v).toString().length <= length)\n .orElse(true) as boolean,\n message ?? `Value {actual} cannot be longer than '${length}' characters.`\n );\n\nexport const rule = (message?: Text): PropertyDecorator =>\n constraint(v => (isFunction(v) ? (v() as boolean | Results) : isBoolean(v) ? v : false), message ?? `Value {actual} must be true`);\n"],"mappings":";AAAA,SAAe,UAAU,QAAQ,WAAW,WAAW,YAAY,MAAM,YAAY,UAAgB,MAAe,MAAY,QAAQ,aAAa;AACrJ,SAAS,gBAA2B;AAI7B,MAAM,aACX,CAAI,GAAe,YACnB,CAAC,SAAkB,aAAoC;AACrD,QAAM,KAAK,KAAK,OAAO,EAAE,SAAS,QAAQ,EAAE,IAAqB,YAAY,KAAK,OAAkB;AACpG,OAAK,OAAO,EACT,SAAS,QAAQ,EACjB,IAAI,cAAc,GAAG,IAAI,EAAE,UAAU,YAAY,GAAG,MAAM,QAAQ,CAAC,CAAC;AACzE;AAEK,MAAM,UAAU,CAAC,YAAsC,WAAW,OAAK,UAAU,CAAC,GAAG,WAAW,sCAAsC;AAEtI,MAAM,WAAW,CAAC,YACvB,WAAW,OAAK,WAAW,CAAC,GAAG,WAAW,wDAAwD;AAE7F,MAAM,WAAW,CAAC,YAAsC,WAAW,OAAK,WAAW,CAAC,GAAG,WAAW,uCAAuC;AAEzI,MAAM,QAAQ,MAAyB,WAAW,OAAK,SAAS,CAAC,GAAG,EAAE;AAEtE,MAAM,WAAW,MAAyB,WAAW,OAAK,CAAC,UAAU,CAAC,KAAK,SAAS,CAAC,GAAG,EAAE;AAE1F,MAAM,WAAW,CAAC,KAAa,YACpC,WAAW,OAAK,UAAU,CAAC,KAAK,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,GAAG,WAAW,gCAAgC,GAAG,IAAI;AAE7G,MAAM,SAAS,CAAC,QAAmB,YACxC,WAAW,OAAK,UAAU,CAAC,KAAK,KAAK,GAAG,MAAM,GAAG,WAAW,qCAAqC;AAE5F,MAAM,KAAK,CAAC,OAAe,YAAsC,WAAW,OAAK,IAAI,OAAO,WAAW,uCAAuC,KAAK,IAAI;AAEvJ,MAAM,MAAM,CAAC,OAAe,YACjC,WAAW,OAAK,KAAK,OAAO,WAAW,kDAAkD,KAAK,GAAG;AAE5F,MAAM,KAAK,CAAC,OAAe,YAAsC,WAAW,OAAK,IAAI,OAAO,WAAW,uCAAuC,KAAK,GAAG;AAEtJ,MAAM,MAAM,CAAC,OAAe,YACjC,WAAW,OAAK,KAAK,OAAO,WAAW,mDAAmD,KAAK,GAAG;AAE7F,MAAM,OAAO,CAAC,YAAsC,WAAW,OAAK,OAAO,CAAC,GAAG,WAAW,sCAAsC;AAEhI,MAAM,SAAS,CAAC,YAAsC,WAAW,OAAK,SAAS,CAAC,GAAG,WAAW,wCAAwC;AAEtI,MAAM,YAAY,CAAC,QAAgB,YACxC;AAAA,EACE,OACE,MAAM,MAAM,CAAC,EACV,GAAG,QAAQ,EACX,IAAI,CAAAA,OAAK,KAAKA,EAAC,EAAE,SAAS,EAAE,UAAU,MAAM,EAC5C,OAAO,IAAI;AAAA,EAChB,WAAW,oCAAoC,MAAM;AACvD;AAEK,MAAM,YAAY,CAAC,QAAgB,YACxC;AAAA,EACE,OACE,MAAM,MAAM,CAAC,EACV,GAAG,QAAQ,EACX,IAAI,CAAAA,OAAK,KAAKA,EAAC,EAAE,SAAS,EAAE,UAAU,MAAM,EAC5C,OAAO,IAAI;AAAA,EAChB,WAAW,yCAAyC,MAAM;AAC5D;AAEK,MAAM,OAAO,CAAC,YACnB,WAAW,OAAM,WAAW,CAAC,IAAK,EAAE,IAA0B,UAAU,CAAC,IAAI,IAAI,OAAQ,WAAW,6BAA6B;","names":["v"]}
|
|
1
|
+
{"version":3,"sources":["../../src/validation/Contraints.ts"],"sourcesContent":["import { Func, inFuture, inPast, isBoolean, isDefined, isFunction, isIn, isNotEmpty, isString, List, meta, Results, text, Text, toList, tryTo } from '../types';\nimport { validate, Validator } from './Validate';\n\nexport type Constraint = Func<boolean | Results, any>;\n\nexport const constraint =\n <T>(c: Constraint, message: Text): PropertyDecorator =>\n (subject: unknown, property: string | symbol): void => {\n const cs = meta(subject).property(property).get<List<Validator>>('constraint') ?? toList<Validator>();\n meta(subject)\n .property(property)\n .set('constraint', cs.add({ property, constraint: c, text: message }));\n };\n\nexport const defined = (message?: Text): PropertyDecorator => constraint(v => isDefined(v), message ?? 'Property {property} must be defined.');\n\nexport const required = (message?: Text): PropertyDecorator =>\n constraint(v => isNotEmpty(v), message ?? 'Property {property} is required, and may not be empty.');\n\nexport const notEmpty = (message?: Text): PropertyDecorator => constraint(v => isNotEmpty(v), message ?? 'Property {property} may not be empty.');\n\nexport const valid = (): PropertyDecorator => constraint(v => validate(v), '');\n\nexport const optional = (): PropertyDecorator => constraint(v => !isDefined(v) || validate(v), '');\n\nexport const includes = (sub: string, message?: string): PropertyDecorator =>\n constraint(s => isDefined(s) && isString(s) && s.includes(sub), message ?? `Value {actual} must include '${sub}'.`);\n\nexport const inList = (values: unknown[], message?: Text): PropertyDecorator =>\n constraint(v => isDefined(v) && isIn(v, values), message ?? 'Value {actual} must appear in list.');\n\nexport const inOptionalList = (values: unknown[], message?: Text): PropertyDecorator =>\n constraint(v => !isDefined(v) || isIn(v, values), message ?? 'Value {actual} must appear in list.');\n\nexport const gt = (limit: number, message?: Text): PropertyDecorator => constraint(v => v > limit, message ?? `Value {actual} must be larger than '${limit}'.`);\n\nexport const gte = (limit: number, message?: Text): PropertyDecorator =>\n constraint(v => v >= limit, message ?? `Value {actual} must be larger than or equal to ${limit}.`);\n\nexport const lt = (limit: number, message?: Text): PropertyDecorator => constraint(v => v < limit, message ?? `Value {actual} must be smaller than ${limit}.`);\n\nexport const lte = (limit: number, message?: Text): PropertyDecorator =>\n constraint(v => v <= limit, message ?? `Value {actual} must be smaller than or equal to ${limit}.`);\n\nexport const past = (message?: Text): PropertyDecorator => constraint(v => inPast(v), message ?? 'Value {actual} must lay in the past.');\n\nexport const future = (message?: Text): PropertyDecorator => constraint(v => inFuture(v), message ?? 'Value {actual} must lay in the future.');\n\nexport const minLength = (length: number, message?: Text): PropertyDecorator =>\n constraint(\n v =>\n tryTo(() => v)\n .is.defined()\n .map(v => text(v).toString().length >= length)\n .orElse(true) as boolean,\n message ?? `Value {actual} must be at least '${length}' characters long.`\n );\n\nexport const maxLength = (length: number, message?: Text): PropertyDecorator =>\n constraint(\n v =>\n tryTo(() => v)\n .is.defined()\n .map(v => text(v).toString().length <= length)\n .orElse(true) as boolean,\n message ?? `Value {actual} cannot be longer than '${length}' characters.`\n );\n\nexport const rule = (message?: Text): PropertyDecorator =>\n constraint(v => (isFunction(v) ? (v() as boolean | Results) : isBoolean(v) ? v : false), message ?? `Value {actual} must be true`);\n"],"mappings":";AAAA,SAAe,UAAU,QAAQ,WAAW,WAAW,YAAY,MAAM,YAAY,UAAgB,MAAe,MAAY,QAAQ,aAAa;AACrJ,SAAS,gBAA2B;AAI7B,MAAM,aACX,CAAI,GAAe,YACnB,CAAC,SAAkB,aAAoC;AACrD,QAAM,KAAK,KAAK,OAAO,EAAE,SAAS,QAAQ,EAAE,IAAqB,YAAY,KAAK,OAAkB;AACpG,OAAK,OAAO,EACT,SAAS,QAAQ,EACjB,IAAI,cAAc,GAAG,IAAI,EAAE,UAAU,YAAY,GAAG,MAAM,QAAQ,CAAC,CAAC;AACzE;AAEK,MAAM,UAAU,CAAC,YAAsC,WAAW,OAAK,UAAU,CAAC,GAAG,WAAW,sCAAsC;AAEtI,MAAM,WAAW,CAAC,YACvB,WAAW,OAAK,WAAW,CAAC,GAAG,WAAW,wDAAwD;AAE7F,MAAM,WAAW,CAAC,YAAsC,WAAW,OAAK,WAAW,CAAC,GAAG,WAAW,uCAAuC;AAEzI,MAAM,QAAQ,MAAyB,WAAW,OAAK,SAAS,CAAC,GAAG,EAAE;AAEtE,MAAM,WAAW,MAAyB,WAAW,OAAK,CAAC,UAAU,CAAC,KAAK,SAAS,CAAC,GAAG,EAAE;AAE1F,MAAM,WAAW,CAAC,KAAa,YACpC,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B,WAAW,yCAAyC,MAAM;AAC5D;AAEK,MAAM,OAAO,CAAC,YACnB,WAAW,OAAM,WAAW,CAAC,IAAK,EAAE,IAA0B,UAAU,CAAC,IAAI,IAAI,OAAQ,WAAW,6BAA6B;","names":["v"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thisisagile/easy",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.13.0",
|
|
4
4
|
"description": "Straightforward library for building domain-driven microservice architectures",
|
|
5
5
|
"author": "Sander Hoogendoorn",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@thisisagile/easy-test": "15.
|
|
36
|
+
"@thisisagile/easy-test": "15.13.0",
|
|
37
37
|
"@types/form-urlencoded": "^4.4.0",
|
|
38
38
|
"@types/jsonwebtoken": "^9.0.2",
|
|
39
39
|
"@types/luxon": "3.2.0",
|
package/src/types/Uri.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { asString, Text } from './Text';
|
|
|
3
3
|
import { toName } from './Constructor';
|
|
4
4
|
import { ctx } from './Context';
|
|
5
5
|
import { List, toList } from './List';
|
|
6
|
-
import { entries, meta } from
|
|
6
|
+
import { entries, meta } from './Meta';
|
|
7
7
|
import { tryTo } from './Try';
|
|
8
8
|
import { Optional } from './Types';
|
|
9
9
|
import { OneOrMore, toArray } from './Array';
|
|
@@ -55,7 +55,7 @@ export type Uri = {
|
|
|
55
55
|
toString: () => string;
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
-
export type UriExpandProps = { q: string
|
|
58
|
+
export type UriExpandProps = { q: string; s: string };
|
|
59
59
|
|
|
60
60
|
export class EasyUri<Props = UriExpandProps> implements Uri {
|
|
61
61
|
static readonly id = uri.path('id');
|
|
@@ -66,7 +66,7 @@ export class EasyUri<Props = UriExpandProps> implements Uri {
|
|
|
66
66
|
static readonly take = uri.query('take');
|
|
67
67
|
|
|
68
68
|
readonly host = uri.host();
|
|
69
|
-
|
|
69
|
+
protected resource = uri.resource(this);
|
|
70
70
|
|
|
71
71
|
protected state: any = {};
|
|
72
72
|
|
|
@@ -29,6 +29,9 @@ export const includes = (sub: string, message?: string): PropertyDecorator =>
|
|
|
29
29
|
export const inList = (values: unknown[], message?: Text): PropertyDecorator =>
|
|
30
30
|
constraint(v => isDefined(v) && isIn(v, values), message ?? 'Value {actual} must appear in list.');
|
|
31
31
|
|
|
32
|
+
export const inOptionalList = (values: unknown[], message?: Text): PropertyDecorator =>
|
|
33
|
+
constraint(v => !isDefined(v) || isIn(v, values), message ?? 'Value {actual} must appear in list.');
|
|
34
|
+
|
|
32
35
|
export const gt = (limit: number, message?: Text): PropertyDecorator => constraint(v => v > limit, message ?? `Value {actual} must be larger than '${limit}'.`);
|
|
33
36
|
|
|
34
37
|
export const gte = (limit: number, message?: Text): PropertyDecorator =>
|