@readme/api-core 7.0.0-alpha.5 → 7.0.0-beta.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.
@@ -0,0 +1,62 @@
1
+ export { FromSchema } from 'json-schema-to-ts';
2
+ import { SchemaWrapper } from 'oas/operation/get-parameters-as-json-schema';
3
+ import Operation from 'oas/operation';
4
+ import Oas from 'oas';
5
+
6
+ /**
7
+ * Run through a JSON Schema object and compose up an object containing default data for any schema
8
+ * property that is required and also has a defined default.
9
+ *
10
+ * Code partially adapted from the `json-schema-default` package but modified to only return
11
+ * defaults of required properties.
12
+ *
13
+ * @todo This is a good candidate to be moved into a core `oas` library method.
14
+ * @see {@link https://github.com/mdornseif/json-schema-default}
15
+ */
16
+ declare function getJSONSchemaDefaults(jsonSchemas: SchemaWrapper[]): {
17
+ [x: string]: Record<string, unknown>;
18
+ };
19
+
20
+ declare function parseResponse<HTTPStatus extends number = number>(response: Response): Promise<{
21
+ data: any;
22
+ status: HTTPStatus;
23
+ headers: Headers;
24
+ res: Response;
25
+ }>;
26
+
27
+ declare function prepareAuth(authKey: (number | string)[], operation: Operation): Record<string, string | number | {
28
+ pass: string | number;
29
+ user: string | number;
30
+ }>;
31
+
32
+ /**
33
+ * With potentially supplied body and/or metadata we need to run through them against a given API
34
+ * operation to see what's what and prepare any available parameters to be used in an API request
35
+ * with `@readme/oas-to-har`.
36
+ *
37
+ */
38
+ declare function prepareParams(operation: Operation, body?: unknown, metadata?: Record<string, unknown>): Promise<{
39
+ body?: any;
40
+ cookie?: Record<string, string | number | boolean> | undefined;
41
+ files?: Record<string, Buffer> | undefined;
42
+ formData?: any;
43
+ header?: Record<string, string | number | boolean> | undefined;
44
+ path?: Record<string, string | number | boolean> | undefined;
45
+ query?: Record<string, string | number | boolean> | undefined;
46
+ server?: {
47
+ selected: number;
48
+ variables: Record<string, string | number>;
49
+ } | undefined;
50
+ }>;
51
+
52
+ /**
53
+ * With an SDK server config and an instance of OAS we should extract and prepare the server and
54
+ * any server variables to be supplied to `@readme/oas-to-har`.
55
+ *
56
+ */
57
+ declare function prepareServer(spec: Oas, url: string, variables?: Record<string, string | number>): false | {
58
+ selected: number;
59
+ variables: Record<string, string | number>;
60
+ };
61
+
62
+ export { getJSONSchemaDefaults, parseResponse, prepareAuth, prepareParams, prepareServer };
@@ -0,0 +1,15 @@
1
+ import {
2
+ getJSONSchemaDefaults,
3
+ parseResponse,
4
+ prepareAuth,
5
+ prepareParams,
6
+ prepareServer
7
+ } from "../chunk-PWY7T36C.js";
8
+ export {
9
+ getJSONSchemaDefaults,
10
+ parseResponse,
11
+ prepareAuth,
12
+ prepareParams,
13
+ prepareServer
14
+ };
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@readme/api-core",
3
- "version": "7.0.0-alpha.5",
3
+ "version": "7.0.0-beta.0",
4
4
  "description": "The magic behind `api` 🧙",
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -13,6 +13,10 @@
13
13
  "require": "./dist/errors/fetchError.cjs",
14
14
  "import": "./dist/errors/fetchError.js"
15
15
  },
16
+ "./lib": {
17
+ "require": "./dist/lib/index.cjs",
18
+ "import": "./dist/lib/index.js"
19
+ },
16
20
  "./package.json": "./package.json"
17
21
  },
18
22
  "main": "dist/index.cjs",
@@ -45,14 +49,15 @@
45
49
  "caseless": "^0.12.0",
46
50
  "datauri": "^4.1.0",
47
51
  "fetch-har": "^11.0.1",
48
- "get-stream": "^6.0.1",
52
+ "get-stream": "^8.0.1",
53
+ "json-schema-to-ts": "^2.9.2",
49
54
  "json-schema-traverse": "^1.0.0",
50
55
  "lodash.merge": "^4.6.2",
51
56
  "oas": "^23.0.0",
