@trayio/tray-openapi 2.9.0 → 2.10.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.
Files changed (39) hide show
  1. package/dist/OpenApiCodecs.d.ts +3 -1
  2. package/dist/OpenApiCodecs.d.ts.map +1 -1
  3. package/dist/OpenApiCodecs.js +3 -1
  4. package/dist/OpenApiSchemaImporter.d.ts +1 -0
  5. package/dist/OpenApiSchemaImporter.d.ts.map +1 -1
  6. package/dist/OpenApiSchemaImporter.js +25 -15
  7. package/dist/OpenApiTypeDescriptors.d.ts +32 -20
  8. package/dist/OpenApiTypeDescriptors.d.ts.map +1 -1
  9. package/dist/OpenApiTypeDescriptors.js +59 -36
  10. package/dist/file-generators/GenerateHandler.d.ts +4 -4
  11. package/dist/file-generators/GenerateHandler.d.ts.map +1 -1
  12. package/dist/file-generators/GenerateHandler.js +43 -46
  13. package/dist/file-generators/GenerateHandler.test.js +194 -38
  14. package/dist/file-generators/GenerateHandlerTest.d.ts +3 -3
  15. package/dist/file-generators/GenerateHandlerTest.d.ts.map +1 -1
  16. package/dist/file-generators/GenerateHandlerTest.js +33 -21
  17. package/dist/file-generators/GenerateHandlerTest.test.js +313 -61
  18. package/dist/file-generators/GenerateOperationJson.test.js +2 -1
  19. package/dist/file-generators/types/GenerateInputSchema.d.ts +2 -3
  20. package/dist/file-generators/types/GenerateInputSchema.d.ts.map +1 -1
  21. package/dist/file-generators/types/GenerateInputSchema.js +63 -28
  22. package/dist/file-generators/types/GenerateInputSchema.test.js +72 -104
  23. package/dist/file-generators/types/GenerateInputType.test.d.ts +2 -0
  24. package/dist/file-generators/types/GenerateInputType.test.d.ts.map +1 -0
  25. package/dist/file-generators/types/GenerateInputType.test.js +400 -0
  26. package/dist/file-generators/types/GenerateInputTypes.d.ts +2 -2
  27. package/dist/file-generators/types/GenerateInputTypes.d.ts.map +1 -1
  28. package/dist/file-generators/types/GenerateInputTypes.js +10 -8
  29. package/dist/file-generators/types/GenerateOutput.d.ts +4 -5
  30. package/dist/file-generators/types/GenerateOutput.d.ts.map +1 -1
  31. package/dist/file-generators/types/GenerateOutput.js +31 -5
  32. package/dist/file-generators/types/GenerateOutput.test.js +94 -88
  33. package/package.json +1 -1
  34. package/dist/ResolveOptionValues.d.ts +0 -3
  35. package/dist/ResolveOptionValues.d.ts.map +0 -1
  36. package/dist/ResolveOptionValues.js +0 -43
  37. package/dist/ResolveOptionValues.test.d.ts +0 -2
  38. package/dist/ResolveOptionValues.test.d.ts.map +0 -1
  39. package/dist/ResolveOptionValues.test.js +0 -91
@@ -25,15 +25,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.generateInputTypes = void 0;
27
27
  const json_schema_to_typescript_1 = require("json-schema-to-typescript");
28
- const TaskEither_1 = require("fp-ts/TaskEither");
29
- const E = __importStar(require("fp-ts/Either"));
28
+ const TE = __importStar(require("fp-ts/TaskEither"));
29
+ const CompositeCodec_1 = require("@trayio/commons/codec/CompositeCodec");
30
+ const RemoveNullValuesCodec_1 = require("@trayio/commons/codec/RemoveNullValuesCodec");
30
31
  const JsonSchemaToTypescriptOptions_1 = require("./JsonSchemaToTypescriptOptions");
