@bsb/base 9.0.5 → 9.1.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.
- package/lib/base/BSBConfig.d.ts +3 -3
- package/lib/base/BSBConfig.js +9 -14
- package/lib/base/BSBConfig.js.map +1 -1
- package/lib/base/BSBEvents.d.ts +3 -3
- package/lib/base/BSBEvents.js +12 -17
- package/lib/base/BSBEvents.js.map +1 -1
- package/lib/base/BSBObservable.d.ts +4 -4
- package/lib/base/BSBObservable.js +17 -22
- package/lib/base/BSBObservable.js.map +1 -1
- package/lib/base/BSBService.d.ts +7 -8
- package/lib/base/BSBService.js +17 -22
- package/lib/base/BSBService.js.map +1 -1
- package/lib/base/BSBServiceClient.d.ts +4 -4
- package/lib/base/BSBServiceClient.js +12 -18
- package/lib/base/BSBServiceClient.js.map +1 -1
- package/lib/base/EventValidator.d.ts +16 -17
- package/lib/base/EventValidator.js +13 -34
- package/lib/base/EventValidator.js.map +1 -1
- package/lib/base/ObservableBackend.d.ts +2 -2
- package/lib/base/ObservableBackend.js +21 -26
- package/lib/base/ObservableBackend.js.map +1 -1
- package/lib/base/PluginConfig.d.ts +9 -5
- package/lib/base/PluginConfig.js +4 -11
- package/lib/base/PluginConfig.js.map +1 -1
- package/lib/base/PluginEvents.d.ts +4 -4
- package/lib/base/PluginEvents.js +4 -9
- package/lib/base/PluginEvents.js.map +1 -1
- package/lib/base/PluginObservable.d.ts +13 -14
- package/lib/base/PluginObservable.js +4 -8
- package/lib/base/PluginObservable.js.map +1 -1
- package/lib/base/ResourceContext.d.ts +1 -1
- package/lib/base/ResourceContext.js +1 -5
- package/lib/base/ResourceContext.js.map +1 -1
- package/lib/base/base.d.ts +3 -3
- package/lib/base/base.js +10 -18
- package/lib/base/base.js.map +1 -1
- package/lib/base/errorMessages.d.ts +1 -1
- package/lib/base/errorMessages.js +6 -11
- package/lib/base/errorMessages.js.map +1 -1
- package/lib/base/factory.d.ts +1 -1
- package/lib/base/factory.js +19 -22
- package/lib/base/factory.js.map +1 -1
- package/lib/base/functions.d.ts +19 -14
- package/lib/base/functions.js +19 -26
- package/lib/base/functions.js.map +1 -1
- package/lib/base/index.d.ts +18 -18
- package/lib/base/index.js +18 -37
- package/lib/base/index.js.map +1 -1
- package/lib/base/logFormatter.d.ts +1 -1
- package/lib/base/logFormatter.js +10 -14
- package/lib/base/logFormatter.js.map +1 -1
- package/lib/base/module-runtime.d.ts +3 -0
- package/lib/base/module-runtime.js +15 -0
- package/lib/base/module-runtime.js.map +1 -0
- package/lib/base/tools.d.ts +1 -1
- package/lib/base/tools.js +9 -13
- package/lib/base/tools.js.map +1 -1
- package/lib/cli.js +13 -12
- package/lib/cli.js.map +1 -1
- package/lib/dev.js +22 -11
- package/lib/dev.js.map +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.js +3 -19
- package/lib/index.js.map +1 -1
- package/lib/interfaces/events.d.ts +2 -2
- package/lib/interfaces/events.js +1 -4
- package/lib/interfaces/events.js.map +1 -1
- package/lib/interfaces/index.d.ts +13 -12
- package/lib/interfaces/index.js +12 -32
- package/lib/interfaces/index.js.map +1 -1
- package/lib/interfaces/logging.d.ts +3 -3
- package/lib/interfaces/logging.js +1 -4
- package/lib/interfaces/logging.js.map +1 -1
- package/lib/interfaces/metrics.d.ts +2 -2
- package/lib/interfaces/metrics.js +1 -5
- package/lib/interfaces/metrics.js.map +1 -1
- package/lib/interfaces/observable-types.d.ts +1 -1
- package/lib/interfaces/observable-types.js +1 -4
- package/lib/interfaces/observable-types.js.map +1 -1
- package/lib/interfaces/observable.d.ts +8 -9
- package/lib/interfaces/observable.js +1 -2
- package/lib/interfaces/observable.js.map +1 -1
- package/lib/interfaces/options.d.ts +15 -6
- package/lib/interfaces/options.js +2 -5
- package/lib/interfaces/options.js.map +1 -1
- package/lib/interfaces/plugins.d.ts +2 -2
- package/lib/interfaces/plugins.js +1 -4
- package/lib/interfaces/plugins.js.map +1 -1
- package/lib/interfaces/result.js +8 -18
- package/lib/interfaces/result.js.map +1 -1
- package/lib/interfaces/schema-events.d.ts +4 -19
- package/lib/interfaces/schema-events.js +6 -13
- package/lib/interfaces/schema-events.js.map +1 -1
- package/lib/interfaces/schema-types.d.ts +32 -352
- package/lib/interfaces/schema-types.js +77 -512
- package/lib/interfaces/schema-types.js.map +1 -1
- package/lib/interfaces/service.d.ts +1 -1
- package/lib/interfaces/service.js +1 -2
- package/lib/interfaces/service.js.map +1 -1
- package/lib/interfaces/tools.js +8 -13
- package/lib/interfaces/tools.js.map +1 -1
- package/lib/plugins/config-default/index.d.ts +16 -14
- package/lib/plugins/config-default/index.js +66 -49
- package/lib/plugins/config-default/index.js.map +1 -1
- package/lib/plugins/config-default/interfaces.d.ts +1 -1
- package/lib/plugins/config-default/interfaces.js +1 -2
- package/lib/plugins/config-default/interfaces.js.map +1 -1
- package/lib/plugins/events-default/events/broadcast.d.ts +1 -1
- package/lib/plugins/events-default/events/broadcast.js +2 -6
- package/lib/plugins/events-default/events/broadcast.js.map +1 -1
- package/lib/plugins/events-default/events/emit.d.ts +1 -1
- package/lib/plugins/events-default/events/emit.js +4 -8
- package/lib/plugins/events-default/events/emit.js.map +1 -1
- package/lib/plugins/events-default/events/emitAndReturn.d.ts +1 -1
- package/lib/plugins/events-default/events/emitAndReturn.js +4 -8
- package/lib/plugins/events-default/events/emitAndReturn.js.map +1 -1
- package/lib/plugins/events-default/events/emitStreamAndReceiveStream.d.ts +1 -1
- package/lib/plugins/events-default/events/emitStreamAndReceiveStream.js +8 -12
- package/lib/plugins/events-default/events/emitStreamAndReceiveStream.js.map +1 -1
- package/lib/plugins/events-default/events/index.d.ts +4 -4
- package/lib/plugins/events-default/events/index.js +4 -11
- package/lib/plugins/events-default/events/index.js.map +1 -1
- package/lib/plugins/events-default/index.d.ts +5 -5
- package/lib/plugins/events-default/index.js +10 -14
- package/lib/plugins/events-default/index.js.map +1 -1
- package/lib/plugins/observable-default/index.d.ts +5 -5
- package/lib/plugins/observable-default/index.js +8 -12
- package/lib/plugins/observable-default/index.js.map +1 -1
- package/lib/plugins/service-benchmarkify/index.d.ts +69 -185
- package/lib/plugins/service-benchmarkify/index.js +39 -43
- package/lib/plugins/service-benchmarkify/index.js.map +1 -1
- package/lib/plugins/service-default0/index.d.ts +73 -171
- package/lib/plugins/service-default0/index.js +36 -40
- package/lib/plugins/service-default0/index.js.map +1 -1
- package/lib/plugins/service-default1/client.d.ts +3 -3
- package/lib/plugins/service-default1/client.js +2 -6
- package/lib/plugins/service-default1/client.js.map +1 -1
- package/lib/plugins/service-default1/index.d.ts +75 -177
- package/lib/plugins/service-default1/index.js +41 -45
- package/lib/plugins/service-default1/index.js.map +1 -1
- package/lib/plugins/service-default2/index.d.ts +89 -231
- package/lib/plugins/service-default2/index.js +47 -51
- package/lib/plugins/service-default2/index.js.map +1 -1
- package/lib/plugins/service-default3/index.d.ts +23 -51
- package/lib/plugins/service-default3/index.js +16 -20
- package/lib/plugins/service-default3/index.js.map +1 -1
- package/lib/plugins/service-default4/index.d.ts +13 -27
- package/lib/plugins/service-default4/index.js +12 -16
- package/lib/plugins/service-default4/index.js.map +1 -1
- package/lib/schemas/config-default.json +24 -16
- package/lib/schemas/config-default.plugin.json +24 -16
- package/lib/schemas/events-default.json +1 -1
- package/lib/schemas/events-default.plugin.json +1 -1
- package/lib/schemas/observable-default.json +15 -5
- package/lib/schemas/observable-default.plugin.json +15 -5
- package/lib/schemas/service-benchmarkify.json +232 -147
- package/lib/schemas/service-default0.json +205 -142
- package/lib/schemas/service-default1.json +245 -160
- package/lib/schemas/service-default2.json +270 -183
- package/lib/schemas/service-default3.json +78 -36
- package/lib/schemas/service-default4.json +45 -15
- package/lib/scripts/bsb-client-cli.js +9 -9
- package/lib/scripts/bsb-client-cli.js.map +1 -1
- package/lib/scripts/bsb-plugin-cli.js +48 -50
- package/lib/scripts/bsb-plugin-cli.js.map +1 -1
- package/lib/scripts/export-schemas.js +8 -10
- package/lib/scripts/export-schemas.js.map +1 -1
- package/lib/scripts/extract-schemas-from-source.js +73 -56
- package/lib/scripts/extract-schemas-from-source.js.map +1 -1
- package/lib/scripts/generate-client-types.d.ts +1 -16
- package/lib/scripts/generate-client-types.js +120 -313
- package/lib/scripts/generate-client-types.js.map +1 -1
- package/lib/scripts/generate-plugin-json.js +9 -10
- package/lib/scripts/generate-plugin-json.js.map +1 -1
- package/lib/serviceBase/config.d.ts +4 -4
- package/lib/serviceBase/config.js +33 -35
- package/lib/serviceBase/config.js.map +1 -1
- package/lib/serviceBase/events.d.ts +6 -6
- package/lib/serviceBase/events.js +42 -44
- package/lib/serviceBase/events.js.map +1 -1
- package/lib/serviceBase/index.d.ts +7 -7
- package/lib/serviceBase/index.js +7 -23
- package/lib/serviceBase/index.js.map +1 -1
- package/lib/serviceBase/observable.d.ts +5 -5
- package/lib/serviceBase/observable.js +21 -25
- package/lib/serviceBase/observable.js.map +1 -1
- package/lib/serviceBase/plugins.d.ts +3 -3
- package/lib/serviceBase/plugins.js +47 -53
- package/lib/serviceBase/plugins.js.map +1 -1
- package/lib/serviceBase/serviceBase.d.ts +3 -3
- package/lib/serviceBase/serviceBase.js +40 -44
- package/lib/serviceBase/serviceBase.js.map +1 -1
- package/lib/serviceBase/services.d.ts +6 -6
- package/lib/serviceBase/services.js +21 -22
- package/lib/serviceBase/services.js.map +1 -1
- package/package.json +18 -11
package/lib/interfaces/result.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
4
3
|
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
@@ -25,15 +24,6 @@
|
|
|
25
24
|
* You should have received a copy of the GNU Affero General Public License
|
|
26
25
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
27
26
|
*/
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.Ok = Ok;
|
|
30
|
-
exports.Err = Err;
|
|
31
|
-
exports.mapResult = mapResult;
|
|
32
|
-
exports.mapError = mapError;
|
|
33
|
-
exports.flatMapResult = flatMapResult;
|
|
34
|
-
exports.unwrap = unwrap;
|
|
35
|
-
exports.unwrapOr = unwrapOr;
|
|
36
|
-
exports.fromPromise = fromPromise;
|
|
37
27
|
/**
|
|
38
28
|
* Creates a successful result
|
|
39
29
|
*
|
|
@@ -44,7 +34,7 @@ exports.fromPromise = fromPromise;
|
|
|
44
34
|
* @category Utilities
|
|
45
35
|
* @see {@link https://bsbcode.dev/languages/nodejs/types/functions/Ok.html | API: Ok}
|
|
46
36
|
*/
|
|
47
|
-
function Ok(data) {
|
|
37
|
+
export function Ok(data) {
|
|
48
38
|
return { success: true, data };
|
|
49
39
|
}
|
|
50
40
|
/**
|
|
@@ -56,7 +46,7 @@ function Ok(data) {
|
|
|
56
46
|
* @group Errors
|
|
57
47
|
* @category Utilities
|
|
58
48
|
*/
|
|
59
|
-
function Err(error) {
|
|
49
|
+
export function Err(error) {
|
|
60
50
|
return { success: false, error };
|
|
61
51
|
}
|
|
62
52
|
/**
|
|
@@ -69,7 +59,7 @@ function Err(error) {
|
|
|
69
59
|
* @group Errors
|
|
70
60
|
* @category Utilities
|
|
71
61
|
*/
|
|
72
|
-
function mapResult(result, fn) {
|
|
62
|
+
export function mapResult(result, fn) {
|
|
73
63
|
if (result.success) {
|
|
74
64
|
return Ok(fn(result.data));
|
|
75
65
|
}
|
|
@@ -86,7 +76,7 @@ function mapResult(result, fn) {
|
|
|
86
76
|
* @category Utilities
|
|
87
77
|
* @see {@link https://bsbcode.dev/languages/nodejs/types/functions/mapError.html | API: mapError}
|
|
88
78
|
*/
|
|
89
|
-
function mapError(result, fn) {
|
|
79
|
+
export function mapError(result, fn) {
|
|
90
80
|
if (!result.success) {
|
|
91
81
|
return Err(fn(result.error));
|
|
92
82
|
}
|
|
@@ -102,7 +92,7 @@ function mapError(result, fn) {
|
|
|
102
92
|
* @group Errors
|
|
103
93
|
* @category Utilities
|
|
104
94
|
*/
|
|
105
|
-
function flatMapResult(result, fn) {
|
|
95
|
+
export function flatMapResult(result, fn) {
|
|
106
96
|
if (result.success) {
|
|
107
97
|
return fn(result.data);
|
|
108
98
|
}
|
|
@@ -118,7 +108,7 @@ function flatMapResult(result, fn) {
|
|
|
118
108
|
* @group Errors
|
|
119
109
|
* @category Utilities
|
|
120
110
|
*/
|
|
121
|
-
function unwrap(result) {
|
|
111
|
+
export function unwrap(result) {
|
|
122
112
|
if (result.success) {
|
|
123
113
|
return result.data;
|
|
124
114
|
}
|
|
@@ -134,7 +124,7 @@ function unwrap(result) {
|
|
|
134
124
|
* @group Errors
|
|
135
125
|
* @category Utilities
|
|
136
126
|
*/
|
|
137
|
-
function unwrapOr(result, defaultValue) {
|
|
127
|
+
export function unwrapOr(result, defaultValue) {
|
|
138
128
|
if (result.success) {
|
|
139
129
|
return result.data;
|
|
140
130
|
}
|
|
@@ -150,7 +140,7 @@ function unwrapOr(result, defaultValue) {
|
|
|
150
140
|
* @category Utilities
|
|
151
141
|
* @see {@link https://bsbcode.dev/languages/nodejs/types/functions/fromPromise.html | API: fromPromise}
|
|
152
142
|
*/
|
|
153
|
-
async function fromPromise(promise) {
|
|
143
|
+
export async function fromPromise(promise) {
|
|
154
144
|
try {
|
|
155
145
|
const data = await promise;
|
|
156
146
|
return Ok(data);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/interfaces/result.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/interfaces/result.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAYH;;;;;;;;;GASG;AACH,MAAM,UAAU,EAAE,CAAI,IAAO;IAC3B,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACjC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,GAAG,CAAI,KAAQ;I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;QACH,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC;QAC3B,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACxE,CAAC;AACH,CAAC"}
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* You should have received a copy of the GNU Affero General Public License
|
|
25
25
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
26
26
|
*/
|
|
27
|
-
import { BSBType, InferBSBType } from './schema-types';
|
|
27
|
+
import { AnyValiDocument, BSBType, InferBSBType } from './schema-types.js';
|
|
28
28
|
/**
|
|
29
29
|
* Schema definition for a returnable event with input/output validation.
|
|
30
30
|
* Type-branded to ensure returnable events are only used in appropriate categories.
|
|
@@ -286,22 +286,7 @@ export type EventCategory = 'emitEvents' | 'onEvents' | 'emitReturnableEvents' |
|
|
|
286
286
|
* JSON Schema type definition for cross-language code generation.
|
|
287
287
|
* Uses standard JSON Schema format with BSB-specific extensions.
|
|
288
288
|
*/
|
|
289
|
-
export
|
|
290
|
-
$schema?: string;
|
|
291
|
-
type?: string | string[];
|
|
292
|
-
format?: string;
|
|
293
|
-
properties?: Record<string, JSONSchemaType>;
|
|
294
|
-
items?: JSONSchemaType;
|
|
295
|
-
required?: string[];
|
|
296
|
-
enum?: any[];
|
|
297
|
-
description?: string;
|
|
298
|
-
minLength?: number;
|
|
299
|
-
maxLength?: number;
|
|
300
|
-
minimum?: number;
|
|
301
|
-
maximum?: number;
|
|
302
|
-
'x-bsb-type'?: string;
|
|
303
|
-
[key: string]: any;
|
|
304
|
-
}
|
|
289
|
+
export type JSONSchemaType = AnyValiDocument;
|
|
305
290
|
/**
|
|
306
291
|
* Exported event definition in JSON format.
|
|
307
292
|
* Contains all information needed for cross-language client generation.
|
|
@@ -316,9 +301,9 @@ export interface EventExportDefinition {
|
|
|
316
301
|
/** Default timeout in seconds for returnable event calls */
|
|
317
302
|
defaultTimeout?: number;
|
|
318
303
|
/** JSON Schema for input validation */
|
|
319
|
-
inputSchema:
|
|
304
|
+
inputSchema: AnyValiDocument;
|
|
320
305
|
/** JSON Schema for output validation (null for fire-and-forget/broadcast) */
|
|
321
|
-
outputSchema:
|
|
306
|
+
outputSchema: AnyValiDocument | null;
|
|
322
307
|
}
|
|
323
308
|
/**
|
|
324
309
|
* Complete exported schema for a plugin.
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
4
3
|
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
@@ -25,12 +24,7 @@
|
|
|
25
24
|
* You should have received a copy of the GNU Affero General Public License
|
|
26
25
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
27
26
|
*/
|
|
28
|
-
|
|
29
|
-
exports.createFireAndForgetEvent = createFireAndForgetEvent;
|
|
30
|
-
exports.createReturnableEvent = createReturnableEvent;
|
|
31
|
-
exports.createBroadcastEvent = createBroadcastEvent;
|
|
32
|
-
exports.createEventSchemas = createEventSchemas;
|
|
33
|
-
exports.exportEventSchemas = exportEventSchemas;
|
|
27
|
+
import { bsbToJsonSchema } from './schema-types.js';
|
|
34
28
|
/**
|
|
35
29
|
* Helper function to create a fire-and-forget event schema.
|
|
36
30
|
* Type-branded to ensure compile-time category validation.
|
|
@@ -40,7 +34,7 @@ exports.exportEventSchemas = exportEventSchemas;
|
|
|
40
34
|
* @returns Event schema object with type brand
|
|
41
35
|
* @see {@link https://bsbcode.dev/languages/nodejs/types/functions/createFireAndForgetEvent.html | API: createFireAndForgetEvent}
|
|
42
36
|
*/
|
|
43
|
-
function createFireAndForgetEvent(input, description) {
|
|
37
|
+
export function createFireAndForgetEvent(input, description) {
|
|
44
38
|
return { input, description, __brand: 'fire-and-forget' };
|
|
45
39
|
}
|
|
46
40
|
/**
|
|
@@ -53,7 +47,7 @@ function createFireAndForgetEvent(input, description) {
|
|
|
53
47
|
* @returns Event schema object with type brand
|
|
54
48
|
* @see {@link https://bsbcode.dev/languages/nodejs/types/functions/createReturnableEvent.html | API: createReturnableEvent}
|
|
55
49
|
*/
|
|
56
|
-
function createReturnableEvent(input, output, description, defaultTimeout) {
|
|
50
|
+
export function createReturnableEvent(input, output, description, defaultTimeout) {
|
|
57
51
|
return { input, output, description, defaultTimeout, __brand: 'returnable' };
|
|
58
52
|
}
|
|
59
53
|
/**
|
|
@@ -66,7 +60,7 @@ function createReturnableEvent(input, output, description, defaultTimeout) {
|
|
|
66
60
|
* @returns Event schema object with type brand
|
|
67
61
|
* @see {@link https://bsbcode.dev/languages/nodejs/types/functions/createBroadcastEvent.html | API: createBroadcastEvent}
|
|
68
62
|
*/
|
|
69
|
-
function createBroadcastEvent(input, description) {
|
|
63
|
+
export function createBroadcastEvent(input, description) {
|
|
70
64
|
return { input, description, __brand: 'broadcast' };
|
|
71
65
|
}
|
|
72
66
|
/**
|
|
@@ -119,7 +113,7 @@ function createBroadcastEvent(input, description) {
|
|
|
119
113
|
* // }
|
|
120
114
|
* ```
|
|
121
115
|
*/
|
|
122
|
-
function createEventSchemas(schemas) {
|
|
116
|
+
export function createEventSchemas(schemas) {
|
|
123
117
|
// Runtime duplicate name detection for developer clarity
|
|
124
118
|
// Note: Duplicate names across categories are not technically invalid, but can be confusing
|
|
125
119
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -193,7 +187,7 @@ function createEventSchemas(schemas) {
|
|
|
193
187
|
*
|
|
194
188
|
* @see {@link https://bsbcode.dev/languages/nodejs/types/functions/exportEventSchemas.html | API: exportEventSchemas}
|
|
195
189
|
*/
|
|
196
|
-
function exportEventSchemas(pluginName, version, schemas) {
|
|
190
|
+
export function exportEventSchemas(pluginName, version, schemas) {
|
|
197
191
|
const events = {};
|
|
198
192
|
// Helper to process a category of events
|
|
199
193
|
const processCategory = (category, categorySchemas) => {
|
|
@@ -212,7 +206,6 @@ function exportEventSchemas(pluginName, version, schemas) {
|
|
|
212
206
|
type = 'fire-and-forget';
|
|
213
207
|
}
|
|
214
208
|
// Convert BSBType input schema to JSON Schema
|
|
215
|
-
const { bsbToJsonSchema } = require('./schema-types');
|
|
216
209
|
const inputSchema = bsbToJsonSchema(eventDef.input);
|
|
217
210
|
// Convert output schema (if returnable)
|
|
218
211
|
let outputSchema = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-events.js","sourceRoot":"","sources":["../../src/interfaces/schema-events.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema-events.js","sourceRoot":"","sources":["../../src/interfaces/schema-events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAA0C,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAgI5F;;;;;;;;GAQG;AACH,MAAM,UAAU,wBAAwB,CACtC,KAAa,EACb,WAAoB;IAMpB,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,iBAA0B,EAAE,CAAC;AACrE,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB,CACnC,KAAa,EACb,MAAe,EACf,WAAoB,EACpB,cAAuB;IAQvB,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,OAAO,EAAE,YAAqB,EAAE,CAAC;AACxF,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAa,EACb,WAAoB;IAMpB,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,WAAoB,EAAE,CAAC;AAC/D,CAAC;AAED;;;;GAIG;AACH,oCAAoC;AACpC,wDAAwD;AACxD,0DAA0D;AAC1D,gEAAgE;AAChE,uDAAuD;AACvD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AwB,EAAE;oBACvD,CAAC,CAAC,EAAE,CAAC;gBACP,WAAW;gBACX,YAAY;aACb,CAAC;QACJ,CAAC;IACH,CAAC,CAAC;IAEF,yBAAyB;IACzB,eAAe,CAAC,YAAY,EAAE,OAAO,CAAC,UAAiB,CAAC,CAAC;IACzD,eAAe,CAAC,UAAU,EAAE,OAAO,CAAC,QAAe,CAAC,CAAC;IACrD,eAAe,CAAC,sBAAsB,EAAE,OAAO,CAAC,oBAA2B,CAAC,CAAC;IAC7E,eAAe,CAAC,oBAAoB,EAAE,OAAO,CAAC,kBAAyB,CAAC,CAAC;IACzE,eAAe,CAAC,eAAe,EAAE,OAAO,CAAC,aAAoB,CAAC,CAAC;IAC/D,eAAe,CAAC,aAAa,EAAE,OAAO,CAAC,WAAkB,CAAC,CAAC;IAE3D,OAAO;QACL,UAAU;QACV,OAAO;QACP,MAAM;KACP,CAAC;AACJ,CAAC"}
|
|
@@ -24,384 +24,64 @@
|
|
|
24
24
|
* You should have received a copy of the GNU Affero General Public License
|
|
25
25
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
26
26
|
*/
|
|
27
|
-
import
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
*/
|
|
33
|
-
export interface BSBTypeBase {
|
|
34
|
-
/** Type discriminator for JSON serialization */
|
|
35
|
-
_bsb: string;
|
|
36
|
-
/** Human-readable description for documentation */
|
|
37
|
-
description?: string;
|
|
38
|
-
/** Whether this field is optional */
|
|
39
|
-
optional?: boolean;
|
|
40
|
-
/** Whether this field can be null */
|
|
41
|
-
nullable?: boolean;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* String type with optional validation constraints.
|
|
45
|
-
*/
|
|
46
|
-
export interface BSBStringType extends BSBTypeBase {
|
|
47
|
-
_bsb: 'string';
|
|
48
|
-
minLength?: number;
|
|
49
|
-
maxLength?: number;
|
|
50
|
-
pattern?: string;
|
|
51
|
-
format?: 'uuid' | 'datetime' | 'email' | 'uri' | 'url';
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Numeric type with optional range constraints.
|
|
55
|
-
*/
|
|
56
|
-
export interface BSBNumberType extends BSBTypeBase {
|
|
57
|
-
_bsb: 'number';
|
|
58
|
-
numberType: 'int32' | 'int64' | 'float' | 'double';
|
|
59
|
-
min?: number;
|
|
60
|
-
max?: number;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Boolean type.
|
|
64
|
-
*/
|
|
65
|
-
export interface BSBBooleanType extends BSBTypeBase {
|
|
66
|
-
_bsb: 'boolean';
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Bytes type for binary data (byte arrays).
|
|
70
|
-
* Maps to Uint8Array in JavaScript, byte[] in C#/Java/Go, bytes in Python.
|
|
71
|
-
*/
|
|
72
|
-
export interface BSBBytesType extends BSBTypeBase {
|
|
73
|
-
_bsb: 'bytes';
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Array type with element type and optional size constraints.
|
|
77
|
-
*/
|
|
78
|
-
export interface BSBArrayType extends BSBTypeBase {
|
|
79
|
-
_bsb: 'array';
|
|
80
|
-
items: BSBType;
|
|
81
|
-
minItems?: number;
|
|
82
|
-
maxItems?: number;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Object type with named properties.
|
|
86
|
-
*/
|
|
87
|
-
export interface BSBObjectType extends BSBTypeBase {
|
|
88
|
-
_bsb: 'object';
|
|
89
|
-
properties: Record<string, BSBType>;
|
|
90
|
-
required: string[];
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Enum type with fixed string values.
|
|
94
|
-
*/
|
|
95
|
-
export interface BSBEnumType extends BSBTypeBase {
|
|
96
|
-
_bsb: 'enum';
|
|
97
|
-
values: string[];
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Union type representing one of multiple possible types.
|
|
101
|
-
*/
|
|
102
|
-
export interface BSBUnionType extends BSBTypeBase {
|
|
103
|
-
_bsb: 'union';
|
|
104
|
-
types: BSBType[];
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Union of all BSB type interfaces.
|
|
108
|
-
*/
|
|
109
|
-
export type BSBType = BSBStringType | BSBNumberType | BSBBooleanType | BSBBytesType | BSBArrayType | BSBObjectType | BSBEnumType | BSBUnionType;
|
|
110
|
-
/**
|
|
111
|
-
* BSB type builder providing a fluent API for creating cross-language type definitions.
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* ```typescript
|
|
115
|
-
* import { bsb, optional } from '@bsb/base';
|
|
116
|
-
*
|
|
117
|
-
* const UserSchema = bsb.object({
|
|
118
|
-
* id: bsb.uuid('User unique identifier'),
|
|
119
|
-
* name: bsb.string({ min: 1, max: 100, description: 'User full name' }),
|
|
120
|
-
* email: bsb.string({ description: 'User email address' }),
|
|
121
|
-
* age: optional(bsb.int32({ min: 0, max: 150, description: 'User age' })),
|
|
122
|
-
* });
|
|
123
|
-
* ```
|
|
124
|
-
*/
|
|
27
|
+
import * as av from '@anyvali/js';
|
|
28
|
+
export type BSBType = av.BaseSchema<any, any>;
|
|
29
|
+
export type InferBSBType<T extends BSBType> = av.Infer<T>;
|
|
30
|
+
export type AnyValiDocument = av.AnyValiDocument;
|
|
31
|
+
export declare function withDescription<T extends BSBType>(schema: T, description?: string): T;
|
|
125
32
|
export declare const bsb: {
|
|
126
|
-
/**
|
|
127
|
-
* Create a string type with optional constraints.
|
|
128
|
-
*/
|
|
129
33
|
string(options?: {
|
|
130
34
|
min?: number;
|
|
131
35
|
max?: number;
|
|
132
36
|
pattern?: string;
|
|
133
37
|
description?: string;
|
|
134
|
-
}):
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
* Language mappings:
|
|
141
|
-
* - JavaScript/TypeScript: string
|
|
142
|
-
* - C#: Guid
|
|
143
|
-
* - Go: uuid.UUID
|
|
144
|
-
* - Java: UUID
|
|
145
|
-
*/
|
|
146
|
-
uuid(description?: string): BSBStringType;
|
|
147
|
-
/**
|
|
148
|
-
* Create an ISO 8601 datetime string type.
|
|
149
|
-
*
|
|
150
|
-
* Format: 2024-01-01T12:00:00Z
|
|
151
|
-
*
|
|
152
|
-
* Language mappings:
|
|
153
|
-
* - JavaScript/TypeScript: Date | string
|
|
154
|
-
* - C#: DateTime
|
|
155
|
-
* - Go: time.Time
|
|
156
|
-
* - Java: Instant
|
|
157
|
-
*/
|
|
158
|
-
datetime(description?: string): BSBStringType;
|
|
159
|
-
/**
|
|
160
|
-
* Create an email address string type.
|
|
161
|
-
*/
|
|
162
|
-
email(description?: string): BSBStringType;
|
|
163
|
-
/**
|
|
164
|
-
* Create a URI string type.
|
|
165
|
-
*/
|
|
166
|
-
uri(description?: string): BSBStringType;
|
|
167
|
-
/**
|
|
168
|
-
* Create a URL string type.
|
|
169
|
-
*/
|
|
170
|
-
url(description?: string): BSBStringType;
|
|
171
|
-
/**
|
|
172
|
-
* Create a 32-bit signed integer type.
|
|
173
|
-
*
|
|
174
|
-
* Range: -2,147,483,648 to 2,147,483,647
|
|
175
|
-
*
|
|
176
|
-
* Language mappings:
|
|
177
|
-
* - JavaScript/TypeScript: number
|
|
178
|
-
* - C#: int
|
|
179
|
-
* - Go: int32
|
|
180
|
-
* - Java: int
|
|
181
|
-
*/
|
|
38
|
+
}): av.StringSchema;
|
|
39
|
+
uuid(description?: string): av.StringSchema;
|
|
40
|
+
datetime(description?: string): av.StringSchema;
|
|
41
|
+
email(description?: string): av.StringSchema;
|
|
42
|
+
uri(description?: string): av.StringSchema;
|
|
43
|
+
url(description?: string): av.StringSchema;
|
|
182
44
|
int32(options?: {
|
|
183
45
|
min?: number;
|
|
184
46
|
max?: number;
|
|
185
47
|
description?: string;
|
|
186
|
-
}):
|
|
187
|
-
/**
|
|
188
|
-
* Create a 64-bit signed integer type.
|
|
189
|
-
*
|
|
190
|
-
* Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
|
|
191
|
-
*
|
|
192
|
-
* Note: JavaScript can only safely represent integers up to 2^53.
|
|
193
|
-
*
|
|
194
|
-
* Language mappings:
|
|
195
|
-
* - JavaScript/TypeScript: number
|
|
196
|
-
* - C#: long
|
|
197
|
-
* - Go: int64
|
|
198
|
-
* - Java: long
|
|
199
|
-
*/
|
|
48
|
+
}): BSBType;
|
|
200
49
|
int64(options?: {
|
|
201
50
|
min?: number;
|
|
202
51
|
max?: number;
|
|
203
52
|
description?: string;
|
|
204
|
-
}):
|
|
205
|
-
/**
|
|
206
|
-
* Create a 32-bit floating point number type.
|
|
207
|
-
*
|
|
208
|
-
* Language mappings:
|
|
209
|
-
* - JavaScript/TypeScript: number
|
|
210
|
-
* - C#: float
|
|
211
|
-
* - Go: float32
|
|
212
|
-
* - Java: float
|
|
213
|
-
*/
|
|
53
|
+
}): BSBType;
|
|
214
54
|
float(options?: {
|
|
215
55
|
min?: number;
|
|
216
56
|
max?: number;
|
|
217
57
|
description?: string;
|
|
218
|
-
}):
|
|
219
|
-
/**
|
|
220
|
-
* Create a 64-bit floating point number type.
|
|
221
|
-
*
|
|
222
|
-
* Language mappings:
|
|
223
|
-
* - JavaScript/TypeScript: number
|
|
224
|
-
* - C#: double
|
|
225
|
-
* - Go: float64
|
|
226
|
-
* - Java: double
|
|
227
|
-
*/
|
|
58
|
+
}): BSBType;
|
|
228
59
|
double(options?: {
|
|
229
60
|
min?: number;
|
|
230
61
|
max?: number;
|
|
231
62
|
description?: string;
|
|
232
|
-
}):
|
|
233
|
-
|
|
234
|
-
* Create a boolean type.
|
|
235
|
-
*
|
|
236
|
-
* Language mappings:
|
|
237
|
-
* - JavaScript/TypeScript: boolean
|
|
238
|
-
* - C#: bool
|
|
239
|
-
* - Go: bool
|
|
240
|
-
* - Java: boolean
|
|
241
|
-
*/
|
|
242
|
-
boolean(description?: string): BSBBooleanType;
|
|
243
|
-
/**
|
|
244
|
-
* Create a bytes type for binary data.
|
|
245
|
-
* Maps to:
|
|
246
|
-
* - JavaScript/TypeScript: Uint8Array or Buffer
|
|
247
|
-
* - C#: byte[]
|
|
248
|
-
* - Go: []byte
|
|
249
|
-
* - Java: byte[]
|
|
250
|
-
* - Python: bytes
|
|
251
|
-
*/
|
|
252
|
-
bytes(description?: string): BSBBytesType;
|
|
253
|
-
/**
|
|
254
|
-
* Create an array type with element type and optional size constraints.
|
|
255
|
-
*
|
|
256
|
-
* @example
|
|
257
|
-
* ```typescript
|
|
258
|
-
* const TagsSchema = bsb.array(
|
|
259
|
-
* bsb.string({ max: 50 }),
|
|
260
|
-
* { min: 1, max: 10, description: 'List of tags' }
|
|
261
|
-
* );
|
|
262
|
-
* ```
|
|
263
|
-
*/
|
|
264
|
-
array(items: BSBType, options?: {
|
|
63
|
+
}): BSBType;
|
|
64
|
+
number(options?: {
|
|
265
65
|
min?: number;
|
|
266
66
|
max?: number;
|
|
267
67
|
description?: string;
|
|
268
|
-
}):
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
* Required fields are automatically determined based on the optional flag.
|
|
273
|
-
*
|
|
274
|
-
* @example
|
|
275
|
-
* ```typescript
|
|
276
|
-
* const UserSchema = bsb.object({
|
|
277
|
-
* id: bsb.uuid('User ID'),
|
|
278
|
-
* name: bsb.string({ min: 1, max: 100, description: 'Full name' }),
|
|
279
|
-
* email: optional(bsb.email('Email address')),
|
|
280
|
-
* }, 'User object');
|
|
281
|
-
* ```
|
|
282
|
-
*/
|
|
283
|
-
object<const T>(properties: T, description?: string): {
|
|
284
|
-
_bsb: "object";
|
|
285
|
-
properties: T;
|
|
286
|
-
required: string[];
|
|
287
|
-
description?: string;
|
|
288
|
-
optional?: boolean;
|
|
289
|
-
nullable?: boolean;
|
|
290
|
-
};
|
|
291
|
-
/**
|
|
292
|
-
* Create an enum type with fixed string values.
|
|
293
|
-
*
|
|
294
|
-
* @example
|
|
295
|
-
* ```typescript
|
|
296
|
-
* const StatusSchema = bsb.enum(
|
|
297
|
-
* ['pending', 'in-progress', 'completed', 'failed'],
|
|
298
|
-
* 'Task status'
|
|
299
|
-
* );
|
|
300
|
-
* ```
|
|
301
|
-
*/
|
|
302
|
-
enum(values: readonly string[], description?: string): BSBEnumType;
|
|
303
|
-
/**
|
|
304
|
-
* Create a union type representing one of multiple possible types.
|
|
305
|
-
*
|
|
306
|
-
* @example
|
|
307
|
-
* ```typescript
|
|
308
|
-
* const IdSchema = bsb.union([
|
|
309
|
-
* bsb.uuid('UUID identifier'),
|
|
310
|
-
* bsb.int32({ description: 'Numeric identifier' }),
|
|
311
|
-
* ], 'Flexible identifier');
|
|
312
|
-
* ```
|
|
313
|
-
*/
|
|
314
|
-
union(types: BSBType[], description?: string): BSBUnionType;
|
|
315
|
-
/**
|
|
316
|
-
* Create a generic number type (defaults to double for floating point).
|
|
317
|
-
* This is a convenience wrapper for double().
|
|
318
|
-
*/
|
|
319
|
-
number(options?: {
|
|
68
|
+
}): BSBType;
|
|
69
|
+
boolean(description?: string): av.BoolSchema;
|
|
70
|
+
bytes(description?: string): av.UnknownSchema;
|
|
71
|
+
array(items: BSBType, options?: {
|
|
320
72
|
min?: number;
|
|
321
73
|
max?: number;
|
|
322
74
|
description?: string;
|
|
323
|
-
}):
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
void():
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
*/
|
|
331
|
-
unknown(description?: string): BSBType;
|
|
332
|
-
/**
|
|
333
|
-
* Create a record/map type with string keys and a value type.
|
|
334
|
-
*/
|
|
335
|
-
record<K extends BSBType, V extends BSBType>(keyType: K, valueType: V, description?: string): BSBType;
|
|
336
|
-
};
|
|
337
|
-
/**
|
|
338
|
-
* Mark a type as optional.
|
|
339
|
-
* Optional fields are not required in object schemas.
|
|
340
|
-
*
|
|
341
|
-
* @example
|
|
342
|
-
* ```typescript
|
|
343
|
-
* const UserSchema = bsb.object({
|
|
344
|
-
* name: bsb.string(), // Required
|
|
345
|
-
* bio: optional(bsb.string()), // Optional
|
|
346
|
-
* });
|
|
347
|
-
* ```
|
|
348
|
-
*/
|
|
349
|
-
export declare function optional<T extends BSBType>(type: T): T & {
|
|
350
|
-
optional: true;
|
|
75
|
+
}): av.ArraySchema<BSBType>;
|
|
76
|
+
object<T extends Record<string, BSBType>>(properties: T, description?: string): av.ObjectSchema<T>;
|
|
77
|
+
enum(values: readonly (string | number)[], description?: string): av.EnumSchema<readonly (string | number)[]>;
|
|
78
|
+
union(types: BSBType[], description?: string): av.UnknownSchema | av.UnionSchema<[BSBType, ...BSBType[]]>;
|
|
79
|
+
void(): av.UnknownSchema;
|
|
80
|
+
unknown(description?: string): av.UnknownSchema;
|
|
81
|
+
record<K extends BSBType, V extends BSBType>(_keyType: K, valueType: V, description?: string): av.RecordSchema<V>;
|
|
351
82
|
};
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
* ```typescript
|
|
358
|
-
* const UserSchema = bsb.object({
|
|
359
|
-
* lastLogin: nullable(bsb.datetime('Last login time')),
|
|
360
|
-
* });
|
|
361
|
-
* ```
|
|
362
|
-
*/
|
|
363
|
-
export declare function nullable<T extends BSBType>(type: T): T;
|
|
364
|
-
type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...0[]];
|
|
365
|
-
/**
|
|
366
|
-
* Infer TypeScript type from BSB type definition with recursion depth limiting.
|
|
367
|
-
* Provides compile-time type safety when using BSB schemas.
|
|
368
|
-
* Limits recursion to prevent "excessively deep" errors.
|
|
369
|
-
*
|
|
370
|
-
* @example
|
|
371
|
-
* ```typescript
|
|
372
|
-
* const UserSchema = bsb.object({
|
|
373
|
-
* id: bsb.uuid(),
|
|
374
|
-
* name: bsb.string(),
|
|
375
|
-
* age: optional(bsb.int32()),
|
|
376
|
-
* });
|
|
377
|
-
*
|
|
378
|
-
* type User = InferBSBType<typeof UserSchema>;
|
|
379
|
-
* // Results in: { id: string; name: string; age?: number }
|
|
380
|
-
* ```
|
|
381
|
-
*/
|
|
382
|
-
export type InferBSBType<T, Depth extends number = 10> = [
|
|
383
|
-
T
|
|
384
|
-
] extends [never] ? never : Depth extends 0 ? any : T extends BSBStringType ? string : T extends BSBNumberType ? number : T extends BSBBooleanType ? boolean : T extends BSBBytesType ? Uint8Array : T extends BSBArrayType ? InferBSBType<T['items'], Prev[Depth]>[] : T extends {
|
|
385
|
-
_bsb: 'object';
|
|
386
|
-
properties: infer Props;
|
|
387
|
-
} ? ({
|
|
388
|
-
[K in keyof Props as Props[K] extends {
|
|
389
|
-
optional: true;
|
|
390
|
-
} ? never : K]: Props[K] extends BSBType ? InferBSBType<Props[K], Prev[Depth]> : never;
|
|
391
|
-
} & {
|
|
392
|
-
[K in keyof Props as Props[K] extends {
|
|
393
|
-
optional: true;
|
|
394
|
-
} ? K : never]?: Props[K] extends BSBType ? InferBSBType<Props[K], Prev[Depth]> : never;
|
|
395
|
-
}) : T extends BSBEnumType ? T['values'][number] : T extends BSBUnionType ? InferBSBType<T['types'][number], Prev[Depth]> : never;
|
|
396
|
-
/**
|
|
397
|
-
* Convert BSB type to JSON Schema format.
|
|
398
|
-
* Used for schema export and client code generation.
|
|
399
|
-
*/
|
|
400
|
-
export declare function bsbToJsonSchema(type: BSBType): any;
|
|
401
|
-
/**
|
|
402
|
-
* Convert BSB type to Zod schema for runtime validation.
|
|
403
|
-
* This is only used in Node.js plugins for runtime validation.
|
|
404
|
-
* Other languages will have their own validation implementations.
|
|
405
|
-
*/
|
|
406
|
-
export declare function bsbToZod(type: BSBType): z.ZodTypeAny;
|
|
407
|
-
export {};
|
|
83
|
+
export declare function optional<T extends BSBType>(type: T): av.OptionalSchema<T>;
|
|
84
|
+
export declare function nullable<T extends BSBType>(type: T): av.NullableSchema<T>;
|
|
85
|
+
export declare function bsbToJsonSchema(type: BSBType): AnyValiDocument;
|
|
86
|
+
export declare function exportPortableSchema(type: BSBType): AnyValiDocument;
|
|
87
|
+
export declare function importPortableSchema(document: AnyValiDocument): BSBType;
|