@intrig/core 0.0.15-1 → 0.0.15-3
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/README.md +1 -12
- package/main.js +135 -53
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<
|
|
3
|
-
<g transform="translate(-41.904154,-168.00498)">
|
|
4
|
-
<path style="fill:#00D8C0;fill-opacity:1;stroke:#ffffff;stroke-width:0.2;stroke-dasharray:none;stroke-opacity:0.2" d="m 114.89996,168.10498 c -1.06916,0 -1.9358,0.86714 -1.9358,1.96733 v 3.84059 h -2.61224 c -1.09993,0 -1.9668,0.86664 -1.9668,1.9358 0,1.06918 0.86687,1.9358 1.9668,1.9358 h 2.61224 v 13.58211 c 0,1.09993 0.86664,1.96681 1.9358,1.96681 1.06916,0 1.9358,-0.86688 1.9358,-1.96681 V 177.7845 h 2.55023 c 1.1002,0 1.96681,-0.86662 1.96681,-1.9358 0,-1.06916 -0.86661,-1.9358 -1.96681,-1.9358 h -2.55023 v -3.84059 c 0,-1.10019 -0.86664,-1.96733 -1.9358,-1.96733 z" />
|
|
5
|
-
<path style="fill:#00D8C0;fill-opacity:1;stroke:#ffffff;stroke-width:0.2;stroke-dasharray:none;stroke-opacity:0.2" d="m 105.8658,183.59235 c 0,-3.2075 -2.6002,-5.8077 -5.8077,-5.8077 -3.20751,0 -5.8077,2.6002 -5.8077,5.82483 1.2e-4,4.19734 0,4.49999 0,7.73546 0,1.07815 -0.866741,1.94487 -1.935903,1.94487 -1.069175,0 -1.935901,-0.86672 -1.935901,-1.94487 0,-3.23547 9.4e-5,-3.11312 0,-7.74183 0,-5.35659 4.333654,-9.69026 9.679504,-9.69026 5.34584,0 9.6795,4.33367 9.6795,9.69275 v 7.68735 c 0,1.11218 -0.86674,1.97892 -1.9359,1.97892 -1.06916,0 -1.9359,-0.86674 -1.9359,-1.97892 z" />
|
|
6
|
-
<path style="fill:#00D8C0;fill-opacity:1;stroke:#ffffff;stroke-width:0.2;stroke-dasharray:none;stroke-opacity:0.2" d="m 124.57948,173.88189 c -1.06917,0 -1.9358,0.86662 -1.9358,1.96681 v 7.74371 7.7742 c 0,1.09993 0.86663,1.96681 1.9358,1.96681 1.06915,0 1.9358,-0.86688 1.9358,-1.96681 v -7.75921 c 0,-3.23303 2.62074,-5.85381 5.83065,-5.83841 1.0461,0.0155 1.91306,-0.85113 1.91306,-1.92029 0,-1.06916 -0.86696,-1.936 -1.91306,-1.9513 -2.18669,-0.006 -4.20651,0.71897 -5.83117,1.94458 -0.004,-1.09694 -0.86834,-1.96009 -1.93528,-1.96009 z" />
|
|
7
|
-
<path style="fill:#00D8C0;fill-opacity:1;stroke:#ffffff;stroke-width:0.2;stroke-dasharray:none;stroke-opacity:0.2" d="m 137.48551,193.318 c -1.06916,0 -1.9359,-0.86674 -1.9359,-1.96666 v -10.95446 c 0,-1.10019 0.86674,-1.96693 1.9359,-1.96693 1.06916,0 1.9359,0.86674 1.9359,1.96693 v 10.95446 c 0,1.09992 -0.86674,1.96666 -1.9359,1.96666 z" />
|
|
8
|
-
<circle style="fill:#00D8C0;fill-opacity:1;stroke:#ffffff;stroke-width:0.2;stroke-dasharray:none;stroke-opacity:0.2" cx="137.48552" cy="175.84875" r="1.9358984" />
|
|
9
|
-
<path style="fill:#00D8C0;fill-opacity:1;stroke:#ffffff;stroke-width:0.2;stroke-dasharray:none;stroke-opacity:0.2" d="m 159.42593,173.88189 c -1.06916,0 -1.93632,0.86662 -1.93632,1.96681 v 0.001 a 9.6795038,9.6795038 0 0 0 -5.8074,-1.93683 9.6795038,9.6795038 0 0 0 -9.67951,9.67951 9.6795038,9.6795038 0 0 0 9.67951,9.67951 9.6795038,9.6795038 0 0 0 5.8074,-1.9668 v 3.82199 c 0,3.28811 -2.60016,5.88852 -5.83168,5.88078 l -93.953959,-0.008 c -1.099919,0 -1.966805,0.86664 -1.966805,1.9358 0,1.06916 0.866886,1.93631 1.966805,1.93631 l 93.934319,0.005 c 5.38943,0.0105 9.72344,-4.32282 9.72344,-9.74927 v -11.5347 -7.74371 c 0,-1.10019 -0.86662,-1.96681 -1.9358,-1.96681 z m -7.74372,3.90312 a 5.8077041,5.8077041 0 0 1 5.8074,5.80172 v 0.0114 a 5.8077041,5.8077041 0 0 1 -5.8074,5.80223 5.8077041,5.8077041 0 0 1 -5.80791,-5.80792 5.8077041,5.8077041 0 0 1 5.80791,-5.8074 z" />
|
|
10
|
-
<path style="fill:#00D8C0;fill-opacity:1;stroke:#ffffff;stroke-width:0.2;stroke-dasharray:none;stroke-opacity:0.2" d="m 85.216195,193.318 c -1.069162,0 -1.9359,-0.86674 -1.9359,-1.96666 v -20.98655 c 0,-1.10019 0.866738,-1.96693 1.9359,-1.96693 1.069162,0 1.935901,0.86674 1.935901,1.96693 v 20.98655 c 0,1.09992 -0.866739,1.96666 -1.935901,1.96666 z" />
|
|
11
|
-
<path style="fill:#888888;fill-opacity:1;stroke:#ffffff;stroke-width:0.2;stroke-dasharray:none;stroke-opacity:0.2" d="m 81.734029,179.04592 -23.717415,0.004 c -8.78429,0.0146 -16.011886,7.2611 -16.01246,16.03158 v 5.1e-4 5.2e-4 c 5.65e-4,8.77049 7.109474,15.87969 15.953032,15.8812 h 9.220626 c 1.249561,0 2.206067,-0.97006 2.206067,-2.16731 0,-1.19725 -0.956114,-2.16783 -2.231906,-2.16783 l -8.990665,-0.0114 c -6.451791,-0.0129 -11.597742,-5.20849 -11.597742,-11.61738 0,-6.40889 5.145707,-11.60343 11.493355,-11.60343 6.347649,0 11.493356,5.19457 11.493356,11.60343 0,8.81624 7.059408,15.96376 15.695682,15.9644 l 66.275541,0.002 c 9.23414,-3e-5 16.47858,-7.14834 16.47858,-15.96595 0,-4.51466 -1.90726,-8.58331 -5.00021,-11.48715 v 9.75754 c 0.086,0.56895 0.14469,1.14707 0.14469,1.73995 0,6.40551 -5.19367,11.59754 -11.62978,11.60756 l -66.117409,0.009 c -6.422849,0 -11.565661,-5.20583 -11.566219,-11.62771 v -5.2e-4 -5.2e-4 c 4.13e-4,-5.32739 3.16079,-9.8136 7.902877,-11.17968 z" />
|
|
12
|
-
</g>
|
|
13
|
-
</svg>
|
|
2
|
+
<img src="https://raw.githubusercontent.com/intrigsoft/intrig-core/refs/heads/main/docs/images/intrig-logo.svg" alt="Intrig Logo" width="300"/>
|
|
14
3
|
</div>
|
|
15
4
|
|
|
16
5
|
# Intrig Core
|
package/main.js
CHANGED
|
@@ -2676,6 +2676,7 @@ function splitPrefixSuffix(input, options = {}) {
|
|
|
2676
2676
|
|
|
2677
2677
|
|
|
2678
2678
|
|
|
2679
|
+
|
|
2679
2680
|
// Templates
|
|
2680
2681
|
|
|
2681
2682
|
|
|
@@ -6109,9 +6110,9 @@ function reactContextTemplate(_path, apisToSync) {
|
|
|
6109
6110
|
${apisToSync.map((a)=>`${a.id}?: DefaultConfigs`).join(",\n ")}
|
|
6110
6111
|
}`;
|
|
6111
6112
|
return ts`
|
|
6112
|
-
|
|
6113
|
+
import { NetworkAction, NetworkState } from '@intrig/react/network-state';
|
|
6113
6114
|
import { AxiosProgressEvent, AxiosRequestConfig } from 'axios';
|
|
6114
|
-
import { ZodSchema } from 'zod';
|
|
6115
|
+
import { ZodSchema, ZodType, ZodTypeDef } from 'zod';
|
|
6115
6116
|
import { createContext, useContext, Dispatch } from 'react';
|
|
6116
6117
|
import { DefaultConfigs } from '@intrig/react/intrig-provider';
|
|
6117
6118
|
|
|
@@ -6123,6 +6124,8 @@ interface RequestType<T = any> extends AxiosRequestConfig {
|
|
|
6123
6124
|
source: string
|
|
6124
6125
|
}
|
|
6125
6126
|
|
|
6127
|
+
export type ZodOut<T> = ZodType<T, ZodTypeDef, unknown>;
|
|
6128
|
+
|
|
6126
6129
|
/**
|
|
6127
6130
|
* Defines the ContextType interface for managing global state, dispatching actions,
|
|
6128
6131
|
* and holding a collection of Axios instances.
|
|
@@ -6137,7 +6140,7 @@ export interface ContextType {
|
|
|
6137
6140
|
filteredState: GlobalState;
|
|
6138
6141
|
dispatch: Dispatch<NetworkAction<unknown, unknown>>;
|
|
6139
6142
|
configs: ${configType};
|
|
6140
|
-
execute: <T>(request: RequestType, dispatch: (state: NetworkState<T>) => void, schema:
|
|
6143
|
+
execute: <T>(request: RequestType, dispatch: (state: NetworkState<T>) => void, schema: ZodOut<T> | undefined, errorSchema: ZodOut<T> | undefined) => Promise<void>;
|
|
6141
6144
|
}
|
|
6142
6145
|
|
|
6143
6146
|
/**
|
|
@@ -7248,7 +7251,7 @@ import logger from './logger';
|
|
|
7248
7251
|
import {flushSync} from "react-dom";
|
|
7249
7252
|
import {createParser} from "eventsource-parser";
|
|
7250
7253
|
|
|
7251
|
-
import {Context, RequestType, GlobalState} from './intrig-context';
|
|
7254
|
+
import {Context, RequestType, GlobalState, ZodOut} from './intrig-context';
|
|
7252
7255
|
|
|
7253
7256
|
/**
|
|
7254
7257
|
* Handles state updates for network requests based on the provided action.
|
|
@@ -7551,8 +7554,8 @@ export interface NetworkStateProps<T, E = unknown> {
|
|
|
7551
7554
|
key: string;
|
|
7552
7555
|
operation: string;
|
|
7553
7556
|
source: string;
|
|
7554
|
-
schema?:
|
|
7555
|
-
errorSchema?:
|
|
7557
|
+
schema?: ZodOut<T>;
|
|
7558
|
+
errorSchema?: ZodOut<E>;
|
|
7556
7559
|
debounceDelay?: number;
|
|
7557
7560
|
}
|
|
7558
7561
|
|
|
@@ -7677,8 +7680,8 @@ export function useTransientCall<T, E = unknown>({
|
|
|
7677
7680
|
schema,
|
|
7678
7681
|
errorSchema
|
|
7679
7682
|
}: {
|
|
7680
|
-
schema?:
|
|
7681
|
-
errorSchema?:
|
|
7683
|
+
schema?: ZodOut<T>;
|
|
7684
|
+
errorSchema?: ZodOut<T>
|
|
7682
7685
|
}): [(request: RequestType) => Promise<T>, () => void] {
|
|
7683
7686
|
const ctx = useContext(Context);
|
|
7684
7687
|
const controller = useRef<AbortController>(null);
|
|
@@ -7825,17 +7828,19 @@ function reactTsConfigTemplate(_path) {
|
|
|
7825
7828
|
;// ../../lib/react-binding/src/lib/templates/source/controller/method/clientIndex.template.ts
|
|
7826
7829
|
|
|
7827
7830
|
|
|
7828
|
-
async function reactClientIndexTemplate(descriptors, _path) {
|
|
7831
|
+
async function reactClientIndexTemplate(descriptors, _path, ctx) {
|
|
7829
7832
|
const { source, data: { paths, operationId, responseType, contentType } } = descriptors[0];
|
|
7830
7833
|
const ts = typescript(external_path_namespaceObject.resolve(_path, 'src', source, ...paths, camelCase(operationId), `client.ts`));
|
|
7834
|
+
const postfix = ctx.potentiallyConflictingDescriptors.includes(operationId) ? generatePostfix(contentType, responseType) : '';
|
|
7831
7835
|
if (descriptors.length === 1) return ts`
|
|
7832
|
-
export { use${pascalCase(operationId)} } from './use${pascalCase(operationId)}${
|
|
7833
|
-
export { use${pascalCase(operationId)}Async } from './use${pascalCase(operationId)}Async${
|
|
7836
|
+
export { use${pascalCase(operationId)} } from './use${pascalCase(operationId)}${postfix}'
|
|
7837
|
+
export { use${pascalCase(operationId)}Async } from './use${pascalCase(operationId)}Async${postfix}'
|
|
7834
7838
|
`;
|
|
7835
7839
|
const exports = descriptors.map(({ data: { contentType, responseType } })=>{
|
|
7840
|
+
const postfix = ctx.potentiallyConflictingDescriptors.includes(operationId) ? generatePostfix(contentType, responseType) : '';
|
|
7836
7841
|
return `
|
|
7837
|
-
export { use${pascalCase(operationId)} as use${pascalCase(operationId)}${
|
|
7838
|
-
export { use${pascalCase(operationId)}Async as use${pascalCase(operationId)}Async${
|
|
7842
|
+
export { use${pascalCase(operationId)} as use${pascalCase(operationId)}${postfix} } from './use${pascalCase(operationId)}${postfix}'
|
|
7843
|
+
export { use${pascalCase(operationId)}Async as use${pascalCase(operationId)}Async${postfix} } from './use${pascalCase(operationId)}Async${postfix}'
|
|
7839
7844
|
`;
|
|
7840
7845
|
}).join('\n');
|
|
7841
7846
|
return ts`
|
|
@@ -7846,7 +7851,7 @@ async function reactClientIndexTemplate(descriptors, _path) {
|
|
|
7846
7851
|
;// ../../lib/react-binding/src/lib/templates/source/controller/method/params.template.ts
|
|
7847
7852
|
|
|
7848
7853
|
|
|
7849
|
-
async function reactParamsTemplate({ source, data: { paths, operationId, variables } }, _path) {
|
|
7854
|
+
async function reactParamsTemplate({ source, data: { paths, operationId, variables } }, _path, ctx) {
|
|
7850
7855
|
const ts = typescript(external_path_namespaceObject.resolve(_path, 'src', source, ...paths, camelCase(operationId), `${pascalCase(operationId)}.params.ts`));
|
|
7851
7856
|
const { variableImports, variableTypes } = decodeVariables(variables ?? [], source, "@intrig/react");
|
|
7852
7857
|
return ts`
|
|
@@ -7936,8 +7941,9 @@ function requestHook_template_extractErrorParams(errorTypes) {
|
|
|
7936
7941
|
const errorSchema = z.union([${errorTypes.map((a)=>`${a}Schema`).join(', ')}])`;
|
|
7937
7942
|
}
|
|
7938
7943
|
}
|
|
7939
|
-
async function reactRequestHookTemplate({ source, data: { paths, operationId, response, requestUrl, variables, requestBody, contentType, responseType, errorResponses, method } }, _path) {
|
|
7940
|
-
const
|
|
7944
|
+
async function reactRequestHookTemplate({ source, data: { paths, operationId, response, requestUrl, variables, requestBody, contentType, responseType, errorResponses, method } }, _path, ctx) {
|
|
7945
|
+
const postfix = ctx.potentiallyConflictingDescriptors.includes(operationId) ? generatePostfix(contentType, responseType) : '';
|
|
7946
|
+
const ts = typescript(external_path_namespaceObject.resolve(_path, 'src', source, ...paths, camelCase(operationId), `use${pascalCase(operationId)}${postfix}.ts`));
|
|
7941
7947
|
const modifiedRequestUrl = `${requestUrl?.replace(/\{/g, "${")}`;
|
|
7942
7948
|
const imports = new Set();
|
|
7943
7949
|
imports.add(`import { z } from 'zod'`);
|
|
@@ -8119,8 +8125,9 @@ function download_template_extractErrorParams(errorTypes) {
|
|
|
8119
8125
|
const errorSchema = z.union([${errorTypes.map((a)=>`${a}Schema`).join(', ')}])`;
|
|
8120
8126
|
}
|
|
8121
8127
|
}
|
|
8122
|
-
async function reactDownloadHookTemplate({ source, data: { paths, operationId, response, requestUrl, variables, requestBody, contentType, responseType, errorResponses, method } }, _path) {
|
|
8123
|
-
const
|
|
8128
|
+
async function reactDownloadHookTemplate({ source, data: { paths, operationId, response, requestUrl, variables, requestBody, contentType, responseType, errorResponses, method } }, _path, ctx) {
|
|
8129
|
+
const postfix = ctx.potentiallyConflictingDescriptors.includes(operationId) ? generatePostfix(contentType, responseType) : '';
|
|
8130
|
+
const ts = typescript(external_path_namespaceObject.resolve(_path, 'src', source, ...paths, camelCase(operationId), `use${pascalCase(operationId)}${postfix}Download.ts`));
|
|
8124
8131
|
const modifiedRequestUrl = `${requestUrl?.replace(/\{/g, "${")}`;
|
|
8125
8132
|
const imports = new Set();
|
|
8126
8133
|
imports.add(`import { z } from 'zod'`);
|
|
@@ -8171,7 +8178,18 @@ async function reactDownloadHookTemplate({ source, data: { paths, operationId, r
|
|
|
8171
8178
|
useEffect(() => {
|
|
8172
8179
|
if (isSuccess(state)) {
|
|
8173
8180
|
let a = document.createElement('a');
|
|
8174
|
-
|
|
8181
|
+
const ct =
|
|
8182
|
+
state.headers?.['content-type'] ?? 'application/octet-stream';
|
|
8183
|
+
let data: any = state.data;
|
|
8184
|
+
if (ct.startsWith('application/json')) {
|
|
8185
|
+
let data: any[];
|
|
8186
|
+
if (ct.startsWith('application/json')) {
|
|
8187
|
+
data = [JSON.stringify(state.data, null, 2)];
|
|
8188
|
+
} else {
|
|
8189
|
+
data = [state.data];
|
|
8190
|
+
}
|
|
8191
|
+
}
|
|
8192
|
+
a.href = URL.createObjectURL(new Blob(Array.isArray(data) ? data : [data], {type: ct}));
|
|
8175
8193
|
const contentDisposition = state.headers?.['content-disposition'];
|
|
8176
8194
|
let filename = '${pascalCase(operationId)}.${external_mime_types_namespaceObject.extension(contentType)}';
|
|
8177
8195
|
if (contentDisposition) {
|
|
@@ -8251,6 +8269,7 @@ async function reactTypeTemplate({ typeName, schema, sourcePath, paths }) {
|
|
|
8251
8269
|
const { imports, zodSchema, tsType } = typeTemplate_openApiSchemaToZod(schema);
|
|
8252
8270
|
const ts = typescript(external_path_namespaceObject.resolve(sourcePath, 'src', ...paths, `${typeName}.ts`));
|
|
8253
8271
|
const simpleType = (await jsonLiteral('')`${JSON.stringify(schema)}`).content;
|
|
8272
|
+
const transport = schema.type === 'string' && schema.format === 'binary' ? 'binary' : 'json';
|
|
8254
8273
|
return ts`
|
|
8255
8274
|
import { z } from 'zod'
|
|
8256
8275
|
|
|
@@ -8272,6 +8291,9 @@ async function reactTypeTemplate({ typeName, schema, sourcePath, paths }) {
|
|
|
8272
8291
|
|
|
8273
8292
|
//--- Simple Type ---//
|
|
8274
8293
|
/*[${simpleType}]*/
|
|
8294
|
+
|
|
8295
|
+
// Transport hint for clients ("binary" => use arraybuffer/blob)
|
|
8296
|
+
export const ${typeName}_transport = '${transport}' as const;
|
|
8275
8297
|
`;
|
|
8276
8298
|
}
|
|
8277
8299
|
function typeTemplate_isRef(schema) {
|
|
@@ -8324,6 +8346,8 @@ function typeTemplate_handleRefSchema(ref, imports) {
|
|
|
8324
8346
|
};
|
|
8325
8347
|
}
|
|
8326
8348
|
function typeTemplate_handleStringSchema(schema) {
|
|
8349
|
+
const imports = new Set();
|
|
8350
|
+
let binaryish = false;
|
|
8327
8351
|
if (schema.enum) {
|
|
8328
8352
|
const enumValues = schema.enum.map((value)=>`'${value}'`).join(' | ');
|
|
8329
8353
|
const zodEnum = `z.enum([${schema.enum.map((value)=>`'${value}'`).join(', ')}])`;
|
|
@@ -8337,7 +8361,7 @@ function typeTemplate_handleStringSchema(schema) {
|
|
|
8337
8361
|
let tsType = 'string';
|
|
8338
8362
|
if (schema.format === 'date' && !schema.pattern) {
|
|
8339
8363
|
tsType = 'Date';
|
|
8340
|
-
zodSchema = 'z.date()';
|
|
8364
|
+
zodSchema = 'z.coerce.date()';
|
|
8341
8365
|
zodSchema += `.transform((val) => {
|
|
8342
8366
|
const parsedDate = new Date(val);
|
|
8343
8367
|
if (isNaN(parsedDate.getTime())) {
|
|
@@ -8361,11 +8385,15 @@ function typeTemplate_handleStringSchema(schema) {
|
|
|
8361
8385
|
return parsedDateTime;
|
|
8362
8386
|
})`;
|
|
8363
8387
|
} else if (schema.format === 'binary') {
|
|
8364
|
-
tsType = '
|
|
8365
|
-
zodSchema = '
|
|
8388
|
+
tsType = 'BinaryData';
|
|
8389
|
+
zodSchema = 'BinaryDataSchema';
|
|
8390
|
+
imports.add(`import { BinaryData, BinaryDataSchema } from '@intrig/react/type-utils'`);
|
|
8391
|
+
binaryish = true;
|
|
8366
8392
|
} else if (schema.format === 'byte') {
|
|
8367
|
-
tsType = '
|
|
8368
|
-
zodSchema = 'z.string().transform((val) =>
|
|
8393
|
+
tsType = 'Uint8Array';
|
|
8394
|
+
zodSchema = 'z.string().transform((val) => base64ToUint8Array(val))';
|
|
8395
|
+
imports.add(`import { base64ToUint8Array } from '@intrig/react/type-utils'`);
|
|
8396
|
+
binaryish = true;
|
|
8369
8397
|
} else if (schema.format === 'email') {
|
|
8370
8398
|
zodSchema = 'z.string().email()';
|
|
8371
8399
|
} else if (schema.format === 'uuid') {
|
|
@@ -8386,7 +8414,8 @@ function typeTemplate_handleStringSchema(schema) {
|
|
|
8386
8414
|
return {
|
|
8387
8415
|
tsType,
|
|
8388
8416
|
zodSchema,
|
|
8389
|
-
imports
|
|
8417
|
+
imports,
|
|
8418
|
+
binaryish
|
|
8390
8419
|
};
|
|
8391
8420
|
}
|
|
8392
8421
|
function typeTemplate_handleNumberSchema(schema) {
|
|
@@ -8418,21 +8447,21 @@ function typeTemplate_handleBooleanSchema() {
|
|
|
8418
8447
|
};
|
|
8419
8448
|
}
|
|
8420
8449
|
function typeTemplate_handleArraySchema(schema, imports) {
|
|
8421
|
-
if (schema.items) {
|
|
8422
|
-
|
|
8423
|
-
let zodSchema = `(z.preprocess((raw) => (Array.isArray(raw) ? raw : [raw]), z.array(${itemZodSchema})) as z.ZodType<${tsType}[], z.ZodTypeDef, ${tsType}[]>)`;
|
|
8424
|
-
if (schema.minItems !== undefined) zodSchema += `.min(${schema.minItems})`;
|
|
8425
|
-
if (schema.maxItems !== undefined) zodSchema += `.max(${schema.maxItems})`;
|
|
8426
|
-
return {
|
|
8427
|
-
tsType: `(${tsType})[]`,
|
|
8428
|
-
zodSchema,
|
|
8429
|
-
imports: new Set([
|
|
8430
|
-
...imports,
|
|
8431
|
-
...itemImports
|
|
8432
|
-
])
|
|
8433
|
-
};
|
|
8450
|
+
if (!schema.items) {
|
|
8451
|
+
throw new Error('Array schema must have an items property');
|
|
8434
8452
|
}
|
|
8435
|
-
|
|
8453
|
+
const { tsType, zodSchema: itemZodSchema, imports: itemImports, binaryish } = typeTemplate_openApiSchemaToZod(schema.items, imports);
|
|
8454
|
+
let zodSchema = binaryish ? `z.array(${itemZodSchema})` : `(z.preprocess((raw) => (Array.isArray(raw) ? raw : [raw]), z.array(${itemZodSchema})) as z.ZodType<${tsType}[], z.ZodTypeDef, ${tsType}[]>)`;
|
|
8455
|
+
if (schema.minItems !== undefined) zodSchema += `.min(${schema.minItems})`;
|
|
8456
|
+
if (schema.maxItems !== undefined) zodSchema += `.max(${schema.maxItems})`;
|
|
8457
|
+
return {
|
|
8458
|
+
tsType: `(${tsType})[]`,
|
|
8459
|
+
zodSchema,
|
|
8460
|
+
imports: new Set([
|
|
8461
|
+
...imports,
|
|
8462
|
+
...itemImports
|
|
8463
|
+
])
|
|
8464
|
+
};
|
|
8436
8465
|
}
|
|
8437
8466
|
function typeTemplate_handleObjectSchema(schema, imports) {
|
|
8438
8467
|
const updatedRequiredFields = schema.required || [];
|
|
@@ -9156,8 +9185,9 @@ function asyncFunctionHook_template_extractParamDeconstruction(variables, reques
|
|
|
9156
9185
|
}
|
|
9157
9186
|
}
|
|
9158
9187
|
}
|
|
9159
|
-
async function reactAsyncFunctionHookTemplate({ source, data: { paths, operationId, response, requestUrl, variables, requestBody, contentType, responseType, errorResponses, method } }, _path) {
|
|
9160
|
-
const
|
|
9188
|
+
async function reactAsyncFunctionHookTemplate({ source, data: { paths, operationId, response, requestUrl, variables, requestBody, contentType, responseType, errorResponses, method } }, _path, ctx) {
|
|
9189
|
+
const postfix = ctx.potentiallyConflictingDescriptors.includes(operationId) ? generatePostfix(contentType, responseType) : '';
|
|
9190
|
+
const ts = typescript(external_path_namespaceObject.resolve(_path, 'src', source, ...paths, camelCase(operationId), `use${pascalCase(operationId)}Async${postfix}.ts`));
|
|
9161
9191
|
const modifiedRequestUrl = `${requestUrl?.replace(/\{/g, "${")}`;
|
|
9162
9192
|
const imports = new Set();
|
|
9163
9193
|
// Basic imports
|
|
@@ -9333,6 +9363,49 @@ ${"```"}
|
|
|
9333
9363
|
`;
|
|
9334
9364
|
}
|
|
9335
9365
|
|
|
9366
|
+
;// ../../lib/react-binding/src/lib/templates/type-utils.template.ts
|
|
9367
|
+
|
|
9368
|
+
|
|
9369
|
+
function typeUtilsTemplate(_path) {
|
|
9370
|
+
const ts = typescript(external_path_default().resolve(_path, 'src', 'type-utils.ts'));
|
|
9371
|
+
return ts`import { z } from 'zod';
|
|
9372
|
+
|
|
9373
|
+
export type BinaryData = Blob | ArrayBuffer | Uint8Array;
|
|
9374
|
+
|
|
9375
|
+
export const BinaryDataSchema = z.union([
|
|
9376
|
+
// Blob in browsers
|
|
9377
|
+
z.instanceof(Blob).optional(), // optional here so union below still validates if Blob is absent in Node
|
|
9378
|
+
// Raw buffers
|
|
9379
|
+
z.instanceof(ArrayBuffer),
|
|
9380
|
+
z.custom<Uint8Array>((v) => v instanceof Uint8Array, { message: 'Expected Uint8Array' }),
|
|
9381
|
+
]).transform((v) => {
|
|
9382
|
+
// Normalize to Blob if possible (nice for downloads in browser)
|
|
9383
|
+
if (typeof Blob !== 'undefined') {
|
|
9384
|
+
if (v instanceof Blob) return v;
|
|
9385
|
+
if (v instanceof ArrayBuffer) return new Blob([v]);
|
|
9386
|
+
if (v instanceof Uint8Array) return new Blob([v.buffer]);
|
|
9387
|
+
}
|
|
9388
|
+
return v;
|
|
9389
|
+
});
|
|
9390
|
+
|
|
9391
|
+
// Base64 helpers (browser + Node compatible; no Buffer required)
|
|
9392
|
+
export function base64ToUint8Array(b64: string): Uint8Array {
|
|
9393
|
+
if (typeof atob === 'function') {
|
|
9394
|
+
// Browser
|
|
9395
|
+
const bin = atob(b64);
|
|
9396
|
+
const bytes = new Uint8Array(bin.length);
|
|
9397
|
+
for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i);
|
|
9398
|
+
return bytes;
|
|
9399
|
+
} else {
|
|
9400
|
+
// Node
|
|
9401
|
+
const buf = Buffer.from(b64, 'base64');
|
|
9402
|
+
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
9403
|
+
}
|
|
9404
|
+
}
|
|
9405
|
+
|
|
9406
|
+
`;
|
|
9407
|
+
}
|
|
9408
|
+
|
|
9336
9409
|
;// ../../lib/react-binding/src/lib/react-binding.service.ts
|
|
9337
9410
|
function react_binding_service_ts_decorate(decorators, target, key, desc) {
|
|
9338
9411
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -9367,12 +9440,14 @@ function react_binding_service_ts_metadata(k, v) {
|
|
|
9367
9440
|
|
|
9368
9441
|
|
|
9369
9442
|
|
|
9443
|
+
|
|
9370
9444
|
|
|
9371
9445
|
|
|
9372
9446
|
const react_binding_service_nonDownloadMimePatterns = external_picomatch_default()([
|
|
9373
9447
|
"application/json",
|
|
9374
9448
|
"application/xml",
|
|
9375
9449
|
"application/x-www-form-urlencoded",
|
|
9450
|
+
"application/event-stream",
|
|
9376
9451
|
"text/*"
|
|
9377
9452
|
]);
|
|
9378
9453
|
class ReactBindingService extends GeneratorBinding {
|
|
@@ -9391,12 +9466,18 @@ class ReactBindingService extends GeneratorBinding {
|
|
|
9391
9466
|
await this.dump(reactPackageJsonTemplate(this._path));
|
|
9392
9467
|
await this.dump(reactProviderTemplate(this._path, apisToSync));
|
|
9393
9468
|
await this.dump(reactTsConfigTemplate(this._path));
|
|
9469
|
+
await this.dump(typeUtilsTemplate(this._path));
|
|
9394
9470
|
}
|
|
9395
9471
|
async generateSource(descriptors, source) {
|
|
9472
|
+
//TODO improve this logic to catch potential conflicts.
|
|
9473
|
+
const potentiallyConflictingDescriptors = descriptors.filter(isRestDescriptor).sort((a, b)=>(a.data.contentType === "application/json" ? -1 : 0) - (b.data.contentType === "application/json" ? -1 : 0)).filter((descriptor, index, array)=>array.findIndex((other)=>other.data.operationId === descriptor.data.operationId) !== index).map((descriptor)=>descriptor.id);
|
|
9474
|
+
const ctx = {
|
|
9475
|
+
potentiallyConflictingDescriptors
|
|
9476
|
+
};
|
|
9396
9477
|
for (const descriptor of descriptors){
|
|
9397
|
-
this.logger.log(`Generating source: ${
|
|
9478
|
+
this.logger.log(`Generating source: ${descriptor.name}`);
|
|
9398
9479
|
if (isRestDescriptor(descriptor)) {
|
|
9399
|
-
await this.generateRestSource(source, descriptor);
|
|
9480
|
+
await this.generateRestSource(source, descriptor, ctx);
|
|
9400
9481
|
} else if (isSchemaDescriptor(descriptor)) {
|
|
9401
9482
|
await this.generateSchemaSource(source, descriptor);
|
|
9402
9483
|
}
|
|
@@ -9408,19 +9489,19 @@ class ReactBindingService extends GeneratorBinding {
|
|
|
9408
9489
|
postBuild() {
|
|
9409
9490
|
return Promise.resolve(undefined);
|
|
9410
9491
|
}
|
|
9411
|
-
async generateRestSource(source, descriptor) {
|
|
9492
|
+
async generateRestSource(source, descriptor, ctx) {
|
|
9412
9493
|
await this.dump(reactClientIndexTemplate([
|
|
9413
9494
|
descriptor
|
|
9414
|
-
], this._path));
|
|
9415
|
-
await this.dump(reactParamsTemplate(descriptor, this._path));
|
|
9416
|
-
await this.dump(reactRequestHookTemplate(descriptor, this._path));
|
|
9417
|
-
await this.dump(reactAsyncFunctionHookTemplate(descriptor, this._path));
|
|
9418
|
-
if (descriptor.data.method.toUpperCase() === 'GET' && !react_binding_service_nonDownloadMimePatterns(descriptor.data.responseType) || descriptor.data.responseHeaders?.['
|
|
9419
|
-
await this.dump(reactDownloadHookTemplate(descriptor, this._path));
|
|
9495
|
+
], this._path, ctx));
|
|
9496
|
+
await this.dump(reactParamsTemplate(descriptor, this._path, ctx));
|
|
9497
|
+
await this.dump(reactRequestHookTemplate(descriptor, this._path, ctx));
|
|
9498
|
+
await this.dump(reactAsyncFunctionHookTemplate(descriptor, this._path, ctx));
|
|
9499
|
+
if (descriptor.data.method.toUpperCase() === 'GET' && (!react_binding_service_nonDownloadMimePatterns(descriptor.data.responseType) || descriptor.data.responseType !== '*/*') || descriptor.data.responseHeaders?.['content-disposition']) {
|
|
9500
|
+
await this.dump(reactDownloadHookTemplate(descriptor, this._path, ctx));
|
|
9420
9501
|
}
|
|
9421
9502
|
}
|
|
9422
9503
|
async generateSchemaSource(source, descriptor) {
|
|
9423
|
-
|
|
9504
|
+
const content = reactTypeTemplate({
|
|
9424
9505
|
schema: descriptor.data.schema,
|
|
9425
9506
|
typeName: descriptor.data.name,
|
|
9426
9507
|
sourcePath: this._path,
|
|
@@ -9429,7 +9510,8 @@ class ReactBindingService extends GeneratorBinding {
|
|
|
9429
9510
|
"components",
|
|
9430
9511
|
"schemas"
|
|
9431
9512
|
]
|
|
9432
|
-
})
|
|
9513
|
+
});
|
|
9514
|
+
await this.dump(content);
|
|
9433
9515
|
}
|
|
9434
9516
|
async getSchemaDocumentation(result) {
|
|
9435
9517
|
const tsFile = external_fs_extra_default().readFileSync(`${this._path}/src/${result.source}/components/schemas/${result.data.name}.ts`, "utf8");
|
|
@@ -13738,7 +13820,7 @@ async function bootstrap() {
|
|
|
13738
13820
|
} else {
|
|
13739
13821
|
try {
|
|
13740
13822
|
await external_nest_commander_namespaceObject.CommandFactory.run(AppModule, {
|
|
13741
|
-
logger:
|
|
13823
|
+
logger: false,
|
|
13742
13824
|
errorHandler (err) {
|
|
13743
13825
|
if (err.code === 'commander.help') {
|
|
13744
13826
|
return process.exit(0);
|