31
- const ResolveOptionValues_1 = require("../../ResolveOptionValues");
32
+ const OpenApiTypeDescriptors_1 = require("../../OpenApiTypeDescriptors");
33
+ const encodeInputSchema = (inputSchema) => {
34
+ const codecWithNullValueRemoval = CompositeCodec_1.CompositeCodec.fromCodecs(OpenApiTypeDescriptors_1.schemaObjectTypeCodec, RemoveNullValuesCodec_1.RemoveNullValuesCodec.instance);
35
+ return codecWithNullValueRemoval.encode(inputSchema);
36
+ };
32
37
  const generateInputTypes = (operationNameCamelCase, parameters) => {
33
- const resolver = (0, ResolveOptionValues_1.resolveOptionValues)(parameters);
34
- const resolvedParameters = E.getOrElse((error) => {
35
- throw new Error(`${error}`);
36
- })(resolver);
37
- return (0, TaskEither_1.tryCatch)(() => (0, json_schema_to_typescript_1.compile)(resolvedParameters, `${operationNameCamelCase}Input`, JsonSchemaToTypescriptOptions_1.JsonSchemaToTypescriptOptions), (reason) => new Error(`${reason}`));
38
+ const resolvedInputSchema = encodeInputSchema(parameters);
39
+ return TE.tryCatch(() => (0, json_schema_to_typescript_1.compile)(resolvedInputSchema, `${operationNameCamelCase}Input`, JsonSchemaToTypescriptOptions_1.JsonSchemaToTypescriptOptions), (reason) => new Error(`${reason}`));
38
40
  };
39
41
  exports.generateInputTypes = generateInputTypes;
@@ -1,9 +1,8 @@
1
- import { JSONSchema4 } from 'json-schema';
2
1
  import * as TE from 'fp-ts/TaskEither';
3
2
  import * as E from 'fp-ts/Either';
4
3
  import * as O from 'fp-ts/Option';
5
- import { Responses, Response, MediaType } from '../../OpenApiTypeDescriptors';
6
- export declare const getApplicationJsonMediaType: (successResponse: Response) => E.Either<Error, MediaType>;
7
- export declare const generateOutputSchema: (responses: O.Option<Responses>) => TE.TaskEither<Error, JSONSchema4>;
8
- export declare const generateOutputTypes: (operationNameCamelCase: string, outputSchema: JSONSchema4) => TE.TaskEither<Error, string>;
4
+ import { Responses, MediaTypeObject, SchemaObject } from '../../OpenApiTypeDescriptors';
5
+ export declare const getApplicationJsonMediaType: (content: Record<string, MediaTypeObject>) => E.Either<Error, MediaTypeObject>;
6
+ export declare const generateOutputSchema: (responses: O.Option<Responses>) => TE.TaskEither<Error, SchemaObject>;
7
+ export declare const generateOutputTypes: (operationNameCamelCase: string, outputSchema: SchemaObject) => TE.TaskEither<Error, string>;
9
8
  //# sourceMappingURL=GenerateOutput.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GenerateOutput.d.ts","sourceRoot":"","sources":["../../../src/file-generators/types/GenerateOutput.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAGlC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAsB9E,eAAO,MAAM,2BAA2B,oBACtB,QAAQ,KACvB,EAAE,MAAM,CAAC,KAAK,EAAE,SAAS,CAgB1B,CAAC;AAEH,eAAO,MAAM,oBAAoB,cACrB,EAAE,MAAM,CAAC,SAAS,CAAC,KAC5B,GAAG,UAAU,CAAC,KAAK,EAAE,WAAW,CAcjC,CAAC;AAEH,eAAO,MAAM,mBAAmB,2BACP,MAAM,gBAChB,WAAW,KACvB,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,CAS5B,CAAC"}
