vovk 3.0.0-draft.153 → 3.0.0-draft.154
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/cjs/client/createRPC.d.ts +1 -1
- package/cjs/client/createRPC.js +9 -4
- package/cjs/client/types.d.ts +1 -0
- package/cjs/types.d.ts +7 -9
- package/mjs/client/createRPC.d.ts +1 -1
- package/mjs/client/createRPC.js +9 -4
- package/mjs/client/types.d.ts +1 -0
- package/mjs/types.d.ts +7 -9
- package/package.json +1 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { KnownAny, VovkSchema } from '../types.js';
|
|
2
2
|
import type { VovkClientOptions, VovkClient, VovkDefaultFetcherOptions } from './types.js';
|
|
3
|
-
export declare const createRPC: <T, OPTS extends Record<string, KnownAny> = VovkDefaultFetcherOptions<Record<string, never>>>(schema: VovkSchema,
|
|
3
|
+
export declare const createRPC: <T, OPTS extends Record<string, KnownAny> = VovkDefaultFetcherOptions<Record<string, never>>>(schema: VovkSchema, givenSegmentName: string, rpcModuleName: string, options?: VovkClientOptions<OPTS>) => VovkClient<T, OPTS>;
|
package/cjs/client/createRPC.js
CHANGED
|
@@ -17,7 +17,8 @@ const getHandlerPath = (endpoint, params, query) => {
|
|
|
17
17
|
}
|
|
18
18
|
return `${result}${queryStr ? '?' : ''}${queryStr}`;
|
|
19
19
|
};
|
|
20
|
-
const createRPC = (schema,
|
|
20
|
+
const createRPC = (schema, givenSegmentName, rpcModuleName, options) => {
|
|
21
|
+
const segmentName = options?.segmentNameOverride ?? givenSegmentName;
|
|
21
22
|
const segmentSchema = schema.segments[segmentName];
|
|
22
23
|
if (!segmentSchema)
|
|
23
24
|
throw new Error(`Unable to create RPC object. Segment schema is missing. Check client template.`);
|
|
@@ -30,9 +31,13 @@ const createRPC = (schema, segmentName, rpcModuleName, options) => {
|
|
|
30
31
|
for (const [staticMethodName, handlerSchema] of Object.entries(controllerSchema.handlers)) {
|
|
31
32
|
const { path, httpMethod, validation } = handlerSchema;
|
|
32
33
|
const getEndpoint = ({ apiRoot, params, query, }) => {
|
|
33
|
-
const mainPrefix =
|
|
34
|
-
(apiRoot.
|
|
35
|
-
|
|
34
|
+
const mainPrefix = [
|
|
35
|
+
apiRoot.startsWith('http://') || apiRoot.startsWith('https://') || apiRoot.startsWith('/') ? '' : '/',
|
|
36
|
+
apiRoot,
|
|
37
|
+
segmentName,
|
|
38
|
+
]
|
|
39
|
+
.filter(Boolean)
|
|
40
|
+
.join('/');
|
|
36
41
|
return mainPrefix + getHandlerPath([controllerPrefix, path].filter(Boolean).join('/'), params, query);
|
|
37
42
|
};
|
|
38
43
|
const handler = (input = {}) => {
|
package/cjs/client/types.d.ts
CHANGED
|
@@ -109,6 +109,7 @@ export type VovkValidateOnClient = (input: {
|
|
|
109
109
|
export type VovkClientOptions<OPTS extends Record<string, KnownAny> = Record<string, never>> = {
|
|
110
110
|
fetcher?: VovkClientFetcher<OPTS>;
|
|
111
111
|
validateOnClient?: VovkValidateOnClient;
|
|
112
|
+
segmentNameOverride?: string;
|
|
112
113
|
defaultOptions?: Partial<OPTS>;
|
|
113
114
|
};
|
|
114
115
|
export {};
|
package/cjs/types.d.ts
CHANGED
|
@@ -215,16 +215,18 @@ type BundleConfig = {
|
|
|
215
215
|
excludeSegments?: string[];
|
|
216
216
|
includeSegments?: never;
|
|
217
217
|
});
|
|
218
|
+
type SegmentConfig = Record<string, {
|
|
219
|
+
origin?: string;
|
|
220
|
+
rootEntry?: string;
|
|
221
|
+
segmentNameOverride?: string;
|
|
222
|
+
}>;
|
|
218
223
|
export type ClientTemplateDef = {
|
|
219
224
|
extends?: string;
|
|
220
225
|
templatePath?: string | null;
|
|
221
226
|
origin?: string | null;
|
|
222
227
|
composedClient?: Omit<ClientConfigFull, 'fromTemplates' | 'enabled'>;
|
|
223
228
|
segmentedClient?: Omit<ClientConfigSegmented, 'fromTemplates' | 'enabled'>;
|
|
224
|
-
segmentConfig?: false |
|
|
225
|
-
origin?: string;
|
|
226
|
-
rootEntry?: string;
|
|
227
|
-
}>;
|
|
229
|
+
segmentConfig?: false | SegmentConfig;
|
|
228
230
|
requires?: Record<string, string>;
|
|
229
231
|
};
|
|
230
232
|
type VovkUserConfig = {
|
|
@@ -253,11 +255,7 @@ type VovkUserConfig = {
|
|
|
253
255
|
[key: string]: string | undefined;
|
|
254
256
|
};
|
|
255
257
|
libs?: Record<string, KnownAny>;
|
|
256
|
-
|
|
257
|
-
segmentConfig?: false | Record<string, {
|
|
258
|
-
origin?: string;
|
|
259
|
-
rootEntry?: string;
|
|
260
|
-
}>;
|
|
258
|
+
segmentConfig?: false | SegmentConfig;
|
|
261
259
|
};
|
|
262
260
|
export type VovkConfig = VovkUserConfig & {
|
|
263
261
|
[key: string]: KnownAny;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { KnownAny, VovkSchema } from '../types.js';
|
|
2
2
|
import type { VovkClientOptions, VovkClient, VovkDefaultFetcherOptions } from './types.js';
|
|
3
|
-
export declare const createRPC: <T, OPTS extends Record<string, KnownAny> = VovkDefaultFetcherOptions<Record<string, never>>>(schema: VovkSchema,
|
|
3
|
+
export declare const createRPC: <T, OPTS extends Record<string, KnownAny> = VovkDefaultFetcherOptions<Record<string, never>>>(schema: VovkSchema, givenSegmentName: string, rpcModuleName: string, options?: VovkClientOptions<OPTS>) => VovkClient<T, OPTS>;
|
package/mjs/client/createRPC.js
CHANGED
|
@@ -17,7 +17,8 @@ const getHandlerPath = (endpoint, params, query) => {
|
|
|
17
17
|
}
|
|
18
18
|
return `${result}${queryStr ? '?' : ''}${queryStr}`;
|
|
19
19
|
};
|
|
20
|
-
const createRPC = (schema,
|
|
20
|
+
const createRPC = (schema, givenSegmentName, rpcModuleName, options) => {
|
|
21
|
+
const segmentName = options?.segmentNameOverride ?? givenSegmentName;
|
|
21
22
|
const segmentSchema = schema.segments[segmentName];
|
|
22
23
|
if (!segmentSchema)
|
|
23
24
|
throw new Error(`Unable to create RPC object. Segment schema is missing. Check client template.`);
|
|
@@ -30,9 +31,13 @@ const createRPC = (schema, segmentName, rpcModuleName, options) => {
|
|
|
30
31
|
for (const [staticMethodName, handlerSchema] of Object.entries(controllerSchema.handlers)) {
|
|
31
32
|
const { path, httpMethod, validation } = handlerSchema;
|
|
32
33
|
const getEndpoint = ({ apiRoot, params, query, }) => {
|
|
33
|
-
const mainPrefix =
|
|
34
|
-
(apiRoot.
|
|
35
|
-
|
|
34
|
+
const mainPrefix = [
|
|
35
|
+
apiRoot.startsWith('http://') || apiRoot.startsWith('https://') || apiRoot.startsWith('/') ? '' : '/',
|
|
36
|
+
apiRoot,
|
|
37
|
+
segmentName,
|
|
38
|
+
]
|
|
39
|
+
.filter(Boolean)
|
|
40
|
+
.join('/');
|
|
36
41
|
return mainPrefix + getHandlerPath([controllerPrefix, path].filter(Boolean).join('/'), params, query);
|
|
37
42
|
};
|
|
38
43
|
const handler = (input = {}) => {
|
package/mjs/client/types.d.ts
CHANGED
|
@@ -109,6 +109,7 @@ export type VovkValidateOnClient = (input: {
|
|
|
109
109
|
export type VovkClientOptions<OPTS extends Record<string, KnownAny> = Record<string, never>> = {
|
|
110
110
|
fetcher?: VovkClientFetcher<OPTS>;
|
|
111
111
|
validateOnClient?: VovkValidateOnClient;
|
|
112
|
+
segmentNameOverride?: string;
|
|
112
113
|
defaultOptions?: Partial<OPTS>;
|
|
113
114
|
};
|
|
114
115
|
export {};
|
package/mjs/types.d.ts
CHANGED
|
@@ -215,16 +215,18 @@ type BundleConfig = {
|
|
|
215
215
|
excludeSegments?: string[];
|
|
216
216
|
includeSegments?: never;
|
|
217
217
|
});
|
|
218
|
+
type SegmentConfig = Record<string, {
|
|
219
|
+
origin?: string;
|
|
220
|
+
rootEntry?: string;
|
|
221
|
+
segmentNameOverride?: string;
|
|
222
|
+
}>;
|
|
218
223
|
export type ClientTemplateDef = {
|
|
219
224
|
extends?: string;
|
|
220
225
|
templatePath?: string | null;
|
|
221
226
|
origin?: string | null;
|
|
222
227
|
composedClient?: Omit<ClientConfigFull, 'fromTemplates' | 'enabled'>;
|
|
223
228
|
segmentedClient?: Omit<ClientConfigSegmented, 'fromTemplates' | 'enabled'>;
|
|
224
|
-
segmentConfig?: false |
|
|
225
|
-
origin?: string;
|
|
226
|
-
rootEntry?: string;
|
|
227
|
-
}>;
|
|
229
|
+
segmentConfig?: false | SegmentConfig;
|
|
228
230
|
requires?: Record<string, string>;
|
|
229
231
|
};
|
|
230
232
|
type VovkUserConfig = {
|
|
@@ -253,11 +255,7 @@ type VovkUserConfig = {
|
|
|
253
255
|
[key: string]: string | undefined;
|
|
254
256
|
};
|
|
255
257
|
libs?: Record<string, KnownAny>;
|
|
256
|
-
|
|
257
|
-
segmentConfig?: false | Record<string, {
|
|
258
|
-
origin?: string;
|
|
259
|
-
rootEntry?: string;
|
|
260
|
-
}>;
|
|
258
|
+
segmentConfig?: false | SegmentConfig;
|
|
261
259
|
};
|
|
262
260
|
export type VovkConfig = VovkUserConfig & {
|
|
263
261
|
[key: string]: KnownAny;
|