@robosystems/client 0.1.10

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,90 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+
3
+ import type {
4
+ ArrayStyle,
5
+ ObjectStyle,
6
+ SerializerOptions,
7
+ } from './pathSerializer.gen';
8
+
9
+ export type QuerySerializer = (query: Record<string, unknown>) => string;
10
+
11
+ export type BodySerializer = (body: any) => any;
12
+
13
+ export interface QuerySerializerOptions {
14
+ allowReserved?: boolean;
15
+ array?: SerializerOptions<ArrayStyle>;
16
+ object?: SerializerOptions<ObjectStyle>;
17
+ }
18
+
19
+ const serializeFormDataPair = (
20
+ data: FormData,
21
+ key: string,
22
+ value: unknown,
23
+ ): void => {
24
+ if (typeof value === 'string' || value instanceof Blob) {
25
+ data.append(key, value);
26
+ } else {
27
+ data.append(key, JSON.stringify(value));
28
+ }
29
+ };
30
+
31
+ const serializeUrlSearchParamsPair = (
32
+ data: URLSearchParams,
33
+ key: string,
34
+ value: unknown,
35
+ ): void => {
36
+ if (typeof value === 'string') {
37
+ data.append(key, value);
38
+ } else {
39
+ data.append(key, JSON.stringify(value));
40
+ }
41
+ };
42
+
43
+ export const formDataBodySerializer = {
44
+ bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(
45
+ body: T,
46
+ ): FormData => {
47
+ const data = new FormData();
48
+
49
+ Object.entries(body).forEach(([key, value]) => {
50
+ if (value === undefined || value === null) {
51
+ return;
52
+ }
53
+ if (Array.isArray(value)) {
54
+ value.forEach((v) => serializeFormDataPair(data, key, v));
55
+ } else {
56
+ serializeFormDataPair(data, key, value);
57
+ }
58
+ });
59
+
60
+ return data;
61
+ },
62
+ };
63
+
64
+ export const jsonBodySerializer = {
65
+ bodySerializer: <T>(body: T): string =>
66
+ JSON.stringify(body, (_key, value) =>
67
+ typeof value === 'bigint' ? value.toString() : value,
68
+ ),
69
+ };
70
+
71
+ export const urlSearchParamsBodySerializer = {
72
+ bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(
73
+ body: T,
74
+ ): string => {
75
+ const data = new URLSearchParams();
76
+
77
+ Object.entries(body).forEach(([key, value]) => {
78
+ if (value === undefined || value === null) {
79
+ return;
80
+ }
81
+ if (Array.isArray(value)) {
82
+ value.forEach((v) => serializeUrlSearchParamsPair(data, key, v));
83
+ } else {
84
+ serializeUrlSearchParamsPair(data, key, value);
85
+ }
86
+ });
87
+
88
+ return data.toString();
89
+ },
90
+ };
@@ -0,0 +1,153 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+
3
+ type Slot = 'body' | 'headers' | 'path' | 'query';
4
+
5
+ export type Field =
6
+ | {
7
+ in: Exclude<Slot, 'body'>;
8
+ /**
9
+ * Field name. This is the name we want the user to see and use.
10
+ */
11
+ key: string;
12
+ /**
13
+ * Field mapped name. This is the name we want to use in the request.
14
+ * If omitted, we use the same value as `key`.
15
+ */
16
+ map?: string;
17
+ }
18
+ | {
19
+ in: Extract<Slot, 'body'>;
20
+ /**
21
+ * Key isn't required for bodies.
22
+ */
23
+ key?: string;
24
+ map?: string;
25
+ };
26
+
27
+ export interface Fields {
28
+ allowExtra?: Partial<Record<Slot, boolean>>;
29
+ args?: ReadonlyArray<Field>;
30
+ }
31
+
32
+ export type FieldsConfig = ReadonlyArray<Field | Fields>;
33
+
34
+ const extraPrefixesMap: Record<string, Slot> = {
35
+ $body_: 'body',
36
+ $headers_: 'headers',
37
+ $path_: 'path',
38
+ $query_: 'query',
39
+ };
40
+ const extraPrefixes = Object.entries(extraPrefixesMap);
41
+
42
+ type KeyMap = Map<
43
+ string,
44
+ {
45
+ in: Slot;
46
+ map?: string;
47
+ }
48
+ >;
49
+
50
+ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
51
+ if (!map) {
52
+ map = new Map();
53
+ }
54
+
55
+ for (const config of fields) {
56
+ if ('in' in config) {
57
+ if (config.key) {
58
+ map.set(config.key, {
59
+ in: config.in,
60
+ map: config.map,
61
+ });
62
+ }
63
+ } else if (config.args) {
64
+ buildKeyMap(config.args, map);
65
+ }
66
+ }
67
+
68
+ return map;
69
+ };
70
+
71
+ interface Params {
72
+ body: unknown;
73
+ headers: Record<string, unknown>;
74
+ path: Record<string, unknown>;
75
+ query: Record<string, unknown>;
76
+ }
77
+
78
+ const stripEmptySlots = (params: Params) => {
79
+ for (const [slot, value] of Object.entries(params)) {
80
+ if (value && typeof value === 'object' && !Object.keys(value).length) {
81
+ delete params[slot as Slot];
82
+ }
83
+ }
84
+ };
85
+
86
+ export const buildClientParams = (
87
+ args: ReadonlyArray<unknown>,
88
+ fields: FieldsConfig,
89
+ ) => {
90
+ const params: Params = {
91
+ body: {},
92
+ headers: {},
93
+ path: {},
94
+ query: {},
95
+ };
96
+
97
+ const map = buildKeyMap(fields);
98
+
99
+ let config: FieldsConfig[number] | undefined;
100
+
101
+ for (const [index, arg] of args.entries()) {
102
+ if (fields[index]) {
103
+ config = fields[index];
104
+ }
105
+
106
+ if (!config) {
107
+ continue;
108
+ }
109
+
110
+ if ('in' in config) {
111
+ if (config.key) {
112
+ const field = map.get(config.key)!;
113
+ const name = field.map || config.key;
114
+ (params[field.in] as Record<string, unknown>)[name] = arg;
115
+ } else {
116
+ params.body = arg;
117
+ }
118
+ } else {
119
+ for (const [key, value] of Object.entries(arg ?? {})) {
120
+ const field = map.get(key);
121
+
122
+ if (field) {
123
+ const name = field.map || key;
124
+ (params[field.in] as Record<string, unknown>)[name] = value;
125
+ } else {
126
+ const extra = extraPrefixes.find(([prefix]) =>
127
+ key.startsWith(prefix),
128
+ );
129
+
130
+ if (extra) {
131
+ const [prefix, slot] = extra;
132
+ (params[slot] as Record<string, unknown>)[
133
+ key.slice(prefix.length)
134
+ ] = value;
135
+ } else {
136
+ for (const [slot, allowed] of Object.entries(
137
+ config.allowExtra ?? {},
138
+ )) {
139
+ if (allowed) {
140
+ (params[slot as Slot] as Record<string, unknown>)[key] = value;
141
+ break;
142
+ }
143
+ }
144
+ }
145
+ }
146
+ }
147
+ }
148
+ }
149
+
150
+ stripEmptySlots(params);
151
+
152
+ return params;
153
+ };
@@ -0,0 +1,181 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+
3
+ interface SerializeOptions<T>
4
+ extends SerializePrimitiveOptions,
5
+ SerializerOptions<T> {}
6
+
7
+ interface SerializePrimitiveOptions {
8
+ allowReserved?: boolean;
9
+ name: string;
10
+ }
11
+
12
+ export interface SerializerOptions<T> {
13
+ /**
14
+ * @default true
15
+ */
16
+ explode: boolean;
17
+ style: T;
18
+ }
19
+
20
+ export type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited';
21
+ export type ArraySeparatorStyle = ArrayStyle | MatrixStyle;
22
+ type MatrixStyle = 'label' | 'matrix' | 'simple';
23
+ export type ObjectStyle = 'form' | 'deepObject';
24
+ type ObjectSeparatorStyle = ObjectStyle | MatrixStyle;
25
+
26
+ interface SerializePrimitiveParam extends SerializePrimitiveOptions {
27
+ value: string;
28
+ }
29
+
30
+ export const separatorArrayExplode = (style: ArraySeparatorStyle) => {
31
+ switch (style) {
32
+ case 'label':
33
+ return '.';
34
+ case 'matrix':
35
+ return ';';
36
+ case 'simple':
37
+ return ',';
38
+ default:
39
+ return '&';
40
+ }
41
+ };
42
+
43
+ export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => {
44
+ switch (style) {
45
+ case 'form':
46
+ return ',';
47
+ case 'pipeDelimited':
48
+ return '|';
49
+ case 'spaceDelimited':
50
+ return '%20';
51
+ default:
52
+ return ',';
53
+ }
54
+ };
55
+
56
+ export const separatorObjectExplode = (style: ObjectSeparatorStyle) => {
57
+ switch (style) {
58
+ case 'label':
59
+ return '.';
60
+ case 'matrix':
61
+ return ';';
62
+ case 'simple':
63
+ return ',';
64
+ default:
65
+ return '&';
66
+ }
67
+ };
68
+
69
+ export const serializeArrayParam = ({
70
+ allowReserved,
71
+ explode,
72
+ name,
73
+ style,
74
+ value,
75
+ }: SerializeOptions<ArraySeparatorStyle> & {
76
+ value: unknown[];
77
+ }) => {
78
+ if (!explode) {
79
+ const joinedValues = (
80
+ allowReserved ? value : value.map((v) => encodeURIComponent(v as string))
81
+ ).join(separatorArrayNoExplode(style));
82
+ switch (style) {
83
+ case 'label':
84
+ return `.${joinedValues}`;
85
+ case 'matrix':
86
+ return `;${name}=${joinedValues}`;
87
+ case 'simple':
88
+ return joinedValues;
89
+ default:
90
+ return `${name}=${joinedValues}`;
91
+ }
92
+ }
93
+
94
+ const separator = separatorArrayExplode(style);
95
+ const joinedValues = value
96
+ .map((v) => {
97
+ if (style === 'label' || style === 'simple') {
98
+ return allowReserved ? v : encodeURIComponent(v as string);
99
+ }
100
+
101
+ return serializePrimitiveParam({
102
+ allowReserved,
103
+ name,
104
+ value: v as string,
105
+ });
106
+ })
107
+ .join(separator);
108
+ return style === 'label' || style === 'matrix'
109
+ ? separator + joinedValues
110
+ : joinedValues;
111
+ };
112
+
113
+ export const serializePrimitiveParam = ({
114
+ allowReserved,
115
+ name,
116
+ value,
117
+ }: SerializePrimitiveParam) => {
118
+ if (value === undefined || value === null) {
119
+ return '';
120
+ }
121
+
122
+ if (typeof value === 'object') {
123
+ throw new Error(
124
+ 'Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.',
125
+ );
126
+ }
127
+
128
+ return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
129
+ };
130
+
131
+ export const serializeObjectParam = ({
132
+ allowReserved,
133
+ explode,
134
+ name,
135
+ style,
136
+ value,
137
+ valueOnly,
138
+ }: SerializeOptions<ObjectSeparatorStyle> & {
139
+ value: Record<string, unknown> | Date;
140
+ valueOnly?: boolean;
141
+ }) => {
142
+ if (value instanceof Date) {
143
+ return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
144
+ }
145
+
146
+ if (style !== 'deepObject' && !explode) {
147
+ let values: string[] = [];
148
+ Object.entries(value).forEach(([key, v]) => {
149
+ values = [
150
+ ...values,
151
+ key,
152
+ allowReserved ? (v as string) : encodeURIComponent(v as string),
153
+ ];
154
+ });
155
+ const joinedValues = values.join(',');
156
+ switch (style) {
157
+ case 'form':
158
+ return `${name}=${joinedValues}`;
159
+ case 'label':
160
+ return `.${joinedValues}`;
161
+ case 'matrix':
162
+ return `;${name}=${joinedValues}`;
163
+ default:
164
+ return joinedValues;
165
+ }
166
+ }
167
+
168
+ const separator = separatorObjectExplode(style);
169
+ const joinedValues = Object.entries(value)
170
+ .map(([key, v]) =>
171
+ serializePrimitiveParam({
172
+ allowReserved,
173
+ name: style === 'deepObject' ? `${name}[${key}]` : key,
174
+ value: v as string,
175
+ }),
176
+ )
177
+ .join(separator);
178
+ return style === 'label' || style === 'matrix'
179
+ ? separator + joinedValues
180
+ : joinedValues;
181
+ };
@@ -0,0 +1,121 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ /* eslint-disable no-undef */
3
+
4
+ import type { Auth, AuthToken } from './auth.gen';
5
+ import type {
6
+ BodySerializer,
7
+ QuerySerializer,
8
+ QuerySerializerOptions,
9
+ } from './bodySerializer.gen';
10
+
11
+ export interface Client<
12
+ RequestFn = never,
13
+ Config = unknown,
14
+ MethodFn = never,
15
+ BuildUrlFn = never,
16
+ > {
17
+ /**
18
+ * Returns the final request URL.
19
+ */
20
+ buildUrl: BuildUrlFn;
21
+ connect: MethodFn;
22
+ delete: MethodFn;
23
+ get: MethodFn;
24
+ getConfig: () => Config;
25
+ head: MethodFn;
26
+ options: MethodFn;
27
+ patch: MethodFn;
28
+ post: MethodFn;
29
+ put: MethodFn;
30
+ request: RequestFn;
31
+ setConfig: (config: Config) => Config;
32
+ trace: MethodFn;
33
+ }
34
+
35
+ export interface Config {
36
+ /**
37
+ * Auth token or a function returning auth token. The resolved value will be
38
+ * added to the request payload as defined by its `security` array.
39
+ */
40
+ auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
41
+ /**
42
+ * A function for serializing request body parameter. By default,
43
+ * {@link JSON.stringify()} will be used.
44
+ */
45
+ bodySerializer?: BodySerializer | null;
46
+ /**
47
+ * An object containing any HTTP headers that you want to pre-populate your
48
+ * `Headers` object with.
49
+ *
50
+ * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
51
+ */
52
+ headers?:
53
+ | RequestInit['headers']
54
+ | Record<
55
+ string,
56
+ | string
57
+ | number
58
+ | boolean
59
+ | (string | number | boolean)[]
60
+ | null
61
+ | undefined
62
+ | unknown
63
+ >;
64
+ /**
65
+ * The request method.
66
+ *
67
+ * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
68
+ */
69
+ method?:
70
+ | 'CONNECT'
71
+ | 'DELETE'
72
+ | 'GET'
73
+ | 'HEAD'
74
+ | 'OPTIONS'
75
+ | 'PATCH'
76
+ | 'POST'
77
+ | 'PUT'
78
+ | 'TRACE';
79
+ /**
80
+ * A function for serializing request query parameters. By default, arrays
81
+ * will be exploded in form style, objects will be exploded in deepObject
82
+ * style, and reserved characters are percent-encoded.
83
+ *
84
+ * This method will have no effect if the native `paramsSerializer()` Axios
85
+ * API function is used.
86
+ *
87
+ * {@link https://swagger.io/docs/specification/serialization/#query View examples}
88
+ */
89
+ querySerializer?: QuerySerializer | QuerySerializerOptions;
90
+ /**
91
+ * A function validating request data. This is useful if you want to ensure
92
+ * the request conforms to the desired shape, so it can be safely sent to
93
+ * the server.
94
+ */
95
+ requestValidator?: (data: unknown) => Promise<unknown>;
96
+ /**
97
+ * A function transforming response data before it's returned. This is useful
98
+ * for post-processing data, e.g. converting ISO strings into Date objects.
99
+ */
100
+ responseTransformer?: (data: unknown) => Promise<unknown>;
101
+ /**
102
+ * A function validating response data. This is useful if you want to ensure
103
+ * the response conforms to the desired shape, so it can be safely passed to
104
+ * the transformers and returned to the user.
105
+ */
106
+ responseValidator?: (data: unknown) => Promise<unknown>;
107
+ }
108
+
109
+ type IsExactlyNeverOrNeverUndefined<T> = [T] extends [never]
110
+ ? true
111
+ : [T] extends [never | undefined]
112
+ ? [undefined] extends [T]
113
+ ? false
114
+ : true
115
+ : false;
116
+
117
+ export type OmitNever<T extends Record<string, unknown>> = {
118
+ [K in keyof T as IsExactlyNeverOrNeverUndefined<T[K]> extends true
119
+ ? never
120
+ : K]: T[K];
121
+ };
package/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ // Re-export all types
2
+ export * from './sdk.gen';
3
+ export * from './types.gen';
4
+ export { client } from './client.gen';
5
+ export * from './client/index';
6
+
7
+ // Re-export SDK extensions
8
+ export * from './extensions/index';
package/index.js ADDED
@@ -0,0 +1,8 @@
1
+ // Re-export everything from the generated SDK
2
+ export * from './sdk.gen.js';
3
+ export * from './types.gen.js';
4
+ export { client } from './client.gen.js';
5
+ export * from './client/index.js';
6
+
7
+ // Re-export SDK extensions
8
+ export * from './extensions/index.js';
package/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ export * from './types.gen';
3
+ export * from './sdk.gen';
@@ -0,0 +1,9 @@
1
+ /** @type {import('@hey-api/openapi-ts').UserConfig} */
2
+ module.exports = {
3
+ input: process.env.ROBOSYSTEMS_API_URL + '/openapi.json',
4
+ output: {
5
+ clean: false, // Preserve custom files like query.ts
6
+ path: 'sdk',
7
+ },
8
+ plugins: ['@hey-api/client-fetch'],
9
+ }
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@robosystems/client",
3
+ "version": "0.1.10",
4
+ "description": "TypeScript client library for RoboSystems Financial Knowledge Graph API",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "files": [
8
+ "*.js",
9
+ "*.ts",
10
+ "*.d.ts",
11
+ "client/**/*",
12
+ "core/**/*",
13
+ "src/**/*",
14
+ "README.md",
15
+ "LICENSE"
16
+ ],
17
+ "scripts": {
18
+ "generate": "npm run generate:clean && npm run generate:sdk && npm run generate:fix && npm run format && npm run lint:fix",
19
+ "generate:clean": "rm -rf sdk",
20
+ "generate:sdk": "ROBOSYSTEMS_API_URL=http://localhost:8000 npx @hey-api/openapi-ts -f openapi-ts.config.js",
21
+ "generate:fix": "node scripts/fix-sdk-types.js",
22
+ "format": "prettier . --write",
23
+ "format:check": "prettier . --check",
24
+ "lint": "eslint .",
25
+ "lint:fix": "eslint . --fix",
26
+ "typecheck": "tsc --noEmit",
27
+ "validate": "npm run format:check && npm run lint && npm run typecheck",
28
+ "validate:fix": "npm run format && npm run lint:fix && npm run typecheck",
29
+ "test": "npm run validate",
30
+ "test:all": "npm run validate && npm run build",
31
+ "prepare:publish": "node prepare.js",
32
+ "prepublishOnly": "npm run prepare:publish",
33
+ "build": "tsc"
34
+ },
35
+ "keywords": [
36
+ "robosystems",
37
+ "financial",
38
+ "graph",
39
+ "api",
40
+ "sdk",
41
+ "typescript",
42
+ "knowledge-graph"
43
+ ],
44
+ "author": "Harbinger FinLab",
45
+ "license": "MIT",
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "https://github.com/RoboFinSystems/robosystems-typescript-client.git"
49
+ },
50
+ "bugs": {
51
+ "url": "https://github.com/RoboFinSystems/robosystems-typescript-client/issues"
52
+ },
53
+ "homepage": "https://github.com/RoboFinSystems/robosystems-typescript-client#readme",
54
+ "dependencies": {},
55
+ "engines": {
56
+ "node": ">=18.0.0"
57
+ },
58
+ "devDependencies": {
59
+ "@hey-api/openapi-ts": "^0.80.2",
60
+ "@types/node": "^22.0.0",
61
+ "@typescript-eslint/eslint-plugin": "^7.0.0",
62
+ "@typescript-eslint/parser": "^7.0.0",
63
+ "eslint": "^8.0.0",
64
+ "eslint-config-prettier": "^10.0.0",
65
+ "eslint-plugin-prettier": "^5.0.0",
66
+ "prettier": "^3.0.0",
67
+ "prettier-plugin-organize-imports": "^4.0.0",
68
+ "typescript": "^5.7.3"
69
+ },
70
+ "publishConfig": {
71
+ "access": "public",
72
+ "registry": "https://registry.npmjs.org/"
73
+ }
74
+ }