1
+ {"version":3,"file":"GenerateOutput.d.ts","sourceRoot":"","sources":["../../../src/file-generators/types/GenerateOutput.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAKlC,OAAO,EACN,SAAS,EAET,eAAe,EACf,YAAY,EAEZ,MAAM,8BAA8B,CAAC;AAuCtC,eAAO,MAAM,2BAA2B,YAC9B,OAAO,MAAM,EAAE,eAAe,CAAC,KACtC,EAAE,MAAM,CAAC,KAAK,EAAE,eAAe,CAWjC,CAAC;AAEF,eAAO,MAAM,oBAAoB,cACrB,EAAE,MAAM,CAAC,SAAS,CAAC,KAC5B,GAAG,UAAU,CAAC,KAAK,EAAE,YAAY,CAelC,CAAC;AAWH,eAAO,MAAM,mBAAmB,2BACP,MAAM,gBAChB,YAAY,KACxB,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,CAe7B,CAAC"}
@@ -29,8 +29,10 @@ const TE = __importStar(require("fp-ts/TaskEither"));
29
29
  const E = __importStar(require("fp-ts/Either"));
30
30
  const O = __importStar(require("fp-ts/Option"));
31
31
  const function_1 = require("fp-ts/function");
32
+ const CompositeCodec_1 = require("@trayio/commons/codec/CompositeCodec");
33
+ const RemoveNullValuesCodec_1 = require("@trayio/commons/codec/RemoveNullValuesCodec");
32
34
  const JsonSchemaToTypescriptOptions_1 = require("./JsonSchemaToTypescriptOptions");
33
- const ResolveOptionValues_1 = require("../../ResolveOptionValues");
35
+ const OpenApiTypeDescriptors_1 = require("../../OpenApiTypeDescriptors");
34
36
  const get2XXResponse = (responses) => O.fold(() => TE.left(new Error('No responses found')), (someResponses) => {
35
37
  const statusCode2XX = Object.keys(someResponses).find((statusCode) => /^2\d{2}$/.test(statusCode));
36
38
  if (statusCode2XX) {
@@ -39,16 +41,40 @@ const get2XXResponse = (responses) => O.fold(() => TE.left(new Error('No respons
39
41
  const responseCodes = Object.keys(someResponses);
40
42
  return TE.left(new Error(`Unsupported success response code: ${responseCodes}`));
41
43
  })(responses);
42
- const getApplicationJsonMediaType = (successResponse) => (0, function_1.pipe)(O.fold(() => E.left(new Error('No success response content found')), (content) => E.right(content))(successResponse.content), E.chain((content) => {
44
+ const blankOutputSchema = () => ({
45
+ type: O.none,
46
+ properties: O.none,
47
+ required: O.none,
48
+ additionalProperties: O.some(false),
49
+ allOf: O.none,
50
+ anyOf: O.none,
51
+ oneOf: O.none,
52
+ not: O.none,
53
+ in: O.none,
54
+ });
55
+ const getContent = (response) => O.fold(() => ({ 'application/json': { schema: O.some(blankOutputSchema()) } }), (content) => content)(response.content);
56
+ const getApplicationJsonMediaType = (content) => {
57
+ if (!Object.keys(content).length)
58
+ return E.right({ schema: O.none });
43
59
  const mediaTypeApplicationJson = Object.keys(content).find((mediaType) => /^application\/.*json.*$/.test(mediaType));
44
60
  if (mediaTypeApplicationJson) {
45
61
  return E.right(content[mediaTypeApplicationJson]);
46
62
  }
47
63
  const mediaTypes = Object.keys(content);
48
64
  return E.left(new Error(`Unsupported media type: ${mediaTypes}`));
49
- }));
65
+ };
50
66
  exports.getApplicationJsonMediaType = getApplicationJsonMediaType;
51
- const generateOutputSchema = (responses) => (0, function_1.pipe)(get2XXResponse(responses), TE.chain((successResponse) => TE.fromEither((0, exports.getApplicationJsonMediaType)(successResponse))), TE.chain((applicationJson) => TE.fromEither((0, ResolveOptionValues_1.resolveOptionValues)(applicationJson.schema))));
67
+ const generateOutputSchema = (responses) => (0, function_1.pipe)(get2XXResponse(responses), TE.chain((successResponse) => TE.fromEither((0, exports.getApplicationJsonMediaType)(getContent(successResponse)))), TE.map((mediaType) => O.fold(() => blankOutputSchema(), (schema) => schema)(mediaType.schema)), TE.mapLeft((error) => new Error(`Failed to generate output schema: ${error}`)));
52
68
  exports.generateOutputSchema = generateOutputSchema;
53
- const generateOutputTypes = (operationNameCamelCase, outputSchema) => TE.tryCatch(() => (0, json_schema_to_typescript_1.compile)(outputSchema, `${operationNameCamelCase}Output`, JsonSchemaToTypescriptOptions_1.JsonSchemaToTypescriptOptions), (error) => new Error(`Failed to generate output types: ${error}`));
69
+ const encodeOutputSchema = (outputSchema) => {
70
+ const codecWithNullValueRemoval = CompositeCodec_1.CompositeCodec.fromCodecs(OpenApiTypeDescriptors_1.schemaObjectTypeCodec, RemoveNullValuesCodec_1.RemoveNullValuesCodec.instance);
71
+ return codecWithNullValueRemoval.encode(outputSchema);
72
+ };
73
+ const generateOutputTypes = (operationNameCamelCase, outputSchema) => {
74
+ const resolvedOutputSchema = encodeOutputSchema(outputSchema);
75
+ return TE.tryCatch(() => (0, json_schema_to_typescript_1.compile)(resolvedOutputSchema, `${operationNameCamelCase}Output`, JsonSchemaToTypescriptOptions_1.JsonSchemaToTypescriptOptions), (error) => {
76
+ console.log(JSON.stringify(resolvedOutputSchema));
77
+ return new Error(`Failed to generate output types: ${error}`);
78
+ });
79
+ };
54
80
  exports.generateOutputTypes = generateOutputTypes;
@@ -54,25 +54,62 @@ describe('Generate output: ', () => {
54
54
  description: 'A post was created',
55
55
  content: O.some({
56
56
  'application/json': {
57
- schema: {
58
- type: 'object',
59
- required: ['id', 'userId', 'title', 'body'],
60
- properties: {
57
+ schema: O.some({
58
+ type: O.some('object'),
59
+ required: O.some(['id', 'userId', 'title', 'body']),
60
+ properties: O.some({
61
61
  id: {
62
- type: 'integer',
62
+ type: O.some('integer'),
63
+ properties: O.none,
64
+ required: O.none,
65
+ additionalProperties: O.some(false),
66
+ allOf: O.none,
67
+ anyOf: O.none,
68
+ oneOf: O.none,
69
+ not: O.none,
70
+ in: O.none,
63
71
  },
64
72
  userId: {
65
- type: 'integer',
73
+ type: O.some('integer'),
74
+ properties: O.none,
75
+ required: O.none,
76
+ additionalProperties: O.some(false),
77
+ allOf: O.none,
78
+ anyOf: O.none,
79
+ oneOf: O.none,
80
+ not: O.none,
81
+ in: O.none,
66
82
  },
67
83
  title: {
68
- type: 'string',
84
+ type: O.some('string'),
85
+ properties: O.none,
86
+ required: O.none,
87
+ additionalProperties: O.some(false),
88
+ allOf: O.none,
89
+ anyOf: O.none,
90
+ oneOf: O.none,
91
+ not: O.none,
92
+ in: O.none,
69
93
  },
70
94
  body: {
71
- type: 'string',
95
+ type: O.some('string'),
96
+ properties: O.none,
97
+ required: O.none,
98
+ additionalProperties: O.some(false),
99
+ allOf: O.none,
100
+ anyOf: O.none,
101
+ oneOf: O.none,
102
+ not: O.none,
103
+ in: O.none,
72
104
  },
73
- },
105
+ }),
74
106
  additionalProperties: O.some(false),
75
- },
107
+ allOf: O.none,
108
+ anyOf: O.none,
109
+ oneOf: O.none,
110
+ not: O.none,
111
+ in: O.none,
112
+ }),
76
113
  },
77
114
  }),
78
115
  },
@@ -93,25 +130,62 @@ describe('Generate output: ', () => {
93
130
  description: 'A post was created',
94
131
  content: O.some({
95
132
  'application/json': {
96
- schema: {
97
- type: 'object',
98
- required: ['id', 'userId', 'title', 'body'],
99
- properties: {
133
+ schema: O.some({
134
+ type: O.some('object'),
135
+ required: O.some(['id', 'userId', 'title', 'body']),
136
+ properties: O.some({
100
137
  id: {
101
- type: 'integer',
138
+ type: O.some('integer'),
139
+ properties: O.none,
140
+ required: O.none,
141
+ additionalProperties: O.some(false),
142
+ allOf: O.none,
143
+ anyOf: O.none,
144
+ oneOf: O.none,
145
+ not: O.none,
146
+ in: O.none,
102
147
  },
103
148
  userId: {
104
- type: 'integer',
149
+ type: O.some('integer'),
150
+ properties: O.none,
151
+ required: O.none,
152
+ additionalProperties: O.some(false),
153
+ allOf: O.none,
154
+ anyOf: O.none,
155
+ oneOf: O.none,
156
+ not: O.none,
157
+ in: O.none,
105
158
  },
106
159
  title: {
107
- type: 'string',
160
+ type: O.some('string'),
161
+ properties: O.none,
162
+ required: O.none,
163
+ additionalProperties: O.some(false),
164
+ allOf: O.none,
165
+ anyOf: O.none,
166
+ oneOf: O.none,
167
+ not: O.none,
168
+ in: O.none,
108
169
  },
109
170
  body: {
110
- type: 'string',
171
+ type: O.some('string'),
172
+ properties: O.none,
173
+ required: O.none,
174
+ additionalProperties: O.some(false),
175
+ allOf: O.none,
176
+ anyOf: O.none,
177
+ oneOf: O.none,
178
+ not: O.none,
179
+ in: O.none,
111
180
  },
112
- },
181
+ }),
113
182
  additionalProperties: O.some(false),
114
- },
183
+ allOf: O.none,
184
+ anyOf: O.none,
185
+ oneOf: O.none,
186
+ not: O.none,
187
+ in: O.none,
188
+ }),
115
189
  },
116
190
  }),
117
191
  },
@@ -126,72 +200,4 @@ describe('Generate output: ', () => {
126
200
  `;
127
201
  expect(generatedOutputFileContents).toEqual(expectedOutputFileContents);
128
202
  }));
129
- it('it should extract different json media types: application/vnd.tableau.analyticsextensions.v1.ServerSettings+json', () => __awaiter(void 0, void 0, void 0, function* () {
130
- const response = {
131
- description: 'A post was created',
132
- content: O.some({
133
- 'application/vnd.tableau.analyticsextensions.v1.ServerSettings+json': {
134
- schema: {
135
- type: 'object',
136
- properties: {
137
- id: {
138
- type: 'integer',
139
- },
140
- },
141
- additionalProperties: O.some(false),
142
- },
143
- },
144
- }),
145
- };
146
- const applicationJson = (0, GenerateOutput_1.getApplicationJsonMediaType)(response);
147
- const actualApplicationJson = E.getOrElse((error) => {
148
- throw new Error('Should have been right');
149
- })(applicationJson);
150
- const expectedApplicationJson = {
151
- schema: {
152
- type: 'object',
153
- properties: {
154
- id: {
155
- type: 'integer',
156
- },
157
- },
158
- additionalProperties: O.some(false),
159
- },
160
- };
161
- expect(actualApplicationJson).toEqual(expectedApplicationJson);
162
- }));
163
- it('it should extract different json media types: application/json; charset=utf-8', () => __awaiter(void 0, void 0, void 0, function* () {
164
- const response = {
165
- description: 'A post was created',
166
- content: O.some({
167
- 'application/json; charset=utf-8': {
168
- schema: {
169
- type: 'object',
170
- properties: {
171
- id: {
172
- type: 'integer',
173
- },
174
- },
175
- additionalProperties: O.some(false),
176
- },
177
- },
178
- }),
179
- };
180
- const applicationJson = (0, GenerateOutput_1.getApplicationJsonMediaType)(response);
181
- const actualApplicationJson = E.getOrElse((error) => {
182
- throw new Error('Should have been right');
183
- })(applicationJson);
184
- const expectedApplicationJson = {
185
- schema: {
186
- type: 'object',
187
- properties: {
188
- id: {
189
- type: 'integer',
190
- },
191
- },
192
- additionalProperties: O.some(false),
193
- },
194
- };
195
- expect(actualApplicationJson).toEqual(expectedApplicationJson);
196
- }));
197
203
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayio/tray-openapi",
3
- "version": "2.9.0",
3
+ "version": "2.10.0",
4
4
  "description": "Creating CDK Projects from OpenAPI 3.0 Schemas",
5
5
  "exports": {
6
6
  "./*": "./dist/*.js"
@@ -1,3 +0,0 @@
1
- import * as E from 'fp-ts/Either';
2
- export declare const resolveOptionValues: (value: unknown) => E.Either<Error, unknown>;
3
- //# sourceMappingURL=ResolveOptionValues.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ResolveOptionValues.d.ts","sourceRoot":"","sources":["../src/ResolveOptionValues.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,eAAO,MAAM,mBAAmB,UAAW,OAAO,KAAG,EAAE,MAAM,CAAC,KAAK,EAAE,OAAO,CAC/B,CAAC"}
@@ -1,43 +0,0 @@
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
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.resolveOptionValues = void 0;
27
- const Option_1 = require("fp-ts/lib/Option");
28
- const O = __importStar(require("fp-ts/Option"));
29
- const E = __importStar(require("fp-ts/Either"));
30
- const resolveOptionValues = (value) => E.right(resolveOptionValuesIfPresent(value));
31
- exports.resolveOptionValues = resolveOptionValues;
32
- const isObject = (value) => typeof value === 'object' && !Array.isArray(value) && value !== null;
33
- const isOption = (value) => (0, Option_1.isSome)(value) || (0, Option_1.isNone)(value);
34
- const resolveOptionValuesIfPresent = (value) => {
35
- if (isOption(value)) {
36
- return O.fold(() => undefined, (someValue) => someValue)(value);
37
- }
38
- if (isObject(value)) {
39
- return resolveOptionFromObjectIfPresent(value);
40
- }
41
- return value;
42
- };
43
- const resolveOptionFromObjectIfPresent = (value) => Object.entries(value).reduce((acc, [key, propertyValue]) => (Object.assign(Object.assign({}, acc), { [key]: resolveOptionValuesIfPresent(propertyValue) })), {});
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=ResolveOptionValues.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ResolveOptionValues.test.d.ts","sourceRoot":"","sources":["../src/ResolveOptionValues.test.ts"],"names":[],"mappings":""}
@@ -1,91 +0,0 @@
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
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const O = __importStar(require("fp-ts/Option"));
27
- const E = __importStar(require("fp-ts/Either"));
28
- const ResolveOptionValues_1 = require("./ResolveOptionValues");
29
- describe('ResolveOptionValues', () => {
30
- it('it should resolve some options to their underlying values', () => {
31
- const given = O.some('some value');
32
- const resolvedOptions = (0, ResolveOptionValues_1.resolveOptionValues)(given);
33
- const actual = E.getOrElse((error) => {
34
- throw new Error('Should have been right');
35
- })(resolvedOptions);
36
- const expected = 'some value';
37
- expect(actual).toEqual(expected);
38
- });
39
- it('it should resolve none options to undefined', () => {
40
- const given = O.none;
41
- const resolvedOptions = (0, ResolveOptionValues_1.resolveOptionValues)(given);
42
- const actual = E.getOrElse((error) => {
43
- throw new Error('Should have been right');
44
- })(resolvedOptions);
45
- const expected = undefined;
46
- expect(actual).toEqual(expected);
47
- });
48
- it('it should return values unaltered that are not options', () => {
49
- const given = 'some value';
50
- const resolvedOptions = (0, ResolveOptionValues_1.resolveOptionValues)(given);
51
- const actual = E.getOrElse((error) => {
52
- throw new Error('Should have been right');
53
- })(resolvedOptions);
54
- const expected = 'some value';
55
- expect(actual).toEqual(expected);
56
- });
57
- it('it should return arrays unaltered that are not options', () => {
58
- const given = ['some value'];
59
- const resolvedOptions = (0, ResolveOptionValues_1.resolveOptionValues)(given);
60
- const actual = E.getOrElse((error) => {
61
- throw new Error('Should have been right');
62
- })(resolvedOptions);
63
- const expected = ['some value'];
64
- expect(actual).toEqual(expected);
65
- });
66
- it('it should resolve an object with some options to their underlying values', () => {
67
- const given = {
68
- property: 'some property',
69
- someOptionalProperty: O.some('some value'),
70
- noneOptionalProperty: O.none,
71
- nestedObject: {
72
- someNestedOptionalProperty: O.some('some nested value'),
73
- someNestedNoneOptionalProperty: O.none,
74
- },
75
- };
76
- const resolvedOptions = (0, ResolveOptionValues_1.resolveOptionValues)(given);
77
- const actual = E.getOrElse((error) => {
78
- throw new Error('Should have been right');
79
- })(resolvedOptions);
80
- const expected = {
81
- property: 'some property',
82
- someOptionalProperty: 'some value',
83
- noneOptionalProperty: undefined,
84
- nestedObject: {
85
- someNestedOptionalProperty: 'some nested value',
86
- someNestedNoneOptionalProperty: undefined,
87
- },
88
- };
89
- expect(actual).toEqual(expected);
90
- });
91
- });