@hg-ts/validation 0.1.14
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/.eslintcache +1 -0
- package/.eslintrc.json +1 -0
- package/dist/extensions.d.ts +8 -0
- package/dist/extensions.d.ts.map +1 -0
- package/dist/extensions.js +13 -0
- package/dist/extensions.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist-esm/async-context.not-found.exception.d.ts +5 -0
- package/dist-esm/async-context.not-found.exception.d.ts.map +1 -0
- package/dist-esm/async-context.not-found.exception.js +7 -0
- package/dist-esm/async-context.not-found.exception.js.map +1 -0
- package/dist-esm/async-context.provider.d.ts +18 -0
- package/dist-esm/async-context.provider.d.ts.map +1 -0
- package/dist-esm/async-context.provider.js +57 -0
- package/dist-esm/async-context.provider.js.map +1 -0
- package/dist-esm/async-context.test-suite.d.ts +16 -0
- package/dist-esm/async-context.test-suite.d.ts.map +1 -0
- package/dist-esm/async-context.test-suite.js +156 -0
- package/dist-esm/async-context.test-suite.js.map +1 -0
- package/dist-esm/extensions.d.ts +8 -0
- package/dist-esm/extensions.d.ts.map +1 -0
- package/dist-esm/extensions.js +10 -0
- package/dist-esm/extensions.js.map +1 -0
- package/dist-esm/index.d.ts +5 -0
- package/dist-esm/index.d.ts.map +1 -0
- package/dist-esm/index.js +5 -0
- package/dist-esm/index.js.map +1 -0
- package/package.json +35 -0
- package/src/extensions.ts +34 -0
- package/src/index.ts +5 -0
- package/tsconfig.esm.json +9 -0
- package/tsconfig.json +9 -0
package/.eslintcache
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[{"/Volumes/Work/ts/hg/framework/packages/async-context/src/async-context.not-found.exception.ts":"1","/Volumes/Work/ts/hg/framework/packages/async-context/src/async-context.provider.ts":"2","/Volumes/Work/ts/hg/framework/packages/async-context/src/async-context.test-suite.ts":"3","/Volumes/Work/ts/hg/framework/packages/async-context/src/index.ts":"4","/Volumes/Work/ts/hg/framework/packages/validation/src/extensions.ts":"5","/Volumes/Work/ts/hg/framework/packages/validation/src/index.ts":"6"},{"size":186,"mtime":1698022585968,"results":"7","hashOfConfig":"8"},{"size":2161,"mtime":1698022585968,"results":"9","hashOfConfig":"8"},{"size":3714,"mtime":1698022585968,"results":"10","hashOfConfig":"8"},{"size":95,"mtime":1698022585968,"results":"11","hashOfConfig":"8"},{"size":1062,"mtime":1713665782754,"results":"12","hashOfConfig":"13"},{"size":88,"mtime":1713662918071,"results":"14","hashOfConfig":"13"},{"filePath":"15","messages":"16","suppressedMessages":"17","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1o9szx6",{"filePath":"18","messages":"19","suppressedMessages":"20","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"21","messages":"22","suppressedMessages":"23","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"24","messages":"25","suppressedMessages":"26","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"27","messages":"28","suppressedMessages":"29","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"xqlb75",{"filePath":"30","messages":"31","suppressedMessages":"32","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Volumes/Work/ts/hg/framework/packages/async-context/src/async-context.not-found.exception.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/async-context/src/async-context.provider.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/async-context/src/async-context.test-suite.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/async-context/src/index.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/validation/src/extensions.ts",[],["33"],"/Volumes/Work/ts/hg/framework/packages/validation/src/index.ts",[],[],{"ruleId":"34","severity":2,"message":"35","line":13,"column":12,"nodeType":"36","messageId":"37","endLine":13,"endColumn":21,"fix":"38","suppressions":"39"},"@typescript-eslint/consistent-type-definitions","Use a `type` instead of an `interface`.","Identifier","typeOverInterface",{"range":"40","text":"41"},["42"],[234,321],"type ZodSchema<Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output> = ",{"kind":"43","justification":"44"},"directive",""]
|
package/.eslintrc.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "extends": "@hg-ts-config/eslint-config" }
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ZodEffects, ZodTypeDef, infer as ZodInfer, input as ZodInput, ZodPipeline, ZodBoolean } from 'zod';
|
|
2
|
+
declare module 'zod' {
|
|
3
|
+
interface ZodSchema<Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output> {
|
|
4
|
+
enforceEnv<T extends ZodSchema<Output, Def, Input>>(this: T, name: string): ZodEffects<T, ZodInfer<T> | string>;
|
|
5
|
+
transformBooleanString<T extends ZodSchema<Output, Def, Input>>(this: T): ZodPipeline<ZodEffects<T, boolean, ZodInput<T>>, ZodBoolean>;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=extensions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extensions.d.ts","sourceRoot":"","sources":["../src/extensions.ts"],"names":[],"mappings":"AAAA,OAAY,EACX,UAAU,EAEV,UAAU,EACV,KAAK,IAAI,QAAQ,EACjB,KAAK,IAAI,QAAQ,EACjB,WAAW,EACX,UAAU,EACV,MAAM,KAAK,CAAC;AAEb,OAAO,QAAQ,KAAK,CAAC;IAEpB,UAAU,SAAS,CAAC,MAAM,GAAG,GAAG,EAAE,GAAG,SAAS,UAAU,GAAG,UAAU,EAAE,KAAK,GAAG,MAAM;QACpF,UAAU,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;QAChH,sBAAsB,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,EAC7D,IAAI,EAAE,CAAC,GACL,WAAW,CAAC,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;KAChE;CACD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const zod_1 = tslib_1.__importDefault(require("zod"));
|
|
5
|
+
zod_1.default.Schema.prototype.enforceEnv = function (name) {
|
|
6
|
+
return this.transform(value => process.env[name] ?? value);
|
|
7
|
+
};
|
|
8
|
+
zod_1.default.Schema.prototype.transformBooleanString = function () {
|
|
9
|
+
return this
|
|
10
|
+
.transform(value => (typeof value === 'boolean' ? value : value === 'true'))
|
|
11
|
+
.pipe(zod_1.default.boolean());
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=extensions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extensions.js","sourceRoot":"","sources":["../src/extensions.ts"],"names":[],"mappings":";;;AAAA,sDAQa;AAYb,aAAG,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,GAAG,UAEjC,IAAY;IAEZ,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC;AAC5D,CAAC,CAAC;AAEF,aAAG,CAAC,MAAM,CAAC,SAAS,CAAC,sBAAsB,GAAG;IAG7C,OAAO,IAAI;SACT,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC;SAC3E,IAAI,CAAC,aAAG,CAAC,OAAO,EAAE,CAAC,CAAC;AACvB,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AACtB,cAAc,KAAK,CAAC;AACpB,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,eAAe,GAAG,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
require("./extensions");
|
|
5
|
+
tslib_1.__exportStar(require("zod"), exports);
|
|
6
|
+
const zod_1 = tslib_1.__importDefault(require("zod"));
|
|
7
|
+
exports.default = zod_1.default;
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,wBAAsB;AACtB,8CAAoB;AACpB,sDAAsB;AAEtB,kBAAe,aAAG,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-context.not-found.exception.d.ts","sourceRoot":"","sources":["../src/async-context.not-found.exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,qBAAa,6BAA8B,SAAQ,aAAa;;CAI/D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-context.not-found.exception.js","sourceRoot":"","sources":["../src/async-context.not-found.exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,OAAO,6BAA8B,SAAQ,aAAa;IAC/D;QACC,KAAK,CAAC,4BAA4B,CAAC,CAAC;IACrC,CAAC;CACD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="@hg-ts/types" />
|
|
3
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
4
|
+
import { MonoTypeOperatorFunction } from 'rxjs';
|
|
5
|
+
type AsyncContextProviderCallback<T> = () => T;
|
|
6
|
+
type AsyncContextFactory<InputType, Context> = (input: InputType) => Context;
|
|
7
|
+
export declare class AsyncContextProvider<Context> {
|
|
8
|
+
protected readonly storage: AsyncLocalStorage<Context>;
|
|
9
|
+
get(): Nullable<Context>;
|
|
10
|
+
getOrFail(): NonNullable<Context>;
|
|
11
|
+
run<ReturnType>(context: Context, callback: AsyncContextProviderCallback<ReturnType>): ReturnType;
|
|
12
|
+
exit<ReturnType>(callback: AsyncContextProviderCallback<ReturnType>): ReturnType;
|
|
13
|
+
runOperator<T>(factory?: AsyncContextFactory<T, Context>): MonoTypeOperatorFunction<T>;
|
|
14
|
+
exitOperator<T>(): MonoTypeOperatorFunction<T>;
|
|
15
|
+
private createOperator;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=async-context.provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-context.provider.d.ts","sourceRoot":"","sources":["../src/async-context.provider.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EACN,wBAAwB,EAExB,MAAM,MAAM,CAAC;AAGd,KAAK,4BAA4B,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC;AAC/C,KAAK,mBAAmB,CAAC,SAAS,EAAE,OAAO,IAAI,CAAC,KAAK,EAAE,SAAS,KAAK,OAAO,CAAC;AAI7E,qBAAa,oBAAoB,CAAC,OAAO;IACxC,SAAS,CAAC,QAAQ,CAAC,OAAO,6BAAoC;IAEvD,GAAG,IAAI,QAAQ,CAAC,OAAO,CAAC;IAIxB,SAAS,IAAI,WAAW,CAAC,OAAO,CAAC;IAUjC,GAAG,CAAC,UAAU,EACpB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,4BAA4B,CAAC,UAAU,CAAC,GAChD,UAAU;IAIN,IAAI,CAAC,UAAU,EACrB,QAAQ,EAAE,4BAA4B,CAAC,UAAU,CAAC,GAChD,UAAU;IAIN,WAAW,CAAC,CAAC,EACnB,OAAO,CAAC,EAAE,mBAAmB,CAAC,CAAC,EAAE,OAAO,CAAC,GACvC,wBAAwB,CAAC,CAAC,CAAC;IAOvB,YAAY,CAAC,CAAC,KAAK,wBAAwB,CAAC,CAAC,CAAC;IAIrD,OAAO,CAAC,cAAc;CA0BtB"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { Observable, } from 'rxjs';
|
|
3
|
+
import { AsyncContextNotFoundException } from './async-context.not-found.exception';
|
|
4
|
+
export class AsyncContextProvider {
|
|
5
|
+
storage = new AsyncLocalStorage();
|
|
6
|
+
get() {
|
|
7
|
+
return this.storage.getStore() ?? null;
|
|
8
|
+
}
|
|
9
|
+
getOrFail() {
|
|
10
|
+
const context = this.get();
|
|
11
|
+
if (typeof context === 'undefined' || context === null) {
|
|
12
|
+
throw new AsyncContextNotFoundException();
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
15
|
+
}
|
|
16
|
+
run(context, callback) {
|
|
17
|
+
return this.storage.run(context, callback);
|
|
18
|
+
}
|
|
19
|
+
exit(callback) {
|
|
20
|
+
return this.storage.exit(callback);
|
|
21
|
+
}
|
|
22
|
+
runOperator(factory) {
|
|
23
|
+
return this.createOperator((next, value) => {
|
|
24
|
+
const context = factory ? factory(value) : value;
|
|
25
|
+
this.storage.run(context, next);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
exitOperator() {
|
|
29
|
+
return this.createOperator(next => this.storage.exit(next));
|
|
30
|
+
}
|
|
31
|
+
createOperator(onNext) {
|
|
32
|
+
return (source) => new Observable(subscriber => {
|
|
33
|
+
const callNext = input => {
|
|
34
|
+
const next = () => {
|
|
35
|
+
if (!subscriber.closed) {
|
|
36
|
+
subscriber.next(input);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
onNext(next, input);
|
|
40
|
+
};
|
|
41
|
+
const callError = input => {
|
|
42
|
+
const next = () => {
|
|
43
|
+
if (!subscriber.closed) {
|
|
44
|
+
subscriber.error(input);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
onNext(next, input);
|
|
48
|
+
};
|
|
49
|
+
source.subscribe({
|
|
50
|
+
next: callNext,
|
|
51
|
+
error: callError,
|
|
52
|
+
complete: () => subscriber.complete(),
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=async-context.provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-context.provider.js","sourceRoot":"","sources":["../src/async-context.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAEN,UAAU,GACV,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,6BAA6B,EAAE,MAAM,qCAAqC,CAAC;AAOpF,MAAM,OAAO,oBAAoB;IACb,OAAO,GAAG,IAAI,iBAAiB,EAAW,CAAC;IAEvD,GAAG;QACT,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,IAAI,CAAC;IACxC,CAAC;IAEM,SAAS;QACf,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAE3B,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,KAAK,IAAI,EAAE;YAC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,CAAC,UAAU,CAAC,MAAM,EAAE;wBACvB,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;qBACxB;gBACF,CAAC,CAAC;gBACF,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YACrB,CAAC,CAAC;YAEF,MAAM,CAAC,SAAS,CAAC;gBAChB,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,SAAS;gBAChB,QAAQ,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE;aACrC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACJ,CAAC;CACD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TestSuite } from '@hg-ts/tests';
|
|
2
|
+
export declare class AsyncContextTestSuite extends TestSuite {
|
|
3
|
+
private context;
|
|
4
|
+
emptyContext(): Promise<void>;
|
|
5
|
+
noPromiseContext(): Promise<void>;
|
|
6
|
+
promiseContext(): Promise<void>;
|
|
7
|
+
operatorContext(): Promise<void>;
|
|
8
|
+
operatorWithFactory(): Promise<void>;
|
|
9
|
+
operatorWithErrorContext(): Promise<void>;
|
|
10
|
+
operatorAfterUnsubscribe(): Promise<void>;
|
|
11
|
+
operatorWithErrorAfterUnsubscribe(): Promise<void>;
|
|
12
|
+
contextNotFound(): Promise<void>;
|
|
13
|
+
beforeEach(): Promise<void>;
|
|
14
|
+
private createOperatorTestSubscription;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=async-context.test-suite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-context.test-suite.d.ts","sourceRoot":"","sources":["../src/async-context.test-suite.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,SAAS,EACT,MAAM,cAAc,CAAC;AAiBtB,qBACa,qBAAsB,SAAQ,SAAS;IACnD,OAAO,CAAC,OAAO,CAA+B;IAGjC,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAK7B,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBjC,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAiB/B,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAUhC,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAUpC,wBAAwB,IAAI,OAAO,CAAC,IAAI,CAAC;IAUzC,wBAAwB,IAAI,OAAO,CAAC,IAAI,CAAC;IAWzC,iCAAiC,IAAI,OAAO,CAAC,IAAI,CAAC;IAYlD,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAIvB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjD,OAAO,CAAC,8BAA8B;CAgCtC"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Describe, expect, ExpectException, Test, TestSuite, } from '@hg-ts/tests';
|
|
3
|
+
import { Subject, tap, } from 'rxjs';
|
|
4
|
+
import { AsyncContextNotFoundException } from './async-context.not-found.exception';
|
|
5
|
+
import { AsyncContextProvider } from './async-context.provider';
|
|
6
|
+
let AsyncContextTestSuite = class AsyncContextTestSuite extends TestSuite {
|
|
7
|
+
context;
|
|
8
|
+
async emptyContext() {
|
|
9
|
+
expect(this.context.get()).toBe(null);
|
|
10
|
+
}
|
|
11
|
+
async noPromiseContext() {
|
|
12
|
+
const contextValue = Math.random();
|
|
13
|
+
const resultValue = Math.random();
|
|
14
|
+
const result = this.context.run(contextValue, () => {
|
|
15
|
+
expect(this.context.getOrFail()).toBe(contextValue);
|
|
16
|
+
this.context.exit(() => {
|
|
17
|
+
expect(this.context.get()).toBe(null);
|
|
18
|
+
});
|
|
19
|
+
return resultValue;
|
|
20
|
+
});
|
|
21
|
+
expect(result).toBe(resultValue);
|
|
22
|
+
}
|
|
23
|
+
async promiseContext() {
|
|
24
|
+
const contextValue = Math.random();
|
|
25
|
+
const resultValue = Math.random();
|
|
26
|
+
const result = await this.context.run(contextValue, async () => {
|
|
27
|
+
expect(this.context.getOrFail()).toBe(contextValue);
|
|
28
|
+
await this.context.exit(async () => {
|
|
29
|
+
expect(this.context.get()).toBe(null);
|
|
30
|
+
});
|
|
31
|
+
return resultValue;
|
|
32
|
+
});
|
|
33
|
+
expect(result).toBe(resultValue);
|
|
34
|
+
}
|
|
35
|
+
async operatorContext() {
|
|
36
|
+
const { subject, input } = this.createOperatorTestSubscription();
|
|
37
|
+
subject.next(input);
|
|
38
|
+
subject.complete();
|
|
39
|
+
expect.assertions(4);
|
|
40
|
+
}
|
|
41
|
+
async operatorWithFactory() {
|
|
42
|
+
const { subject, input } = this.createOperatorTestSubscription(value => -value);
|
|
43
|
+
subject.next(input);
|
|
44
|
+
subject.complete();
|
|
45
|
+
expect.assertions(4);
|
|
46
|
+
}
|
|
47
|
+
async operatorWithErrorContext() {
|
|
48
|
+
const { subject, input } = this.createOperatorTestSubscription();
|
|
49
|
+
subject.error(input);
|
|
50
|
+
subject.complete();
|
|
51
|
+
expect.assertions(4);
|
|
52
|
+
}
|
|
53
|
+
async operatorAfterUnsubscribe() {
|
|
54
|
+
const { subject, input, subscription } = this.createOperatorTestSubscription();
|
|
55
|
+
subscription.unsubscribe();
|
|
56
|
+
subject.next(input);
|
|
57
|
+
subject.complete();
|
|
58
|
+
expect.assertions(2);
|
|
59
|
+
}
|
|
60
|
+
async operatorWithErrorAfterUnsubscribe() {
|
|
61
|
+
const { subject, input, subscription } = this.createOperatorTestSubscription();
|
|
62
|
+
subscription.unsubscribe();
|
|
63
|
+
subject.error(input);
|
|
64
|
+
subject.complete();
|
|
65
|
+
expect.assertions(2);
|
|
66
|
+
}
|
|
67
|
+
async contextNotFound() {
|
|
68
|
+
this.context.getOrFail();
|
|
69
|
+
}
|
|
70
|
+
async beforeEach() {
|
|
71
|
+
this.context = new AsyncContextProvider();
|
|
72
|
+
}
|
|
73
|
+
createOperatorTestSubscription(factory) {
|
|
74
|
+
const subject = new Subject();
|
|
75
|
+
const input = Math.random();
|
|
76
|
+
const context = factory ? factory(input) : input;
|
|
77
|
+
const withContext = (value) => {
|
|
78
|
+
expect(value).toBe(input);
|
|
79
|
+
expect(this.context.getOrFail()).toBe(context);
|
|
80
|
+
};
|
|
81
|
+
const withoutContext = (value) => {
|
|
82
|
+
expect(value).toBe(input);
|
|
83
|
+
expect(this.context.get()).toBe(null);
|
|
84
|
+
};
|
|
85
|
+
const subscription = subject.asObservable()
|
|
86
|
+
.pipe(this.context.runOperator(factory), tap({
|
|
87
|
+
next: withContext,
|
|
88
|
+
error: withContext,
|
|
89
|
+
}), this.context.exitOperator(), tap({
|
|
90
|
+
next: withoutContext,
|
|
91
|
+
error: withoutContext,
|
|
92
|
+
}))
|
|
93
|
+
.subscribe({ next() { }, error() { } });
|
|
94
|
+
return { subject, subscription, input, context };
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
__decorate([
|
|
98
|
+
Test(),
|
|
99
|
+
__metadata("design:type", Function),
|
|
100
|
+
__metadata("design:paramtypes", []),
|
|
101
|
+
__metadata("design:returntype", Promise)
|
|
102
|
+
], AsyncContextTestSuite.prototype, "emptyContext", null);
|
|
103
|
+
__decorate([
|
|
104
|
+
Test(),
|
|
105
|
+
__metadata("design:type", Function),
|
|
106
|
+
__metadata("design:paramtypes", []),
|
|
107
|
+
__metadata("design:returntype", Promise)
|
|
108
|
+
], AsyncContextTestSuite.prototype, "noPromiseContext", null);
|
|
109
|
+
__decorate([
|
|
110
|
+
Test(),
|
|
111
|
+
__metadata("design:type", Function),
|
|
112
|
+
__metadata("design:paramtypes", []),
|
|
113
|
+
__metadata("design:returntype", Promise)
|
|
114
|
+
], AsyncContextTestSuite.prototype, "promiseContext", null);
|
|
115
|
+
__decorate([
|
|
116
|
+
Test(),
|
|
117
|
+
__metadata("design:type", Function),
|
|
118
|
+
__metadata("design:paramtypes", []),
|
|
119
|
+
__metadata("design:returntype", Promise)
|
|
120
|
+
], AsyncContextTestSuite.prototype, "operatorContext", null);
|
|
121
|
+
__decorate([
|
|
122
|
+
Test(),
|
|
123
|
+
__metadata("design:type", Function),
|
|
124
|
+
__metadata("design:paramtypes", []),
|
|
125
|
+
__metadata("design:returntype", Promise)
|
|
126
|
+
], AsyncContextTestSuite.prototype, "operatorWithFactory", null);
|
|
127
|
+
__decorate([
|
|
128
|
+
Test(),
|
|
129
|
+
__metadata("design:type", Function),
|
|
130
|
+
__metadata("design:paramtypes", []),
|
|
131
|
+
__metadata("design:returntype", Promise)
|
|
132
|
+
], AsyncContextTestSuite.prototype, "operatorWithErrorContext", null);
|
|
133
|
+
__decorate([
|
|
134
|
+
Test(),
|
|
135
|
+
__metadata("design:type", Function),
|
|
136
|
+
__metadata("design:paramtypes", []),
|
|
137
|
+
__metadata("design:returntype", Promise)
|
|
138
|
+
], AsyncContextTestSuite.prototype, "operatorAfterUnsubscribe", null);
|
|
139
|
+
__decorate([
|
|
140
|
+
Test(),
|
|
141
|
+
__metadata("design:type", Function),
|
|
142
|
+
__metadata("design:paramtypes", []),
|
|
143
|
+
__metadata("design:returntype", Promise)
|
|
144
|
+
], AsyncContextTestSuite.prototype, "operatorWithErrorAfterUnsubscribe", null);
|
|
145
|
+
__decorate([
|
|
146
|
+
Test(),
|
|
147
|
+
ExpectException(AsyncContextNotFoundException),
|
|
148
|
+
__metadata("design:type", Function),
|
|
149
|
+
__metadata("design:paramtypes", []),
|
|
150
|
+
__metadata("design:returntype", Promise)
|
|
151
|
+
], AsyncContextTestSuite.prototype, "contextNotFound", null);
|
|
152
|
+
AsyncContextTestSuite = __decorate([
|
|
153
|
+
Describe()
|
|
154
|
+
], AsyncContextTestSuite);
|
|
155
|
+
export { AsyncContextTestSuite };
|
|
156
|
+
//# sourceMappingURL=async-context.test-suite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-context.test-suite.js","sourceRoot":"","sources":["../src/async-context.test-suite.ts"],"names":[],"mappings":";AAAA,OAAO,EACN,QAAQ,EACR,MAAM,EACN,eAAe,EACf,IAAI,EACJ,SAAS,GACT,MAAM,cAAc,CA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{ ZodEffects, ZodTypeDef, infer as ZodInfer, input as ZodInput, ZodPipeline, ZodBoolean } from 'zod';
|
|
2
|
+
declare module 'zod' {
|
|
3
|
+
interface ZodSchema<Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output> {
|
|
4
|
+
enforceEnv<T extends ZodSchema<Output, Def, Input>>(this: T, name: string): ZodEffects<T, ZodInfer<T> | string>;
|
|
5
|
+
transformBooleanString<T extends ZodSchema<Output, Def, Input>>(this: T): ZodPipeline<ZodEffects<T, boolean, ZodInput<T>>, ZodBoolean>;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=extensions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extensions.d.ts","sourceRoot":"","sources":["../src/extensions.ts"],"names":[],"mappings":"AAAA,OAAY,EACX,UAAU,EAEV,UAAU,EACV,KAAK,IAAI,QAAQ,EACjB,KAAK,IAAI,QAAQ,EACjB,WAAW,EACX,UAAU,EACV,MAAM,KAAK,CAAC;AAEb,OAAO,QAAQ,KAAK,CAAC;IAEpB,UAAU,SAAS,CAAC,MAAM,GAAG,GAAG,EAAE,GAAG,SAAS,UAAU,GAAG,UAAU,EAAE,KAAK,GAAG,MAAM;QACpF,UAAU,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;QAChH,sBAAsB,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,EAC7D,IAAI,EAAE,CAAC,GACL,WAAW,CAAC,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;KAChE;CACD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import zod from 'zod';
|
|
2
|
+
zod.Schema.prototype.enforceEnv = function (name) {
|
|
3
|
+
return this.transform(value => process.env[name] ?? value);
|
|
4
|
+
};
|
|
5
|
+
zod.Schema.prototype.transformBooleanString = function () {
|
|
6
|
+
return this
|
|
7
|
+
.transform(value => (typeof value === 'boolean' ? value : value === 'true'))
|
|
8
|
+
.pipe(zod.boolean());
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=extensions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extensions.js","sourceRoot":"","sources":["../src/extensions.ts"],"names":[],"mappings":"AAAA,OAAO,GAQN,MAAM,KAAK,CAAC;AAYb,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,GAAG,UAEjC,IAAY;IAEZ,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC;AAC5D,CAAC,CAAC;AAEF,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,sBAAsB,GAAG;IAG7C,OAAO,IAAI;SACT,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC;SAC3E,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;AACvB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AACtB,cAAc,KAAK,CAAC;AACpB,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,eAAe,GAAG,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AACtB,cAAc,KAAK,CAAC;AACpB,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,eAAe,GAAG,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hg-ts/validation",
|
|
3
|
+
"version": "0.1.14",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"module": "dist-esm/index.js",
|
|
6
|
+
"repository": "git@gitlab.com:hyper-graph/framework.git",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"prepack": "yarn build && yarn lint",
|
|
9
|
+
"build": "hg build",
|
|
10
|
+
"build:dev": "hg build:dev",
|
|
11
|
+
"lint": "hg lint",
|
|
12
|
+
"lint:fix": "hg lint:fix"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@hg-ts-config/eslint-config": "0.1.14",
|
|
16
|
+
"@hg-ts-config/typescript": "0.1.14",
|
|
17
|
+
"@hg-ts/cli": "0.1.14",
|
|
18
|
+
"@hg-ts/types": "0.1.14",
|
|
19
|
+
"@types/node": "20.8.7",
|
|
20
|
+
"@typescript-eslint/eslint-plugin": "6.8.0",
|
|
21
|
+
"@typescript-eslint/parser": "6.8.0",
|
|
22
|
+
"eslint": "8.52.0",
|
|
23
|
+
"reflect-metadata": "0.1.13",
|
|
24
|
+
"tsc-watch": "6.0.4",
|
|
25
|
+
"tslib": "2.6.2",
|
|
26
|
+
"typescript": "5.2.2"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"reflect-metadata": "*",
|
|
30
|
+
"tslib": "*"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"zod": "3.22.5"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import zod, {
|
|
2
|
+
ZodEffects,
|
|
3
|
+
ZodSchema,
|
|
4
|
+
ZodTypeDef,
|
|
5
|
+
infer as ZodInfer,
|
|
6
|
+
input as ZodInput,
|
|
7
|
+
ZodPipeline,
|
|
8
|
+
ZodBoolean,
|
|
9
|
+
} from 'zod';
|
|
10
|
+
|
|
11
|
+
declare module 'zod' {
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
13
|
+
interface ZodSchema<Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output> {
|
|
14
|
+
enforceEnv<T extends ZodSchema<Output, Def, Input>>(this: T, name: string): ZodEffects<T, ZodInfer<T> | string>;
|
|
15
|
+
transformBooleanString<T extends ZodSchema<Output, Def, Input>>(
|
|
16
|
+
this: T,
|
|
17
|
+
): ZodPipeline<ZodEffects<T, boolean, ZodInput<T>>, ZodBoolean>;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
zod.Schema.prototype.enforceEnv = function<T extends ZodSchema>(
|
|
22
|
+
this: T,
|
|
23
|
+
name: string,
|
|
24
|
+
): ZodEffects<T, ZodInfer<T> | string> {
|
|
25
|
+
return this.transform(value => process.env[name] ?? value);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
zod.Schema.prototype.transformBooleanString = function<T extends ZodSchema>(
|
|
29
|
+
this: T,
|
|
30
|
+
): ZodPipeline<zod.ZodEffects<T, boolean, ZodInput<T>>, ZodBoolean> {
|
|
31
|
+
return this
|
|
32
|
+
.transform(value => (typeof value === 'boolean' ? value : value === 'true'))
|
|
33
|
+
.pipe(zod.boolean());
|
|
34
|
+
};
|
package/src/index.ts
ADDED