52
57
  "remove-undefined-objects": "^5.0.0"
53
58
  },
54
59
  "devDependencies": {
55
- "@api/test-utils": "^7.0.0-alpha.5",
60
+ "@api/test-utils": "^7.0.0-beta.0",
56
61
  "@readme/oas-examples": "^5.12.0",
57
62
  "@types/caseless": "^0.12.3",
58
63
  "@types/lodash.merge": "^4.6.7",
@@ -62,5 +67,5 @@
62
67
  "vitest": "^0.34.5"
63
68
  },
64
69
  "prettier": "@readme/eslint-config/prettier",
65
- "gitHead": "b1e705dddedd223f360f1dfe620ae721f54af88b"
70
+ "gitHead": "6ea3f3468343cea16536dda9460d8f0c65fa35c8"
66
71
  }
package/src/index.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import type { Har } from 'har-format';
2
- import type Oas from 'oas';
3
2
  import type Operation from 'oas/operation';
4
- import type { HttpMethods } from 'oas/rmoas.types';
3
+ import type { HttpMethods, OASDocument } from 'oas/rmoas.types';
5
4
 
6
5
  import oasToHar from '@readme/oas-to-har';
7
6
  import fetchHar from 'fetch-har';
7
+ import Oas from 'oas';
8
8
 
9
9
  import FetchError from './errors/fetchError.js';
10
10
  import { parseResponse, prepareAuth, prepareParams, prepareServer } from './lib/index.js';
@@ -47,8 +47,8 @@ export default class APICore {
47
47
 
48
48
  private userAgent!: string;
49
49
 
50
- constructor(spec?: Oas, userAgent?: string) {
51
- if (spec) this.spec = spec;
50
+ constructor(definition?: Record<string, unknown> | OASDocument, userAgent?: string) {
51
+ if (definition) this.spec = Oas.init(definition);
52
52
  if (userAgent) this.userAgent = userAgent;
53
53
  }
54
54
 
package/src/lib/index.ts CHANGED
@@ -1,7 +1,9 @@
1
+ import type { FromSchema } from 'json-schema-to-ts';
2
+
1
3
  import getJSONSchemaDefaults from './getJSONSchemaDefaults.js';
2
4
  import parseResponse from './parseResponse.js';
3
5
  import prepareAuth from './prepareAuth.js';
4
6
  import prepareParams from './prepareParams.js';
5
7
  import prepareServer from './prepareServer.js';
6
8
 
7
- export { getJSONSchemaDefaults, parseResponse, prepareAuth, prepareParams, prepareServer };
9
+ export { FromSchema, getJSONSchemaDefaults, parseResponse, prepareAuth, prepareParams, prepareServer };
@@ -9,7 +9,7 @@ import stream from 'node:stream';
9
9
  import caseless from 'caseless';
10
10
  import DatauriParser from 'datauri/parser.js';
11
11
  import datauri from 'datauri/sync.js';
12
- import getStream from 'get-stream';
12
+ import { getStreamAsBuffer } from 'get-stream';
13
13
  import lodashMerge from 'lodash.merge';
14
14
  import removeUndefinedObjects from 'remove-undefined-objects';
15
15
 
@@ -111,7 +111,7 @@ function processFile(
111
111
  });
112
112
  });
113
113
  } else if (file instanceof stream.Readable) {
114
- return getStream.buffer(file).then(buffer => {
114
+ return getStreamAsBuffer(file).then(buffer => {
115
115
  const filePath = file.path as string;
116
116
  const parser = new DatauriParser();
117
117
  const base64 = parser.format(filePath, buffer).content;
package/tsup.config.ts CHANGED
@@ -1,6 +1,6 @@
1
+ /* eslint-disable import/no-extraneous-dependencies, node/no-extraneous-import */
1
2
  import type { Options } from 'tsup';
2
3
 
3
- // eslint-disable-next-line import/no-extraneous-dependencies
4
4
  import { defineConfig } from 'tsup';
5
5
 
6
6
  // eslint-disable-next-line import/no-relative-packages
@@ -10,6 +10,6 @@ export default defineConfig((options: Options) => ({
10
10
  ...options,
11
11
  ...config,
12
12
 
13
- entry: ['src/errors/fetchError.ts', 'src/index.ts'],
13
+ entry: ['src/errors/fetchError.ts', 'src/lib/index.ts', 'src/index.ts'],
14
14
  silent: !options.watch,
15
15
  }));