@trayio/commons 5.35.0-unstable.fd7158a → 6.0.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/base64/Base64.d.ts +10 -5
- package/dist/base64/Base64.d.ts.map +1 -1
- package/dist/base64/Base64.js +40 -8
- package/dist/base64/Base64.unit.test.js +27 -4
- package/dist/buffer/BufferExtensions.d.ts +4 -4
- package/dist/buffer/BufferExtensions.d.ts.map +1 -1
- package/dist/buffer/BufferExtensions.js +38 -25
- package/dist/buffer/BufferExtensions.unit.test.js +45 -22
- package/dist/callsite/CallSite.js +7 -17
- package/dist/codec/CamelCasePropertyNameCodec.d.ts +2 -2
- package/dist/codec/CamelCasePropertyNameCodec.d.ts.map +1 -1
- package/dist/codec/CamelCasePropertyNameCodec.js +25 -2
- package/dist/codec/Codec.abstract.test.d.ts +2 -2
- package/dist/codec/Codec.abstract.test.d.ts.map +1 -1
- package/dist/codec/Codec.abstract.test.js +31 -5
- package/dist/codec/Codec.d.ts +2 -2
- package/dist/codec/Codec.d.ts.map +1 -1
- package/dist/codec/CompositeCodec.d.ts +2 -2
- package/dist/codec/CompositeCodec.d.ts.map +1 -1
- package/dist/codec/CompositeCodec.js +26 -2
- package/dist/codec/PartialRedactionCodec.d.ts +2 -2
- package/dist/codec/PartialRedactionCodec.d.ts.map +1 -1
- package/dist/codec/PartialRedactionCodec.js +25 -2
- package/dist/codec/RemoveNullValuesCodec.d.ts +2 -2
- package/dist/codec/RemoveNullValuesCodec.d.ts.map +1 -1
- package/dist/codec/RemoveNullValuesCodec.js +25 -2
- package/dist/codec/RemoveTopLevelTagCodec.d.ts +2 -2
- package/dist/codec/RemoveTopLevelTagCodec.d.ts.map +1 -1
- package/dist/codec/RemoveTopLevelTagCodec.js +25 -2
- package/dist/codec/SensitiveRemoveTagAndRedactCodec.d.ts +2 -2
- package/dist/codec/SensitiveRemoveTagAndRedactCodec.d.ts.map +1 -1
- package/dist/codec/SensitiveRemoveTagAndRedactCodec.js +25 -2
- package/dist/codec/SensitiveRemoveTagAndRedactCodec.unit.test.js +38 -15
- package/dist/codec/SnakeCasePropertyNameCodec.d.ts +2 -2
- package/dist/codec/SnakeCasePropertyNameCodec.d.ts.map +1 -1
- package/dist/codec/SnakeCasePropertyNameCodec.js +25 -2
- package/dist/codec/TypeCodec.d.ts +8 -24
- package/dist/codec/TypeCodec.d.ts.map +1 -1
- package/dist/codec/TypeCodec.js +48 -40
- package/dist/codec/TypeCodec.unit.test.js +38 -12
- package/dist/dynamicschema/DynamicSchema.d.ts +12 -6
- package/dist/dynamicschema/DynamicSchema.d.ts.map +1 -1
- package/dist/dynamicschema/DynamicSchema.js +41 -18
- package/dist/dynamicschema/DynamicSchema.unit.test.js +75 -51
- package/dist/dynamictype/DynamicType.d.ts +20 -17
- package/dist/dynamictype/DynamicType.d.ts.map +1 -1
- package/dist/dynamictype/DynamicType.js +35 -48
- package/dist/file/FakeFileStorage.d.ts +8 -8
- package/dist/file/FakeFileStorage.d.ts.map +1 -1
- package/dist/file/FakeFileStorage.js +40 -16
- package/dist/file/File.d.ts +14 -10
- package/dist/file/File.d.ts.map +1 -1
- package/dist/file/File.js +24 -31
- package/dist/file/FileStorage.abstract.test.d.ts.map +1 -1
- package/dist/file/FileStorage.abstract.test.js +41 -18
- package/dist/file/NodeFsFileStorage.d.ts +11 -9
- package/dist/file/NodeFsFileStorage.d.ts.map +1 -1
- package/dist/file/NodeFsFileStorage.integration.test.js +45 -21
- package/dist/file/NodeFsFileStorage.js +29 -37
- package/dist/http/Http.d.ts +13 -11
- package/dist/http/Http.d.ts.map +1 -1
- package/dist/http/Http.js +22 -30
- package/dist/http/Http.unit.test.js +26 -3
- package/dist/http/HttpClient.abstract.test.d.ts.map +1 -1
- package/dist/http/HttpClient.abstract.test.js +108 -104
- package/dist/http/HttpClient.d.ts +2 -2
- package/dist/http/HttpClient.d.ts.map +1 -1
- package/dist/http/HttpController.d.ts +3 -2
- package/dist/http/HttpController.d.ts.map +1 -1
- package/dist/http/HttpTypeDescriptors.d.ts +11 -0
- package/dist/http/HttpTypeDescriptors.d.ts.map +1 -0
- package/dist/http/HttpTypeDescriptors.js +59 -0
- package/dist/http/MultipartHttpRequestBody.integration.test.js +20 -31
- package/dist/http/MultipartHttpRequestBody.unit.test.js +53 -70
- package/dist/record/Record.d.ts +3 -3
- package/dist/record/Record.d.ts.map +1 -1
- package/dist/record/Record.js +30 -9
- package/dist/result/Result.d.ts +3 -3
- package/dist/result/Result.d.ts.map +1 -1
- package/dist/result/Result.js +26 -9
- package/dist/schema/JsonSchemaIntrospector.js +7 -17
- package/dist/sensitive/Sensitive.d.ts +3 -7
- package/dist/sensitive/Sensitive.d.ts.map +1 -1
- package/dist/sensitive/Sensitive.js +39 -23
- package/dist/sensitive/Sensitive.unit.test.d.ts +4 -4
- package/dist/sensitive/Sensitive.unit.test.d.ts.map +1 -1
- package/dist/sensitive/Sensitive.unit.test.js +46 -20
- package/dist/serialization/FormUrlEncodedSerialization.d.ts +2 -2
- package/dist/serialization/FormUrlEncodedSerialization.d.ts.map +1 -1
- package/dist/serialization/FormUrlEncodedSerialization.js +28 -5
- package/dist/serialization/JsonSerialization.d.ts +2 -2
- package/dist/serialization/JsonSerialization.d.ts.map +1 -1
- package/dist/serialization/JsonSerialization.js +28 -5
- package/dist/serialization/Serialization.abstract.test.d.ts.map +1 -1
- package/dist/serialization/Serialization.abstract.test.js +32 -6
- package/dist/serialization/Serialization.d.ts +2 -2
- package/dist/serialization/Serialization.d.ts.map +1 -1
- package/dist/task/Task.d.ts +19 -0
- package/dist/task/Task.d.ts.map +1 -0
- package/dist/task/Task.js +74 -0
- package/dist/task/Task.unit.test.d.ts +2 -0
- package/dist/task/Task.unit.test.d.ts.map +1 -0
- package/dist/task/Task.unit.test.js +46 -0
- package/dist/try/Try.d.ts +2 -2
- package/dist/try/Try.d.ts.map +1 -1
- package/dist/try/Try.js +32 -2
- package/dist/uuid/Uuid.d.ts +10 -11
- package/dist/uuid/Uuid.d.ts.map +1 -1
- package/dist/uuid/Uuid.js +39 -13
- package/dist/uuid/Uuid.unit.test.js +27 -4
- package/dist/zod/SchemaParser.abstract.test.d.ts.map +1 -1
- package/dist/zod/SchemaParser.abstract.test.js +31 -6
- package/dist/zod/SchemaParser.d.ts +2 -2
- package/dist/zod/SchemaParser.d.ts.map +1 -1
- package/dist/zod/ZodSchemaParser.d.ts +4 -3
- package/dist/zod/ZodSchemaParser.d.ts.map +1 -1
- package/dist/zod/ZodSchemaParser.js +28 -4
- package/dist/zod/ZodSchemaParser.unit.test.js +25 -2
- package/package.json +9 -4
- package/dist/effect/EffectExtensions.d.ts +0 -29
- package/dist/effect/EffectExtensions.d.ts.map +0 -1
- package/dist/effect/EffectExtensions.js +0 -30
- package/dist/effect/EffectExtensions.unit.test.d.ts +0 -2
- package/dist/effect/EffectExtensions.unit.test.d.ts.map +0 -1
- package/dist/effect/EffectExtensions.unit.test.js +0 -59
- package/dist/effect/Interop.d.ts +0 -53
- package/dist/effect/Interop.d.ts.map +0 -1
- package/dist/effect/Interop.js +0 -56
- package/dist/effect/Interop.unit.test.d.ts +0 -2
- package/dist/effect/Interop.unit.test.d.ts.map +0 -1
- package/dist/effect/Interop.unit.test.js +0 -134
- package/dist/effect/SchemaExtensions.d.ts +0 -11
- package/dist/effect/SchemaExtensions.d.ts.map +0 -1
- package/dist/effect/SchemaExtensions.js +0 -7
- package/dist/effect/SchemaExtensions.unit.test.d.ts +0 -2
- package/dist/effect/SchemaExtensions.unit.test.d.ts.map +0 -1
- package/dist/effect/SchemaExtensions.unit.test.js +0 -29
- package/dist/http/HttpSchemas.d.ts +0 -13
- package/dist/http/HttpSchemas.d.ts.map +0 -1
- package/dist/http/HttpSchemas.js +0 -23
- package/dist/schema/DateFromUnixTime.d.ts +0 -4
- package/dist/schema/DateFromUnixTime.d.ts.map +0 -1
- package/dist/schema/DateFromUnixTime.js +0 -10
- package/dist/schema/DateFromUnixTime.unit.test.d.ts +0 -2
- package/dist/schema/DateFromUnixTime.unit.test.d.ts.map +0 -1
- package/dist/schema/DateFromUnixTime.unit.test.js +0 -11
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as E from 'fp-ts/Either';
|
|
2
|
+
import * as O from 'fp-ts/Option';
|
|
3
|
+
import * as t from 'io-ts';
|
|
2
4
|
import { DynamicObject } from '../dynamictype/DynamicType';
|
|
3
|
-
|
|
4
|
-
export type DynamicSchema = typeof
|
|
5
|
+
declare const dynamicSchemaTypeDescriptor: t.BrandC<t.Type<DynamicObject, DynamicObject, unknown>, DynamicSchemaBrand>;
|
|
6
|
+
export type DynamicSchema = t.TypeOf<typeof dynamicSchemaTypeDescriptor>;
|
|
7
|
+
export interface DynamicSchemaBrand {
|
|
8
|
+
readonly DynamicSchema: unique symbol;
|
|
9
|
+
}
|
|
5
10
|
export interface DynamicSchemaInterface {
|
|
6
|
-
fromDynamicObject: (schema: DynamicObject, strict?:
|
|
7
|
-
validate: (schema: DynamicSchema | DynamicObject, value: DynamicObject, strict?:
|
|
8
|
-
fromValue: (value: DynamicObject, schemaUrl:
|
|
11
|
+
fromDynamicObject: (schema: DynamicObject, strict?: O.Option<boolean>) => E.Either<Error, DynamicSchema>;
|
|
12
|
+
validate: (schema: DynamicSchema | DynamicObject, value: DynamicObject, strict?: O.Option<boolean>, coerce?: boolean) => E.Either<Error, DynamicObject>;
|
|
13
|
+
fromValue: (value: DynamicObject, schemaUrl: O.Option<string>) => DynamicObject;
|
|
9
14
|
isValidJsonSchema: (schema: DynamicObject) => boolean;
|
|
10
15
|
}
|
|
11
16
|
export declare const DynamicSchema: DynamicSchemaInterface;
|
|
17
|
+
export {};
|
|
12
18
|
//# sourceMappingURL=DynamicSchema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynamicSchema.d.ts","sourceRoot":"","sources":["../../src/dynamicschema/DynamicSchema.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"DynamicSchema.d.ts","sourceRoot":"","sources":["../../src/dynamicschema/DynamicSchema.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAG3B,OAAO,EACN,aAAa,EAEb,MAAM,4BAA4B,CAAC;AA+BpC,QAAA,MAAM,2BAA2B,6EAKhC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,2BAA2B,CAAC,CAAC;AA0FzE,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,aAAa,EAAE,OAAO,MAAM,CAAC;CACtC;AAED,MAAM,WAAW,sBAAsB;IACtC,iBAAiB,EAAE,CAClB,MAAM,EAAE,aAAa,EACrB,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KACtB,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IACpC,QAAQ,EAAE,CACT,MAAM,EAAE,aAAa,GAAG,aAAa,EACrC,KAAK,EAAE,aAAa,EACpB,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,EAC1B,MAAM,CAAC,EAAE,OAAO,KACZ,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IACpC,SAAS,EAAE,CACV,KAAK,EAAE,aAAa,EACpB,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KACvB,aAAa,CAAC;IACnB,iBAAiB,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC;CACtD;AAED,eAAO,MAAM,aAAa,EAAE,sBAgD3B,CAAC"}
|
|
@@ -1,12 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.DynamicSchema =
|
|
29
|
+
exports.DynamicSchema = void 0;
|
|
7
30
|
const ajv_draft_04_1 = __importDefault(require("ajv-draft-04"));
|
|
8
31
|
const ajv_formats_1 = __importDefault(require("ajv-formats"));
|
|
9
|
-
const
|
|
32
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
33
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
34
|
+
const t = __importStar(require("io-ts"));
|
|
35
|
+
const function_1 = require("fp-ts/lib/function");
|
|
10
36
|
const deep_copy_ts_1 = require("deep-copy-ts");
|
|
11
37
|
const DynamicType_1 = require("../dynamictype/DynamicType");
|
|
12
38
|
const TypeCodec_1 = require("../codec/TypeCodec");
|
|
@@ -34,14 +60,10 @@ const isDynamicSchema = (o) => {
|
|
|
34
60
|
return false;
|
|
35
61
|
}
|
|
36
62
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
message: () => 'Not a valid JSON schema',
|
|
40
|
-
}), effect_1.Schema.brand('DynamicSchema'))
|
|
41
|
-
.annotations({ identifier: 'DynamicSchema' });
|
|
42
|
-
const dynamicSchemaTypeCodec = TypeCodec_1.TypeCodec.fromSchema(exports.dynamicSchemaSchema);
|
|
63
|
+
const dynamicSchemaTypeDescriptor = t.brand(DynamicType_1.dynamicObjectTypeDescriptor, (input) => isDynamicSchema(input), 'DynamicSchema');
|
|
64
|
+
const dynamicSchemaTypeCodec = TypeCodec_1.TypeCodec.fromDescriptor(dynamicSchemaTypeDescriptor);
|
|
43
65
|
const preprocessSchema = (schema, strict) => {
|
|
44
|
-
const hasStrict =
|
|
66
|
+
const hasStrict = O.isSome(strict);
|
|
45
67
|
delete schema.$schema;
|
|
46
68
|
if (schema.oneOf || schema.anyOf || schema.allOf) {
|
|
47
69
|
const schemas = (schema.oneOf ||
|
|
@@ -105,17 +127,18 @@ const createSchema = (value) => {
|
|
|
105
127
|
return {};
|
|
106
128
|
};
|
|
107
129
|
const createSchemaWithSchemaUrl = (schema, schemaUrl) => {
|
|
130
|
+
const hasSchemaUrl = O.isSome(schemaUrl);
|
|
108
131
|
const schemaObj = createSchema(schema);
|
|
109
|
-
schemaObj[schemaProperty] =
|
|
132
|
+
schemaObj[schemaProperty] = hasSchemaUrl ? schemaUrl.value : draft04SchemaUrl;
|
|
110
133
|
return schemaObj;
|
|
111
134
|
};
|
|
112
135
|
exports.DynamicSchema = {
|
|
113
|
-
fromDynamicObject: (schema, strict =
|
|
136
|
+
fromDynamicObject: (schema, strict = O.none) => {
|
|
114
137
|
const copiedSchema = (0, deep_copy_ts_1.deepCopy)(schema);
|
|
115
138
|
preprocessSchema(copiedSchema, strict);
|
|
116
|
-
return
|
|
139
|
+
return (0, function_1.pipe)(dynamicSchemaTypeCodec.decode(copiedSchema), E.mapLeft((e) => new Error(`Failed to create DynamicSchema: ${e}`)));
|
|
117
140
|
},
|
|
118
|
-
validate: (schema, value, strict =
|
|
141
|
+
validate: (schema, value, strict = O.none, coerce = false) => {
|
|
119
142
|
const copiedSchema = (0, deep_copy_ts_1.deepCopy)(schema);
|
|
120
143
|
preprocessSchema(copiedSchema, strict);
|
|
121
144
|
const copiedValue = (0, deep_copy_ts_1.deepCopy)(value);
|
|
@@ -125,16 +148,16 @@ exports.DynamicSchema = {
|
|
|
125
148
|
}
|
|
126
149
|
return ajv.compile(copiedSchema);
|
|
127
150
|
});
|
|
128
|
-
return
|
|
151
|
+
return (0, function_1.pipe)(validateE, E.chain((validate) => {
|
|
129
152
|
if (validate(copiedValue)) {
|
|
130
|
-
return
|
|
153
|
+
return E.right(copiedValue);
|
|
131
154
|
}
|
|
132
155
|
const errorText = ajv
|
|
133
156
|
.errorsText(validate.errors)
|
|
134
157
|
.replace(/data\//g, '');
|
|
135
|
-
return
|
|
136
|
-
});
|
|
158
|
+
return E.left(new Error(errorText));
|
|
159
|
+
}));
|
|
137
160
|
},
|
|
138
|
-
fromValue: (value, schemaUrl =
|
|
161
|
+
fromValue: (value, schemaUrl = O.none) => createSchemaWithSchemaUrl(value, schemaUrl),
|
|
139
162
|
isValidJsonSchema: (schema) => isDynamicSchema(schema),
|
|
140
163
|
};
|
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
26
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
27
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
4
28
|
const DynamicSchema_1 = require("./DynamicSchema");
|
|
5
29
|
describe('DynamicSchema', () => {
|
|
6
30
|
let validSchema;
|
|
@@ -142,15 +166,15 @@ describe('DynamicSchema', () => {
|
|
|
142
166
|
describe('fromDynamicObject', () => {
|
|
143
167
|
it('should return a Right DynamicSchema when given a valid schema object', () => {
|
|
144
168
|
const result = DynamicSchema_1.DynamicSchema.fromDynamicObject(validSchema);
|
|
145
|
-
expect(
|
|
146
|
-
if (
|
|
169
|
+
expect(E.isRight(result)).toBe(true);
|
|
170
|
+
if (E.isRight(result)) {
|
|
147
171
|
expect(result.right).toEqual(validSchema);
|
|
148
172
|
}
|
|
149
173
|
});
|
|
150
174
|
it('should return a Left Error when given an invalid schema object', () => {
|
|
151
175
|
const result = DynamicSchema_1.DynamicSchema.fromDynamicObject(invalidSchema);
|
|
152
|
-
expect(
|
|
153
|
-
if (
|
|
176
|
+
expect(E.isLeft(result)).toBe(true);
|
|
177
|
+
if (E.isLeft(result)) {
|
|
154
178
|
expect(result.left).toBeInstanceOf(Error);
|
|
155
179
|
expect(result.left.message).toContain('Failed to create DynamicSchema:');
|
|
156
180
|
}
|
|
@@ -181,8 +205,8 @@ describe('DynamicSchema', () => {
|
|
|
181
205
|
},
|
|
182
206
|
advanced: [],
|
|
183
207
|
};
|
|
184
|
-
const actualSchemaE = DynamicSchema_1.DynamicSchema.fromDynamicObject(schema,
|
|
185
|
-
expect(actualSchemaE).toEqual(
|
|
208
|
+
const actualSchemaE = DynamicSchema_1.DynamicSchema.fromDynamicObject(schema, O.none);
|
|
209
|
+
expect(actualSchemaE).toEqual(E.right(expectedSchema));
|
|
186
210
|
});
|
|
187
211
|
it('should correctly remove empty required arrays and not add additionalProperties when strict is not set', () => {
|
|
188
212
|
const schema = {
|
|
@@ -210,8 +234,8 @@ describe('DynamicSchema', () => {
|
|
|
210
234
|
},
|
|
211
235
|
advanced: [],
|
|
212
236
|
};
|
|
213
|
-
const actualSchemaE = DynamicSchema_1.DynamicSchema.fromDynamicObject(schema,
|
|
214
|
-
expect(actualSchemaE).toEqual(
|
|
237
|
+
const actualSchemaE = DynamicSchema_1.DynamicSchema.fromDynamicObject(schema, O.none);
|
|
238
|
+
expect(actualSchemaE).toEqual(E.right(expectedSchema));
|
|
215
239
|
});
|
|
216
240
|
it('should correctly keep populated required arrays and not add additionalProperties when strict is not set', () => {
|
|
217
241
|
const schema = {
|
|
@@ -240,8 +264,8 @@ describe('DynamicSchema', () => {
|
|
|
240
264
|
required: ['age', 'name'],
|
|
241
265
|
advanced: [],
|
|
242
266
|
};
|
|
243
|
-
const actualSchemaE = DynamicSchema_1.DynamicSchema.fromDynamicObject(schema,
|
|
244
|
-
expect(actualSchemaE).toEqual(
|
|
267
|
+
const actualSchemaE = DynamicSchema_1.DynamicSchema.fromDynamicObject(schema, O.none);
|
|
268
|
+
expect(actualSchemaE).toEqual(E.right(expectedSchema));
|
|
245
269
|
});
|
|
246
270
|
it('should correctly remove empty required and add additionalProperties=true to object schema when strict is set', () => {
|
|
247
271
|
const schema = {
|
|
@@ -270,8 +294,8 @@ describe('DynamicSchema', () => {
|
|
|
270
294
|
advanced: [],
|
|
271
295
|
additionalProperties: true,
|
|
272
296
|
};
|
|
273
|
-
const actualSchemaE = DynamicSchema_1.DynamicSchema.fromDynamicObject(schema,
|
|
274
|
-
expect(actualSchemaE).toEqual(
|
|
297
|
+
const actualSchemaE = DynamicSchema_1.DynamicSchema.fromDynamicObject(schema, O.some(false));
|
|
298
|
+
expect(actualSchemaE).toEqual(E.right(expectedSchema));
|
|
275
299
|
});
|
|
276
300
|
it('should correctly add additionalProperties=false to object schema', () => {
|
|
277
301
|
const schema = validSchema;
|
|
@@ -311,8 +335,8 @@ describe('DynamicSchema', () => {
|
|
|
311
335
|
advanced: [],
|
|
312
336
|
additionalProperties: false,
|
|
313
337
|
};
|
|
314
|
-
const actualSchemaE = DynamicSchema_1.DynamicSchema.fromDynamicObject(schema,
|
|
315
|
-
expect(actualSchemaE).toEqual(
|
|
338
|
+
const actualSchemaE = DynamicSchema_1.DynamicSchema.fromDynamicObject(schema, O.some(true));
|
|
339
|
+
expect(actualSchemaE).toEqual(E.right(expectedSchema));
|
|
316
340
|
});
|
|
317
341
|
it('should correctly add additionalProperties=true to complex object schema', () => {
|
|
318
342
|
const schema = {
|
|
@@ -378,15 +402,15 @@ describe('DynamicSchema', () => {
|
|
|
378
402
|
},
|
|
379
403
|
additionalProperties: true,
|
|
380
404
|
};
|
|
381
|
-
const actualSchemaE = DynamicSchema_1.DynamicSchema.fromDynamicObject(schema,
|
|
382
|
-
expect(actualSchemaE).toEqual(
|
|
405
|
+
const actualSchemaE = DynamicSchema_1.DynamicSchema.fromDynamicObject(schema, O.some(false));
|
|
406
|
+
expect(actualSchemaE).toEqual(E.right(expectedSchema));
|
|
383
407
|
});
|
|
384
408
|
it('should skip mutation if there is no object type schema', () => {
|
|
385
409
|
const schema = {
|
|
386
410
|
type: 'string',
|
|
387
411
|
};
|
|
388
|
-
const actualSchemaE = DynamicSchema_1.DynamicSchema.fromDynamicObject(schema,
|
|
389
|
-
expect(actualSchemaE).toEqual(
|
|
412
|
+
const actualSchemaE = DynamicSchema_1.DynamicSchema.fromDynamicObject(schema, O.some(true));
|
|
413
|
+
expect(actualSchemaE).toEqual(E.right(schema));
|
|
390
414
|
});
|
|
391
415
|
it('should correctly add additionalProperties=true to oneOf schemas', () => {
|
|
392
416
|
const schema = {
|
|
@@ -433,8 +457,8 @@ describe('DynamicSchema', () => {
|
|
|
433
457
|
},
|
|
434
458
|
],
|
|
435
459
|
};
|
|
436
|
-
const actualSchemaE = DynamicSchema_1.DynamicSchema.fromDynamicObject(schema,
|
|
437
|
-
expect(actualSchemaE).toEqual(
|
|
460
|
+
const actualSchemaE = DynamicSchema_1.DynamicSchema.fromDynamicObject(schema, O.some(false));
|
|
461
|
+
expect(actualSchemaE).toEqual(E.right(expectedSchema));
|
|
438
462
|
});
|
|
439
463
|
it('should correctly add additionalProperties=true to anyOf schemas', () => {
|
|
440
464
|
const schema = {
|
|
@@ -481,8 +505,8 @@ describe('DynamicSchema', () => {
|
|
|
481
505
|
},
|
|
482
506
|
],
|
|
483
507
|
};
|
|
484
|
-
const actualSchemaE = DynamicSchema_1.DynamicSchema.fromDynamicObject(schema,
|
|
485
|
-
expect(actualSchemaE).toEqual(
|
|
508
|
+
const actualSchemaE = DynamicSchema_1.DynamicSchema.fromDynamicObject(schema, O.some(false));
|
|
509
|
+
expect(actualSchemaE).toEqual(E.right(expectedSchema));
|
|
486
510
|
});
|
|
487
511
|
it('should correctly add additionalProperties=true to allOf schemas', () => {
|
|
488
512
|
const schema = {
|
|
@@ -529,67 +553,67 @@ describe('DynamicSchema', () => {
|
|
|
529
553
|
},
|
|
530
554
|
],
|
|
531
555
|
};
|
|
532
|
-
const actualSchemaE = DynamicSchema_1.DynamicSchema.fromDynamicObject(schema,
|
|
533
|
-
expect(actualSchemaE).toEqual(
|
|
556
|
+
const actualSchemaE = DynamicSchema_1.DynamicSchema.fromDynamicObject(schema, O.some(false));
|
|
557
|
+
expect(actualSchemaE).toEqual(E.right(expectedSchema));
|
|
534
558
|
});
|
|
535
559
|
});
|
|
536
560
|
describe('validate', () => {
|
|
537
561
|
it('should return a Right with the value when the value matches the schema', () => {
|
|
538
562
|
const schema = DynamicSchema_1.DynamicSchema.fromDynamicObject(validSchema);
|
|
539
|
-
if (
|
|
540
|
-
const result = DynamicSchema_1.DynamicSchema.validate(schema.right, value,
|
|
541
|
-
expect(
|
|
542
|
-
if (
|
|
563
|
+
if (E.isRight(schema)) {
|
|
564
|
+
const result = DynamicSchema_1.DynamicSchema.validate(schema.right, value, O.none);
|
|
565
|
+
expect(E.isRight(result)).toBe(true);
|
|
566
|
+
if (E.isRight(result)) {
|
|
543
567
|
expect(result.right).toEqual(value);
|
|
544
568
|
}
|
|
545
569
|
}
|
|
546
570
|
});
|
|
547
571
|
it('should return a Right with the value when strict is false and value matches the schema', () => {
|
|
548
572
|
const schema = DynamicSchema_1.DynamicSchema.fromDynamicObject(validSchema);
|
|
549
|
-
if (
|
|
550
|
-
const result = DynamicSchema_1.DynamicSchema.validate(schema.right, value,
|
|
551
|
-
expect(
|
|
552
|
-
if (
|
|
573
|
+
if (E.isRight(schema)) {
|
|
574
|
+
const result = DynamicSchema_1.DynamicSchema.validate(schema.right, value, O.some(true));
|
|
575
|
+
expect(E.isRight(result)).toBe(true);
|
|
576
|
+
if (E.isRight(result)) {
|
|
553
577
|
expect(result.right).toEqual(value);
|
|
554
578
|
}
|
|
555
579
|
}
|
|
556
580
|
});
|
|
557
581
|
it('should return a Right with non extra values when value matches the schema but has extra fields', () => {
|
|
558
582
|
const schema = DynamicSchema_1.DynamicSchema.fromDynamicObject(validSchema);
|
|
559
|
-
if (
|
|
560
|
-
const result = DynamicSchema_1.DynamicSchema.validate(schema.right, valueWithExtraFields,
|
|
561
|
-
expect(
|
|
562
|
-
if (
|
|
583
|
+
if (E.isRight(schema)) {
|
|
584
|
+
const result = DynamicSchema_1.DynamicSchema.validate(schema.right, valueWithExtraFields, O.some(true));
|
|
585
|
+
expect(E.isRight(result)).toBe(true);
|
|
586
|
+
if (E.isRight(result)) {
|
|
563
587
|
expect(result.right).toEqual(value);
|
|
564
588
|
}
|
|
565
589
|
}
|
|
566
590
|
});
|
|
567
591
|
it('should return a Right with extra values when value matches the schema but has extra fields and strict is false', () => {
|
|
568
592
|
const schema = DynamicSchema_1.DynamicSchema.fromDynamicObject(validSchema);
|
|
569
|
-
if (
|
|
570
|
-
const result = DynamicSchema_1.DynamicSchema.validate(schema.right, valueWithExtraFields,
|
|
571
|
-
expect(
|
|
572
|
-
if (
|
|
593
|
+
if (E.isRight(schema)) {
|
|
594
|
+
const result = DynamicSchema_1.DynamicSchema.validate(schema.right, valueWithExtraFields, O.some(false));
|
|
595
|
+
expect(E.isRight(result)).toBe(true);
|
|
596
|
+
if (E.isRight(result)) {
|
|
573
597
|
expect(result.right).toEqual(valueWithExtraFields);
|
|
574
598
|
}
|
|
575
599
|
}
|
|
576
600
|
});
|
|
577
601
|
it('should return a Right with when value matches the schema but has coerceable types', () => {
|
|
578
602
|
const schema = DynamicSchema_1.DynamicSchema.fromDynamicObject(validSchema);
|
|
579
|
-
if (
|
|
580
|
-
const result = DynamicSchema_1.DynamicSchema.validate(schema.right, valueWithCoerceableTypes,
|
|
581
|
-
expect(
|
|
582
|
-
if (
|
|
603
|
+
if (E.isRight(schema)) {
|
|
604
|
+
const result = DynamicSchema_1.DynamicSchema.validate(schema.right, valueWithCoerceableTypes, O.some(true), true);
|
|
605
|
+
expect(E.isRight(result)).toBe(true);
|
|
606
|
+
if (E.isRight(result)) {
|
|
583
607
|
expect(result.right).toEqual(value);
|
|
584
608
|
}
|
|
585
609
|
}
|
|
586
610
|
});
|
|
587
611
|
it('should return a Left Error when the value does not match the schema', () => {
|
|
588
612
|
const schema = DynamicSchema_1.DynamicSchema.fromDynamicObject(validSchema);
|
|
589
|
-
if (
|
|
590
|
-
const result = DynamicSchema_1.DynamicSchema.validate(schema.right, invalidValue,
|
|
591
|
-
expect(
|
|
592
|
-
if (
|
|
613
|
+
if (E.isRight(schema)) {
|
|
614
|
+
const result = DynamicSchema_1.DynamicSchema.validate(schema.right, invalidValue, O.none);
|
|
615
|
+
expect(E.isLeft(result)).toBe(true);
|
|
616
|
+
if (E.isLeft(result)) {
|
|
593
617
|
expect(result.left).toBeInstanceOf(Error);
|
|
594
618
|
}
|
|
595
619
|
}
|
|
@@ -597,12 +621,12 @@ describe('DynamicSchema', () => {
|
|
|
597
621
|
});
|
|
598
622
|
describe('fromValue', () => {
|
|
599
623
|
it('should return a Right with the schema when given a valid value object', () => {
|
|
600
|
-
const result = DynamicSchema_1.DynamicSchema.fromValue(value,
|
|
624
|
+
const result = DynamicSchema_1.DynamicSchema.fromValue(value, O.none);
|
|
601
625
|
expect(result).toEqual(validSchemaWithoutExtraFields);
|
|
602
626
|
});
|
|
603
627
|
it('should return a Right with the schema when given a valid value object and a schema url', () => {
|
|
604
628
|
const schemaUrl = 'http://json-schema.org/draft-04/schema#';
|
|
605
|
-
const result = DynamicSchema_1.DynamicSchema.fromValue(value,
|
|
629
|
+
const result = DynamicSchema_1.DynamicSchema.fromValue(value, O.some(schemaUrl));
|
|
606
630
|
expect(result.$schema).toEqual(schemaUrl);
|
|
607
631
|
});
|
|
608
632
|
});
|
|
@@ -1,33 +1,36 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as TE from 'fp-ts/TaskEither';
|
|
2
|
+
import * as E from 'fp-ts/Either';
|
|
3
|
+
import * as O from 'fp-ts/Option';
|
|
4
|
+
import * as t from 'io-ts';
|
|
2
5
|
import { Codec } from '../codec/Codec';
|
|
3
6
|
export type DynamicType = string | number | boolean | null | DynamicObject | DynamicArray;
|
|
4
7
|
export type DynamicObject = {
|
|
5
8
|
[x: string]: DynamicType;
|
|
6
9
|
};
|
|
7
10
|
export type DynamicArray = Array<DynamicType>;
|
|
8
|
-
export declare const dynamicTypeSchema: Schema.Schema<DynamicType>;
|
|
9
|
-
export declare const dynamicObjectSchema: Schema.Schema<DynamicObject>;
|
|
10
|
-
export declare const dynamicArraySchema: Schema.Schema<DynamicArray>;
|
|
11
11
|
export interface DynamicObjectInterface {
|
|
12
|
-
fromBase64String: (base64Str: string) =>
|
|
12
|
+
fromBase64String: (base64Str: string) => E.Either<Error, DynamicObject>;
|
|
13
13
|
removeNullValues: (value: DynamicObject) => DynamicObject;
|
|
14
14
|
isDynamicObject: (value: unknown) => value is DynamicObject;
|
|
15
|
-
getTypedProperty: <T>(dynamicObject: DynamicObject, name: string, codec: Codec<T>) =>
|
|
16
|
-
getObjectProperty: (dynamicObject: DynamicObject, name: string) =>
|
|
17
|
-
getStringProperty: (dynamicObject: DynamicObject, name: string) =>
|
|
18
|
-
getNumberProperty: (dynamicObject: DynamicObject, name: string) =>
|
|
19
|
-
getBooleanProperty: (dynamicObject: DynamicObject, name: string) =>
|
|
15
|
+
getTypedProperty: <T>(dynamicObject: DynamicObject, name: string, codec: Codec<T>) => O.Option<T>;
|
|
16
|
+
getObjectProperty: (dynamicObject: DynamicObject, name: string) => O.Option<DynamicObject>;
|
|
17
|
+
getStringProperty: (dynamicObject: DynamicObject, name: string) => O.Option<string>;
|
|
18
|
+
getNumberProperty: (dynamicObject: DynamicObject, name: string) => O.Option<number>;
|
|
19
|
+
getBooleanProperty: (dynamicObject: DynamicObject, name: string) => O.Option<boolean>;
|
|
20
20
|
}
|
|
21
21
|
export declare const DynamicObject: DynamicObjectInterface;
|
|
22
22
|
export interface DynamicTypeInterface {
|
|
23
|
-
readFromFile: (path: string) =>
|
|
24
|
-
writeToFile: (path: string, value: DynamicType) =>
|
|
25
|
-
writeToFileAsync: (path: string, value: DynamicType) =>
|
|
26
|
-
safeCast: <T>(dynamicType: DynamicType, codec: Codec<T>) =>
|
|
27
|
-
getStringProperty: (dynamicObject: DynamicObject, name: string) =>
|
|
28
|
-
getNumberProperty: (dynamicObject: DynamicObject, name: string) =>
|
|
29
|
-
getBooleanProperty: (dynamicObject: DynamicObject, name: string) =>
|
|
23
|
+
readFromFile: (path: string) => E.Either<Error, DynamicType>;
|
|
24
|
+
writeToFile: (path: string, value: DynamicType) => E.Either<Error, undefined>;
|
|
25
|
+
writeToFileAsync: (path: string, value: DynamicType) => TE.TaskEither<Error, undefined>;
|
|
26
|
+
safeCast: <T>(dynamicType: DynamicType, codec: Codec<T>) => E.Either<Error, T>;
|
|
27
|
+
getStringProperty: (dynamicObject: DynamicObject, name: string) => O.Option<string>;
|
|
28
|
+
getNumberProperty: (dynamicObject: DynamicObject, name: string) => O.Option<number>;
|
|
29
|
+
getBooleanProperty: (dynamicObject: DynamicObject, name: string) => O.Option<boolean>;
|
|
30
30
|
}
|
|
31
31
|
export declare const DynamicType: DynamicTypeInterface;
|
|
32
|
+
export declare const dynamicTypeDescriptor: t.Type<DynamicType>;
|
|
33
|
+
export declare const dynamicObjectTypeDescriptor: t.Type<DynamicObject>;
|
|
34
|
+
export declare const dynamicArrayTypeDescriptor: t.Type<DynamicArray>;
|
|
32
35
|
export declare const castUndefinedPropertyToNull: (obj: Record<string, any>) => DynamicType;
|
|
33
36
|
//# sourceMappingURL=DynamicType.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynamicType.d.ts","sourceRoot":"","sources":["../../src/dynamictype/DynamicType.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DynamicType.d.ts","sourceRoot":"","sources":["../../src/dynamictype/DynamicType.ts"],"names":[],"mappings":"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"}
|
|
@@ -15,71 +15,58 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) ||
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
35
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.castUndefinedPropertyToNull = exports.
|
|
26
|
+
exports.castUndefinedPropertyToNull = exports.dynamicArrayTypeDescriptor = exports.dynamicObjectTypeDescriptor = exports.dynamicTypeDescriptor = exports.DynamicType = exports.DynamicObject = void 0;
|
|
27
|
+
const TE = __importStar(require("fp-ts/TaskEither"));
|
|
37
28
|
const fs = __importStar(require("fs"));
|
|
38
29
|
const fse = __importStar(require("fs-extra"));
|
|
39
|
-
const
|
|
30
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
31
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
32
|
+
const function_1 = require("fp-ts/function");
|
|
33
|
+
const t = __importStar(require("io-ts"));
|
|
40
34
|
const Base64_1 = require("../base64/Base64");
|
|
41
35
|
const JsonSerialization_1 = require("../serialization/JsonSerialization");
|
|
42
36
|
const Try_1 = require("../try/Try");
|
|
43
37
|
const RemoveNullValuesCodec_1 = require("../codec/RemoveNullValuesCodec");
|
|
44
38
|
const TypeCodec_1 = require("../codec/TypeCodec");
|
|
45
|
-
const Error_1 = require("../error/Error");
|
|
46
|
-
exports.dynamicTypeSchema = effect_1.Schema.Union(effect_1.Schema.String, effect_1.Schema.Number, effect_1.Schema.Boolean, effect_1.Schema.Null, effect_1.Schema.suspend(() => exports.dynamicObjectSchema), effect_1.Schema.suspend(() => exports.dynamicArraySchema)).annotations({ identifier: 'DynamicType' });
|
|
47
|
-
exports.dynamicObjectSchema = effect_1.Schema.mutable(effect_1.Schema.Record({
|
|
48
|
-
key: effect_1.Schema.String,
|
|
49
|
-
value: effect_1.Schema.suspend(() => exports.dynamicTypeSchema),
|
|
50
|
-
})).annotations({ identifier: 'DynamicObject' });
|
|
51
|
-
exports.dynamicArraySchema = effect_1.Schema.mutable(effect_1.Schema.Array(effect_1.Schema.suspend(() => exports.dynamicTypeSchema))).annotations({ identifier: 'DynamicArray' });
|
|
52
39
|
const serializer = new JsonSerialization_1.JsonSerialization();
|
|
53
40
|
const testRemoveNullValuesCodec = RemoveNullValuesCodec_1.RemoveNullValuesCodec.instance;
|
|
54
|
-
const isDynamicObject = effect_1.Schema.is(exports.dynamicObjectSchema);
|
|
55
|
-
const propertyOfType = (typeName) => (dynamicObject, name) => {
|
|
56
|
-
const property = dynamicObject[name];
|
|
57
|
-
return typeof property === typeName
|
|
58
|
-
? effect_1.Option.some(property)
|
|
59
|
-
: effect_1.Option.none();
|
|
60
|
-
};
|
|
61
41
|
exports.DynamicObject = {
|
|
62
|
-
fromBase64String: (base64Str) =>
|
|
42
|
+
fromBase64String: (base64Str) => (0, function_1.pipe)(Base64_1.Base64.fromBase64String(base64Str), E.map((base64) => Base64_1.Base64.decodeBinary(base64)), E.chain((decoded) => serializer.deserialize(decoded)), E.map((decoded) => decoded)),
|
|
63
43
|
removeNullValues: (value) => testRemoveNullValuesCodec.encode(value),
|
|
64
|
-
isDynamicObject: (value) =>
|
|
65
|
-
getTypedProperty: (dynamicObject, name, codec) =>
|
|
66
|
-
getObjectProperty: (dynamicObject, name) => exports.DynamicObject.getTypedProperty(dynamicObject, name, TypeCodec_1.TypeCodec.
|
|
67
|
-
getStringProperty:
|
|
68
|
-
getNumberProperty:
|
|
69
|
-
getBooleanProperty:
|
|
44
|
+
isDynamicObject: (value) => exports.dynamicObjectTypeDescriptor.is(value),
|
|
45
|
+
getTypedProperty: (dynamicObject, name, codec) => (0, function_1.pipe)((0, function_1.pipe)(O.fromNullable(dynamicObject[name]), O.chain((property) => O.fromEither(exports.DynamicType.safeCast(property, codec))))),
|
|
46
|
+
getObjectProperty: (dynamicObject, name) => exports.DynamicObject.getTypedProperty(dynamicObject, name, TypeCodec_1.TypeCodec.fromDescriptor(exports.dynamicObjectTypeDescriptor)),
|
|
47
|
+
getStringProperty: (dynamicObject, name) => (0, function_1.pipe)(O.fromNullable(dynamicObject[name]), O.chain((property) => typeof property === 'string' ? O.some(property) : O.none)),
|
|
48
|
+
getNumberProperty: (dynamicObject, name) => (0, function_1.pipe)(O.fromNullable(dynamicObject[name]), O.chain((property) => typeof property === 'number' ? O.some(property) : O.none)),
|
|
49
|
+
getBooleanProperty: (dynamicObject, name) => (0, function_1.pipe)(O.fromNullable(dynamicObject[name]), O.chain((property) => typeof property === 'boolean' ? O.some(property) : O.none)),
|
|
70
50
|
};
|
|
71
51
|
exports.DynamicType = {
|
|
72
52
|
readFromFile: (path) => (0, Try_1.tryToEither)(() => JSON.parse(fs.readFileSync(path, 'utf8'))),
|
|
73
|
-
writeToFile: (path, value) =>
|
|
74
|
-
writeToFileAsync: (path, value) =>
|
|
75
|
-
try: () => fse.writeFile(path, JSON.stringify(value)),
|
|
76
|
-
catch: Error_1.castError,
|
|
77
|
-
}), () => undefined),
|
|
53
|
+
writeToFile: (path, value) => (0, function_1.pipe)((0, Try_1.tryToEither)(() => fs.writeFileSync(path, JSON.stringify(value))), E.map(() => undefined)),
|
|
54
|
+
writeToFileAsync: (path, value) => (0, function_1.pipe)(TE.tryCatch(() => fse.writeFile(path, JSON.stringify(value)), (err) => new Error(err.message)), TE.map(() => undefined)),
|
|
78
55
|
safeCast: (dynamicType, codec) => codec.decode(dynamicType),
|
|
79
|
-
getStringProperty:
|
|
80
|
-
getNumberProperty:
|
|
81
|
-
getBooleanProperty:
|
|
56
|
+
getStringProperty: (dynamicObject, name) => (0, function_1.pipe)(O.fromNullable(dynamicObject[name]), O.chain((property) => typeof property === 'string' ? O.some(property) : O.none)),
|
|
57
|
+
getNumberProperty: (dynamicObject, name) => (0, function_1.pipe)(O.fromNullable(dynamicObject[name]), O.chain((property) => typeof property === 'number' ? O.some(property) : O.none)),
|
|
58
|
+
getBooleanProperty: (dynamicObject, name) => (0, function_1.pipe)(O.fromNullable(dynamicObject[name]), O.chain((property) => typeof property === 'boolean' ? O.some(property) : O.none)),
|
|
82
59
|
};
|
|
60
|
+
exports.dynamicTypeDescriptor = t.recursion('DynamicType', () => t.union([
|
|
61
|
+
t.string,
|
|
62
|
+
t.number,
|
|
63
|
+
t.boolean,
|
|
64
|
+
t.null,
|
|
65
|
+
exports.dynamicObjectTypeDescriptor,
|
|
66
|
+
exports.dynamicArrayTypeDescriptor,
|
|
67
|
+
]));
|
|
68
|
+
exports.dynamicObjectTypeDescriptor = t.recursion('DynamicObject', () => t.record(t.string, exports.dynamicTypeDescriptor));
|
|
69
|
+
exports.dynamicArrayTypeDescriptor = t.recursion('DynamicArray', () => t.array(exports.dynamicTypeDescriptor));
|
|
83
70
|
const castUndefinedPropertyToNull = (obj) => {
|
|
84
71
|
if (obj === undefined) {
|
|
85
72
|
return null;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as TE from 'fp-ts/TaskEither';
|
|
2
2
|
import { File, FileStorage, SharedUrl } from './File';
|
|
3
3
|
export declare class FakeFileStorage implements FileStorage {
|
|
4
4
|
files: Map<string, File>;
|
|
5
5
|
constructor();
|
|
6
|
-
write(file: File):
|
|
7
|
-
read(fileName: string):
|
|
8
|
-
delete(fileName: string):
|
|
9
|
-
getSharedUrl(key: string):
|
|
10
|
-
getSize(key: string):
|
|
11
|
-
createDirectory(key: string):
|
|
12
|
-
deleteDirectory(key: string):
|
|
6
|
+
write(file: File): TE.TaskEither<Error, File>;
|
|
7
|
+
read(fileName: string): TE.TaskEither<Error, File>;
|
|
8
|
+
delete(fileName: string): TE.TaskEither<Error, undefined>;
|
|
9
|
+
getSharedUrl(key: string): TE.TaskEither<Error, SharedUrl>;
|
|
10
|
+
getSize(key: string): TE.TaskEither<Error, number>;
|
|
11
|
+
createDirectory(key: string): TE.TaskEither<Error, undefined>;
|
|
12
|
+
deleteDirectory(key: string): TE.TaskEither<Error, undefined>;
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=FakeFileStorage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FakeFileStorage.d.ts","sourceRoot":"","sources":["../../src/file/FakeFileStorage.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"FakeFileStorage.d.ts","sourceRoot":"","sources":["../../src/file/FakeFileStorage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAIvC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEtD,qBAAa,eAAgB,YAAW,WAAW;IAClD,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;;IAMzB,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC;IAY7C,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC;IAkBlD,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;IAYzD,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;IAI1D,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC;IAUlD,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;IAoB7D,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;CAW7D"}
|