@vrplatform/api 1.3.1-1368 → 1.3.1-1419
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/build/main/cache.d.ts +2 -5
- package/build/main/cache.js.map +1 -1
- package/build/main/error.js +3 -3
- package/build/main/error.js.map +1 -1
- package/build/main/generated/v1.d.ts +21498 -15969
- package/build/main/generated/v1.js.map +1 -1
- package/build/main/types.d.ts +8 -13
- package/build/main/types.js.map +1 -1
- package/build/module/cache.d.ts +2 -5
- package/build/module/cache.js.map +1 -1
- package/build/module/error.js +3 -3
- package/build/module/error.js.map +1 -1
- package/build/module/generated/v1.d.ts +21498 -15969
- package/build/module/generated/v1.js.map +1 -1
- package/build/module/types.d.ts +8 -13
- package/build/module/types.js.map +1 -1
- package/package.json +1 -2
- package/src/cache.ts +2 -2
- package/src/error.ts +4 -3
- package/src/generated/v1.ts +21498 -15969
- package/src/types.ts +14 -14
package/build/main/types.d.ts
CHANGED
|
@@ -33,22 +33,17 @@ export type ResponseData<T extends ResponseCombinations> = T extends `${infer Me
|
|
|
33
33
|
} ? Data : never : never : never : never;
|
|
34
34
|
type RequestBodyCombinations = {
|
|
35
35
|
[Path in keyof paths]: {
|
|
36
|
-
[Method in keyof paths[Path]]: paths[Path][Method] extends never ? never : paths[Path][Method] extends {
|
|
37
|
-
requestBody: {
|
|
38
|
-
content: {
|
|
39
|
-
'application/json': unknown;
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
} ? `${Method & string}:${Path}` : never;
|
|
36
|
+
[Method in keyof paths[Path]]: paths[Path][Method] extends never ? never : ExtractJsonRequestBody<paths[Path][Method]> extends never ? never : `${Method & string}:${Path}`;
|
|
43
37
|
}[keyof paths[Path]];
|
|
44
38
|
}[keyof paths];
|
|
45
|
-
|
|
46
|
-
requestBody
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
39
|
+
type ExtractJsonRequestBody<T> = T extends {
|
|
40
|
+
requestBody?: infer RequestBody;
|
|
41
|
+
} ? RequestBody extends {
|
|
42
|
+
content: {
|
|
43
|
+
'application/json': infer Data;
|
|
50
44
|
};
|
|
51
|
-
} ? Data : never : never
|
|
45
|
+
} ? Data : never : never;
|
|
46
|
+
export type RequestBody<T extends RequestBodyCombinations> = T extends `${infer Method}:${infer Path}` ? Path extends keyof paths ? Method extends keyof paths[Path] ? ExtractJsonRequestBody<paths[Path][Method]> : never : never : never;
|
|
52
47
|
type RequestParamCombinations = {
|
|
53
48
|
[Path in keyof paths]: {
|
|
54
49
|
[Method in keyof paths[Path]]: paths[Path][Method] extends never ? never : paths[Path][Method] extends {
|
package/build/main/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"src/","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["import type createClient from 'openapi-fetch';\nimport type { paths } from './generated/v1';\n\nexport type ApiClientAuth = {\n apiKey?: string;\n sec?: string;\n tenantId?: string;\n accessToken?: string;\n};\nexport type ApiClient = ReturnType<typeof createClient<paths>> & {\n sessionId: string;\n};\ntype ResponseCombinations = {\n [Path in keyof paths]: {\n [Method in keyof paths[Path]]: paths[Path][Method] extends never\n ? never\n : paths[Path][Method] extends {\n responses: {\n 200: { content: { 'application/json': unknown } };\n };\n }\n ? `${Method & string}:${Path}`\n : never;\n }[keyof paths[Path]];\n}[keyof paths];\n\nexport type ResponseData<T extends ResponseCombinations> =\n T extends `${infer Method}:${infer Path}`\n ? Path extends keyof paths\n ? Method extends keyof paths[Path]\n ? paths[Path][Method] extends {\n responses: {\n 200: { content: { 'application/json': infer Data } };\n };\n }\n ? Data\n : never\n : never\n : never\n : never;\n\ntype RequestBodyCombinations = {\n [Path in keyof paths]: {\n [Method in keyof paths[Path]]: paths[Path][Method] extends never\n ? never\n : paths[Path][Method] extends
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"src/","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["import type createClient from 'openapi-fetch';\nimport type { paths } from './generated/v1';\n\nexport type ApiClientAuth = {\n apiKey?: string;\n sec?: string;\n tenantId?: string;\n accessToken?: string;\n};\nexport type ApiClient = ReturnType<typeof createClient<paths>> & {\n sessionId: string;\n};\ntype ResponseCombinations = {\n [Path in keyof paths]: {\n [Method in keyof paths[Path]]: paths[Path][Method] extends never\n ? never\n : paths[Path][Method] extends {\n responses: {\n 200: { content: { 'application/json': unknown } };\n };\n }\n ? `${Method & string}:${Path}`\n : never;\n }[keyof paths[Path]];\n}[keyof paths];\n\nexport type ResponseData<T extends ResponseCombinations> =\n T extends `${infer Method}:${infer Path}`\n ? Path extends keyof paths\n ? Method extends keyof paths[Path]\n ? paths[Path][Method] extends {\n responses: {\n 200: { content: { 'application/json': infer Data } };\n };\n }\n ? Data\n : never\n : never\n : never\n : never;\n\ntype RequestBodyCombinations = {\n [Path in keyof paths]: {\n [Method in keyof paths[Path]]: paths[Path][Method] extends never\n ? never\n : ExtractJsonRequestBody<paths[Path][Method]> extends never\n ? never\n : `${Method & string}:${Path}`;\n }[keyof paths[Path]];\n}[keyof paths];\n\ntype ExtractJsonRequestBody<T> = T extends {\n requestBody?: infer RequestBody;\n}\n ? RequestBody extends {\n content: { 'application/json': infer Data };\n }\n ? Data\n : never\n : never;\n\nexport type RequestBody<T extends RequestBodyCombinations> =\n T extends `${infer Method}:${infer Path}`\n ? Path extends keyof paths\n ? Method extends keyof paths[Path]\n ? ExtractJsonRequestBody<paths[Path][Method]>\n : never\n : never\n : never;\n\ntype RequestParamCombinations = {\n [Path in keyof paths]: {\n [Method in keyof paths[Path]]: paths[Path][Method] extends never\n ? never\n : paths[Path][Method] extends {\n parameters: {\n query?: Record<string, unknown>;\n };\n }\n ? `${Method & string}:${Path}`\n : never;\n }[keyof paths[Path]];\n}[keyof paths];\n\nexport type RequestQuery<T extends RequestParamCombinations> =\n T extends `${infer Method}:${infer Path}`\n ? Path extends keyof paths\n ? Method extends keyof paths[Path]\n ? paths[Path][Method] extends {\n parameters: {\n query?: infer Data;\n };\n }\n ? Data\n : never\n : never\n : never\n : never;\n"]}
|
package/build/module/cache.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
value: T;
|
|
3
|
-
expiresAt: number;
|
|
4
|
-
};
|
|
5
|
-
export type CacheResult<T, A> = {
|
|
1
|
+
type CacheResult<T, A> = {
|
|
6
2
|
current: (arg: A) => Promise<T>;
|
|
7
3
|
invalidate: () => void;
|
|
8
4
|
};
|
|
9
5
|
export declare function useCache<T, A>(fetchFn: (arg: A) => Promise<T>, expiryTimeMs: number): CacheResult<T, A>;
|
|
6
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"src/","sources":["cache.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,QAAQ,CACtB,OAA+B,EAC/B,YAAoB;IAEpB,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAyB,CAAC;IAClD,MAAM,aAAa,GAAG,IAAI,GAAG,EAAsB,CAAC;IAEpD,MAAM,cAAc,GAAG,KAAK,EAAE,GAAM,EAAc,EAAE;QAClD,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACrC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAEvB,yCAAyC;QACzC,MAAM,WAAW,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC3C,IAAI,WAAW,IAAI,GAAG,IAAI,WAAW,CAAC,SAAS,EAAE,CAAC;YAChD,OAAO,WAAW,CAAC,KAAK,CAAC;QAC3B,CAAC;QAED,0EAA0E;QAC1E,MAAM,eAAe,GAAG,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACpD,IAAI,eAAe;YAAE,OAAO,eAAe,CAAC;QAE5C,kBAAkB;QAClB,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,C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,CAAC,CAAC;QACpD,IAAI,eAAe;YAAE,OAAO,eAAe,CAAC;QAE5C,kBAAkB;QAClB,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;YAC7B,aAAa,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAErC,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC;YACjC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE;gBACrB,KAAK,EAAE,UAAU;gBACjB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,YAAY;aACrC,CAAC,CAAC;YAEH,OAAO,UAAU,CAAC;QACpB,CAAC;gBAAS,CAAC;YACT,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACjC,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,UAAU,EAAE,GAAG,EAAE;YACf,QAAQ,CAAC,KAAK,EAAE,CAAC;YACjB,aAAa,CAAC,KAAK,EAAE,CAAC;QACxB,CAAC;QACD,OAAO,EAAE,cAAc;KACxB,CAAC;AACJ,CAAC","sourcesContent":["type CacheEntry<T> = {\n value: T;\n expiresAt: number;\n};\n\ntype CacheResult<T, A> = {\n current: (arg: A) => Promise<T>;\n invalidate: () => void;\n};\n\nexport function useCache<T, A>(\n fetchFn: (arg: A) => Promise<T>,\n expiryTimeMs: number\n): CacheResult<T, A> {\n const cacheMap = new Map<string, CacheEntry<T>>();\n const fetchPromises = new Map<string, Promise<T>>();\n\n const getCachedValue = async (arg: A): Promise<T> => {\n const cacheKey = JSON.stringify(arg);\n const now = Date.now();\n\n // If cache is valid, return cached value\n const cachedEntry = cacheMap.get(cacheKey);\n if (cachedEntry && now <= cachedEntry.expiresAt) {\n return cachedEntry.value;\n }\n\n // If there's already a fetch in progress for this key, return its promise\n const existingPromise = fetchPromises.get(cacheKey);\n if (existingPromise) return existingPromise;\n\n // Start new fetch\n try {\n const promise = fetchFn(arg);\n fetchPromises.set(cacheKey, promise);\n\n const freshValue = await promise;\n cacheMap.set(cacheKey, {\n value: freshValue,\n expiresAt: Date.now() + expiryTimeMs,\n });\n\n return freshValue;\n } finally {\n fetchPromises.delete(cacheKey);\n }\n };\n\n return {\n invalidate: () => {\n cacheMap.clear();\n fetchPromises.clear();\n },\n current: getCachedValue,\n };\n}\n"]}
|
package/build/module/error.js
CHANGED
|
@@ -5,8 +5,8 @@ export class ApiClientError extends Error {
|
|
|
5
5
|
issues;
|
|
6
6
|
context;
|
|
7
7
|
constructor(error) {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const message = error.message ||
|
|
9
|
+
[
|
|
10
10
|
error.code,
|
|
11
11
|
error.issues
|
|
12
12
|
?.map((x) => [x.message, x.path?.join('->')]
|
|
@@ -16,7 +16,7 @@ export class ApiClientError extends Error {
|
|
|
16
16
|
]
|
|
17
17
|
.filter(hasValue)
|
|
18
18
|
.join(': ');
|
|
19
|
-
super(
|
|
19
|
+
super(message);
|
|
20
20
|
this.error = error;
|
|
21
21
|
this.code = error.code;
|
|
22
22
|
this.issues = error.issues || [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"src/","sources":["error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAY7C,MAAM,OAAO,cAAe,SAAQ,KAAK;IAMpB;IALnB,IAAI,CAAS;IACb,MAAM,CAEF;IACJ,OAAO,CAAM;IACb,YAAmB,KAAQ;QACzB,
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"src/","sources":["error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAY7C,MAAM,OAAO,cAAe,SAAQ,KAAK;IAMpB;IALnB,IAAI,CAAS;IACb,MAAM,CAEF;IACJ,OAAO,CAAM;IACb,YAAmB,KAAQ;QACzB,MAAM,OAAO,GACX,KAAK,CAAC,OAAO;YACb;gBACE,KAA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I,KAAK;QAAE,MAAM,IAAI,cAAc,CAAC,KAAK,CAAC,CAAC;IAC3C,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB,CAAC","sourcesContent":["import { hasValue } from '@vrplatform/utils';\nimport type { FetchResponse } from './generated/openapi-fetch';\n\ntype E = {\n code: string;\n message: string;\n issues?: {\n message: string;\n }[];\n context?: any;\n stack?: any;\n};\nexport class ApiClientError extends Error {\n code: string;\n issues: {\n message: string;\n }[];\n context: any;\n constructor(public error: E) {\n const message =\n error.message ||\n [\n error.code,\n error.issues\n ?.map((x) =>\n [x.message, (x as any).path?.join('->')]\n .filter(hasValue)\n .join(' on ')\n )\n .join(', '),\n ]\n .filter(hasValue)\n .join(': ');\n super(message);\n\n this.code = error.code;\n this.issues = error.issues || [];\n this.context = error.context || {};\n if (error.stack) this.stack = error.stack;\n }\n}\nexport function throwIfError<T extends FetchResponse<any, any, any>>(\n response: T\n): NonNullable<T['data']>;\nexport function throwIfError<T extends FetchResponse<any, any, any>>(\n response: Promise<T>\n): Promise<NonNullable<T['data']>>;\nexport function throwIfError<T extends FetchResponse<any, any, any>>(\n response: Promise<T> | T\n): Promise<NonNullable<T['data']>> | NonNullable<T['data']> {\n if (response instanceof Promise) {\n return response.then((response) => {\n if (response.response.status === 503) {\n throw new Error('Worker resources exceeded.');\n }\n\n const error: E = response.error;\n\n if (error) throw new ApiClientError(error);\n return response.data;\n });\n }\n\n const error: E = response.error;\n\n if (error) throw new ApiClientError(error);\n return response.data;\n}\n"]}
|