web-speech-cognitive-services 8.0.0 → 8.0.1-main.7b3a347
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/dist/web-speech-cognitive-services.d.mts +35 -20
- package/dist/web-speech-cognitive-services.d.ts +35 -20
- package/dist/web-speech-cognitive-services.development.js +843 -172
- package/dist/web-speech-cognitive-services.development.js.map +1 -1
- package/dist/web-speech-cognitive-services.js +141 -81
- package/dist/web-speech-cognitive-services.js.map +1 -1
- package/dist/web-speech-cognitive-services.mjs +147 -87
- package/dist/web-speech-cognitive-services.mjs.map +1 -1
- package/dist/web-speech-cognitive-services.production.min.js +12 -12
- package/dist/web-speech-cognitive-services.production.min.js.map +1 -1
- package/package.json +3 -2
|
@@ -122,7 +122,7 @@
|
|
|
122
122
|
});
|
|
123
123
|
exports.default = void 0;
|
|
124
124
|
var _rng = _interopRequireDefault(require_rng());
|
|
125
|
-
var
|
|
125
|
+
var _stringify2 = require_stringify();
|
|
126
126
|
function _interopRequireDefault(obj) {
|
|
127
127
|
return obj && obj.__esModule ? obj : { default: obj };
|
|
128
128
|
}
|
|
@@ -176,7 +176,7 @@
|
|
|
176
176
|
for (let n = 0; n < 6; ++n) {
|
|
177
177
|
b[i + n] = node[n];
|
|
178
178
|
}
|
|
179
|
-
return buf || (0,
|
|
179
|
+
return buf || (0, _stringify2.unsafeStringify)(b);
|
|
180
180
|
}
|
|
181
181
|
var _default = v1;
|
|
182
182
|
exports.default = _default;
|
|
@@ -195,7 +195,7 @@
|
|
|
195
195
|
function _interopRequireDefault(obj) {
|
|
196
196
|
return obj && obj.__esModule ? obj : { default: obj };
|
|
197
197
|
}
|
|
198
|
-
function
|
|
198
|
+
function parse2(uuid) {
|
|
199
199
|
if (!(0, _validate.default)(uuid)) {
|
|
200
200
|
throw TypeError("Invalid UUID");
|
|
201
201
|
}
|
|
@@ -219,7 +219,7 @@
|
|
|
219
219
|
arr[15] = v & 255;
|
|
220
220
|
return arr;
|
|
221
221
|
}
|
|
222
|
-
var _default =
|
|
222
|
+
var _default = parse2;
|
|
223
223
|
exports.default = _default;
|
|
224
224
|
}
|
|
225
225
|
});
|
|
@@ -233,7 +233,7 @@
|
|
|
233
233
|
});
|
|
234
234
|
exports.URL = exports.DNS = void 0;
|
|
235
235
|
exports.default = v35;
|
|
236
|
-
var
|
|
236
|
+
var _stringify2 = require_stringify();
|
|
237
237
|
var _parse = _interopRequireDefault(require_parse());
|
|
238
238
|
function _interopRequireDefault(obj) {
|
|
239
239
|
return obj && obj.__esModule ? obj : { default: obj };
|
|
@@ -275,7 +275,7 @@
|
|
|
275
275
|
}
|
|
276
276
|
return buf;
|
|
277
277
|
}
|
|
278
|
-
return (0,
|
|
278
|
+
return (0, _stringify2.unsafeStringify)(bytes);
|
|
279
279
|
}
|
|
280
280
|
try {
|
|
281
281
|
generateUUID.name = name;
|
|
@@ -487,7 +487,7 @@
|
|
|
487
487
|
exports.default = void 0;
|
|
488
488
|
var _native = _interopRequireDefault(require_native());
|
|
489
489
|
var _rng = _interopRequireDefault(require_rng());
|
|
490
|
-
var
|
|
490
|
+
var _stringify2 = require_stringify();
|
|
491
491
|
function _interopRequireDefault(obj) {
|
|
492
492
|
return obj && obj.__esModule ? obj : { default: obj };
|
|
493
493
|
}
|
|
@@ -506,7 +506,7 @@
|
|
|
506
506
|
}
|
|
507
507
|
return buf;
|
|
508
508
|
}
|
|
509
|
-
return (0,
|
|
509
|
+
return (0, _stringify2.unsafeStringify)(rnds);
|
|
510
510
|
}
|
|
511
511
|
var _default = v4;
|
|
512
512
|
exports.default = _default;
|
|
@@ -674,7 +674,7 @@
|
|
|
674
674
|
Object.defineProperty(exports, "stringify", {
|
|
675
675
|
enumerable: true,
|
|
676
676
|
get: function get() {
|
|
677
|
-
return
|
|
677
|
+
return _stringify2.default;
|
|
678
678
|
}
|
|
679
679
|
});
|
|
680
680
|
Object.defineProperty(exports, "v1", {
|
|
@@ -720,7 +720,7 @@
|
|
|
720
720
|
var _nil = _interopRequireDefault(require_nil());
|
|
721
721
|
var _version = _interopRequireDefault(require_version());
|
|
722
722
|
var _validate = _interopRequireDefault(require_validate());
|
|
723
|
-
var
|
|
723
|
+
var _stringify2 = _interopRequireDefault(require_stringify());
|
|
724
724
|
var _parse = _interopRequireDefault(require_parse());
|
|
725
725
|
function _interopRequireDefault(obj) {
|
|
726
726
|
return obj && obj.__esModule ? obj : { default: obj };
|
|
@@ -1540,9 +1540,9 @@
|
|
|
1540
1540
|
this.throwIfDisposed();
|
|
1541
1541
|
return new _List(this.privList.concat(list.toArray()));
|
|
1542
1542
|
}
|
|
1543
|
-
concatArray(
|
|
1543
|
+
concatArray(array2) {
|
|
1544
1544
|
this.throwIfDisposed();
|
|
1545
|
-
return new _List(this.privList.concat(
|
|
1545
|
+
return new _List(this.privList.concat(array2));
|
|
1546
1546
|
}
|
|
1547
1547
|
isDisposed() {
|
|
1548
1548
|
return this.privList == null;
|
|
@@ -2673,12 +2673,12 @@
|
|
|
2673
2673
|
throw new Error("the object is already disposed");
|
|
2674
2674
|
}
|
|
2675
2675
|
}
|
|
2676
|
-
static throwIfArrayEmptyOrWhitespace(
|
|
2677
|
-
_Contracts.throwIfNullOrUndefined(
|
|
2678
|
-
if (
|
|
2676
|
+
static throwIfArrayEmptyOrWhitespace(array2, name) {
|
|
2677
|
+
_Contracts.throwIfNullOrUndefined(array2, name);
|
|
2678
|
+
if (array2.length === 0) {
|
|
2679
2679
|
throw new Error("throwIfArrayEmptyOrWhitespace:" + name);
|
|
2680
2680
|
}
|
|
2681
|
-
for (const item of
|
|
2681
|
+
for (const item of array2) {
|
|
2682
2682
|
_Contracts.throwIfNullOrWhitespace(item, name);
|
|
2683
2683
|
}
|
|
2684
2684
|
}
|
|
@@ -6694,78 +6694,78 @@
|
|
|
6694
6694
|
"use strict";
|
|
6695
6695
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6696
6696
|
exports.PropertyId = void 0;
|
|
6697
|
-
var
|
|
6698
|
-
(function(
|
|
6699
|
-
|
|
6700
|
-
|
|
6701
|
-
|
|
6702
|
-
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
|
|
6714
|
-
|
|
6715
|
-
|
|
6716
|
-
|
|
6717
|
-
|
|
6718
|
-
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
|
|
6722
|
-
|
|
6723
|
-
|
|
6724
|
-
|
|
6725
|
-
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
|
|
6738
|
-
|
|
6739
|
-
|
|
6740
|
-
|
|
6741
|
-
|
|
6742
|
-
|
|
6743
|
-
|
|
6744
|
-
|
|
6745
|
-
|
|
6746
|
-
|
|
6747
|
-
|
|
6748
|
-
|
|
6749
|
-
|
|
6750
|
-
|
|
6751
|
-
|
|
6752
|
-
|
|
6753
|
-
|
|
6754
|
-
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
|
|
6758
|
-
|
|
6759
|
-
|
|
6760
|
-
|
|
6761
|
-
|
|
6762
|
-
|
|
6763
|
-
|
|
6764
|
-
|
|
6765
|
-
|
|
6766
|
-
|
|
6767
|
-
|
|
6768
|
-
})(
|
|
6697
|
+
var PropertyId2;
|
|
6698
|
+
(function(PropertyId3) {
|
|
6699
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_Key"] = 0] = "SpeechServiceConnection_Key";
|
|
6700
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_Endpoint"] = 1] = "SpeechServiceConnection_Endpoint";
|
|
6701
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_Region"] = 2] = "SpeechServiceConnection_Region";
|
|
6702
|
+
PropertyId3[PropertyId3["SpeechServiceAuthorization_Token"] = 3] = "SpeechServiceAuthorization_Token";
|
|
6703
|
+
PropertyId3[PropertyId3["SpeechServiceAuthorization_Type"] = 4] = "SpeechServiceAuthorization_Type";
|
|
6704
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_EndpointId"] = 5] = "SpeechServiceConnection_EndpointId";
|
|
6705
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_TranslationToLanguages"] = 6] = "SpeechServiceConnection_TranslationToLanguages";
|
|
6706
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_TranslationVoice"] = 7] = "SpeechServiceConnection_TranslationVoice";
|
|
6707
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_TranslationFeatures"] = 8] = "SpeechServiceConnection_TranslationFeatures";
|
|
6708
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_IntentRegion"] = 9] = "SpeechServiceConnection_IntentRegion";
|
|
6709
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_ProxyHostName"] = 10] = "SpeechServiceConnection_ProxyHostName";
|
|
6710
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_ProxyPort"] = 11] = "SpeechServiceConnection_ProxyPort";
|
|
6711
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_ProxyUserName"] = 12] = "SpeechServiceConnection_ProxyUserName";
|
|
6712
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_ProxyPassword"] = 13] = "SpeechServiceConnection_ProxyPassword";
|
|
6713
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_RecoMode"] = 14] = "SpeechServiceConnection_RecoMode";
|
|
6714
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_RecoLanguage"] = 15] = "SpeechServiceConnection_RecoLanguage";
|
|
6715
|
+
PropertyId3[PropertyId3["Speech_SessionId"] = 16] = "Speech_SessionId";
|
|
6716
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_SynthLanguage"] = 17] = "SpeechServiceConnection_SynthLanguage";
|
|
6717
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_SynthVoice"] = 18] = "SpeechServiceConnection_SynthVoice";
|
|
6718
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_SynthOutputFormat"] = 19] = "SpeechServiceConnection_SynthOutputFormat";
|
|
6719
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_AutoDetectSourceLanguages"] = 20] = "SpeechServiceConnection_AutoDetectSourceLanguages";
|
|
6720
|
+
PropertyId3[PropertyId3["SpeechServiceResponse_RequestDetailedResultTrueFalse"] = 21] = "SpeechServiceResponse_RequestDetailedResultTrueFalse";
|
|
6721
|
+
PropertyId3[PropertyId3["SpeechServiceResponse_RequestProfanityFilterTrueFalse"] = 22] = "SpeechServiceResponse_RequestProfanityFilterTrueFalse";
|
|
6722
|
+
PropertyId3[PropertyId3["SpeechServiceResponse_JsonResult"] = 23] = "SpeechServiceResponse_JsonResult";
|
|
6723
|
+
PropertyId3[PropertyId3["SpeechServiceResponse_JsonErrorDetails"] = 24] = "SpeechServiceResponse_JsonErrorDetails";
|
|
6724
|
+
PropertyId3[PropertyId3["CancellationDetails_Reason"] = 25] = "CancellationDetails_Reason";
|
|
6725
|
+
PropertyId3[PropertyId3["CancellationDetails_ReasonText"] = 26] = "CancellationDetails_ReasonText";
|
|
6726
|
+
PropertyId3[PropertyId3["CancellationDetails_ReasonDetailedText"] = 27] = "CancellationDetails_ReasonDetailedText";
|
|
6727
|
+
PropertyId3[PropertyId3["LanguageUnderstandingServiceResponse_JsonResult"] = 28] = "LanguageUnderstandingServiceResponse_JsonResult";
|
|
6728
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_Url"] = 29] = "SpeechServiceConnection_Url";
|
|
6729
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_InitialSilenceTimeoutMs"] = 30] = "SpeechServiceConnection_InitialSilenceTimeoutMs";
|
|
6730
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_EndSilenceTimeoutMs"] = 31] = "SpeechServiceConnection_EndSilenceTimeoutMs";
|
|
6731
|
+
PropertyId3[PropertyId3["Speech_SegmentationSilenceTimeoutMs"] = 32] = "Speech_SegmentationSilenceTimeoutMs";
|
|
6732
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_EnableAudioLogging"] = 33] = "SpeechServiceConnection_EnableAudioLogging";
|
|
6733
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_LanguageIdMode"] = 34] = "SpeechServiceConnection_LanguageIdMode";
|
|
6734
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_RecognitionEndpointVersion"] = 35] = "SpeechServiceConnection_RecognitionEndpointVersion";
|
|
6735
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_SpeakerIdMode"] = 36] = "SpeechServiceConnection_SpeakerIdMode";
|
|
6736
|
+
PropertyId3[PropertyId3["SpeechServiceResponse_ProfanityOption"] = 37] = "SpeechServiceResponse_ProfanityOption";
|
|
6737
|
+
PropertyId3[PropertyId3["SpeechServiceResponse_PostProcessingOption"] = 38] = "SpeechServiceResponse_PostProcessingOption";
|
|
6738
|
+
PropertyId3[PropertyId3["SpeechServiceResponse_RequestWordLevelTimestamps"] = 39] = "SpeechServiceResponse_RequestWordLevelTimestamps";
|
|
6739
|
+
PropertyId3[PropertyId3["SpeechServiceResponse_StablePartialResultThreshold"] = 40] = "SpeechServiceResponse_StablePartialResultThreshold";
|
|
6740
|
+
PropertyId3[PropertyId3["SpeechServiceResponse_OutputFormatOption"] = 41] = "SpeechServiceResponse_OutputFormatOption";
|
|
6741
|
+
PropertyId3[PropertyId3["SpeechServiceResponse_TranslationRequestStablePartialResult"] = 42] = "SpeechServiceResponse_TranslationRequestStablePartialResult";
|
|
6742
|
+
PropertyId3[PropertyId3["SpeechServiceResponse_RequestWordBoundary"] = 43] = "SpeechServiceResponse_RequestWordBoundary";
|
|
6743
|
+
PropertyId3[PropertyId3["SpeechServiceResponse_RequestPunctuationBoundary"] = 44] = "SpeechServiceResponse_RequestPunctuationBoundary";
|
|
6744
|
+
PropertyId3[PropertyId3["SpeechServiceResponse_RequestSentenceBoundary"] = 45] = "SpeechServiceResponse_RequestSentenceBoundary";
|
|
6745
|
+
PropertyId3[PropertyId3["Conversation_ApplicationId"] = 46] = "Conversation_ApplicationId";
|
|
6746
|
+
PropertyId3[PropertyId3["Conversation_DialogType"] = 47] = "Conversation_DialogType";
|
|
6747
|
+
PropertyId3[PropertyId3["Conversation_Initial_Silence_Timeout"] = 48] = "Conversation_Initial_Silence_Timeout";
|
|
6748
|
+
PropertyId3[PropertyId3["Conversation_From_Id"] = 49] = "Conversation_From_Id";
|
|
6749
|
+
PropertyId3[PropertyId3["Conversation_Conversation_Id"] = 50] = "Conversation_Conversation_Id";
|
|
6750
|
+
PropertyId3[PropertyId3["Conversation_Custom_Voice_Deployment_Ids"] = 51] = "Conversation_Custom_Voice_Deployment_Ids";
|
|
6751
|
+
PropertyId3[PropertyId3["Conversation_Speech_Activity_Template"] = 52] = "Conversation_Speech_Activity_Template";
|
|
6752
|
+
PropertyId3[PropertyId3["Conversation_Request_Bot_Status_Messages"] = 53] = "Conversation_Request_Bot_Status_Messages";
|
|
6753
|
+
PropertyId3[PropertyId3["Conversation_Agent_Connection_Id"] = 54] = "Conversation_Agent_Connection_Id";
|
|
6754
|
+
PropertyId3[PropertyId3["SpeechServiceConnection_Host"] = 55] = "SpeechServiceConnection_Host";
|
|
6755
|
+
PropertyId3[PropertyId3["ConversationTranslator_Host"] = 56] = "ConversationTranslator_Host";
|
|
6756
|
+
PropertyId3[PropertyId3["ConversationTranslator_Name"] = 57] = "ConversationTranslator_Name";
|
|
6757
|
+
PropertyId3[PropertyId3["ConversationTranslator_CorrelationId"] = 58] = "ConversationTranslator_CorrelationId";
|
|
6758
|
+
PropertyId3[PropertyId3["ConversationTranslator_Token"] = 59] = "ConversationTranslator_Token";
|
|
6759
|
+
PropertyId3[PropertyId3["PronunciationAssessment_ReferenceText"] = 60] = "PronunciationAssessment_ReferenceText";
|
|
6760
|
+
PropertyId3[PropertyId3["PronunciationAssessment_GradingSystem"] = 61] = "PronunciationAssessment_GradingSystem";
|
|
6761
|
+
PropertyId3[PropertyId3["PronunciationAssessment_Granularity"] = 62] = "PronunciationAssessment_Granularity";
|
|
6762
|
+
PropertyId3[PropertyId3["PronunciationAssessment_EnableMiscue"] = 63] = "PronunciationAssessment_EnableMiscue";
|
|
6763
|
+
PropertyId3[PropertyId3["PronunciationAssessment_Json"] = 64] = "PronunciationAssessment_Json";
|
|
6764
|
+
PropertyId3[PropertyId3["PronunciationAssessment_Params"] = 65] = "PronunciationAssessment_Params";
|
|
6765
|
+
PropertyId3[PropertyId3["SpeakerRecognition_Api_Version"] = 66] = "SpeakerRecognition_Api_Version";
|
|
6766
|
+
PropertyId3[PropertyId3["WebWorkerLoadType"] = 67] = "WebWorkerLoadType";
|
|
6767
|
+
PropertyId3[PropertyId3["TalkingAvatarService_WebRTC_SDP"] = 68] = "TalkingAvatarService_WebRTC_SDP";
|
|
6768
|
+
})(PropertyId2 = exports.PropertyId || (exports.PropertyId = {}));
|
|
6769
6769
|
}
|
|
6770
6770
|
});
|
|
6771
6771
|
|
|
@@ -9242,10 +9242,10 @@
|
|
|
9242
9242
|
throw new Error_js_1.InvalidOperationError("Only WAVE_FORMAT_PCM (8/16/32 bps) format supported at this time");
|
|
9243
9243
|
}
|
|
9244
9244
|
}
|
|
9245
|
-
formatArrayBuffer(audioData,
|
|
9245
|
+
formatArrayBuffer(audioData, maxValue2) {
|
|
9246
9246
|
const float32Data = new Float32Array(audioData.length);
|
|
9247
9247
|
for (let i = 0; i < audioData.length; i++) {
|
|
9248
|
-
float32Data[i] = audioData[i] /
|
|
9248
|
+
float32Data[i] = audioData[i] / maxValue2;
|
|
9249
9249
|
}
|
|
9250
9250
|
return float32Data;
|
|
9251
9251
|
}
|
|
@@ -23432,6 +23432,633 @@
|
|
|
23432
23432
|
}
|
|
23433
23433
|
});
|
|
23434
23434
|
|
|
23435
|
+
// src/SpeechServices/SpeechToText/createSpeechRecognitionPonyfill.ts
|
|
23436
|
+
var import_microsoft_cognitiveservices_speech_sdk = __toESM(require_microsoft_cognitiveservices_speech_sdk());
|
|
23437
|
+
|
|
23438
|
+
// node_modules/valibot/dist/index.js
|
|
23439
|
+
var EMOJI_REGEX = (
|
|
23440
|
+
// eslint-disable-next-line redos-detector/no-unsafe-regex, regexp/no-dupe-disjunctions -- false positives
|
|
23441
|
+
new RegExp("^(?:[\\u{1F1E6}-\\u{1F1FF}]{2}|\\u{1F3F4}[\\u{E0061}-\\u{E007A}]{2}[\\u{E0030}-\\u{E0039}\\u{E0061}-\\u{E007A}]{1,3}\\u{E007F}|(?:\\p{Emoji}\\uFE0F\\u20E3?|\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation})(?:\\u200D(?:\\p{Emoji}\\uFE0F\\u20E3?|\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation}))*)+$", "u")
|
|
23442
|
+
);
|
|
23443
|
+
var store;
|
|
23444
|
+
function getGlobalConfig(config2) {
|
|
23445
|
+
return {
|
|
23446
|
+
lang: config2?.lang ?? store?.lang,
|
|
23447
|
+
message: config2?.message,
|
|
23448
|
+
abortEarly: config2?.abortEarly ?? store?.abortEarly,
|
|
23449
|
+
abortPipeEarly: config2?.abortPipeEarly ?? store?.abortPipeEarly
|
|
23450
|
+
};
|
|
23451
|
+
}
|
|
23452
|
+
var store2;
|
|
23453
|
+
function getGlobalMessage(lang) {
|
|
23454
|
+
return store2?.get(lang);
|
|
23455
|
+
}
|
|
23456
|
+
var store3;
|
|
23457
|
+
function getSchemaMessage(lang) {
|
|
23458
|
+
return store3?.get(lang);
|
|
23459
|
+
}
|
|
23460
|
+
var store4;
|
|
23461
|
+
function getSpecificMessage(reference, lang) {
|
|
23462
|
+
return store4?.get(reference)?.get(lang);
|
|
23463
|
+
}
|
|
23464
|
+
function _stringify(input) {
|
|
23465
|
+
const type = typeof input;
|
|
23466
|
+
if (type === "string") {
|
|
23467
|
+
return `"${input}"`;
|
|
23468
|
+
}
|
|
23469
|
+
if (type === "number" || type === "bigint" || type === "boolean") {
|
|
23470
|
+
return `${input}`;
|
|
23471
|
+
}
|
|
23472
|
+
if (type === "object" || type === "function") {
|
|
23473
|
+
return (input && Object.getPrototypeOf(input)?.constructor?.name) ?? "null";
|
|
23474
|
+
}
|
|
23475
|
+
return type;
|
|
23476
|
+
}
|
|
23477
|
+
function _addIssue(context, label, dataset, config2, other) {
|
|
23478
|
+
const input = other && "input" in other ? other.input : dataset.value;
|
|
23479
|
+
const expected = other?.expected ?? context.expects ?? null;
|
|
23480
|
+
const received = other?.received ?? _stringify(input);
|
|
23481
|
+
const issue = {
|
|
23482
|
+
kind: context.kind,
|
|
23483
|
+
type: context.type,
|
|
23484
|
+
input,
|
|
23485
|
+
expected,
|
|
23486
|
+
received,
|
|
23487
|
+
message: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : "R"}eceived ${received}`,
|
|
23488
|
+
requirement: context.requirement,
|
|
23489
|
+
path: other?.path,
|
|
23490
|
+
issues: other?.issues,
|
|
23491
|
+
lang: config2.lang,
|
|
23492
|
+
abortEarly: config2.abortEarly,
|
|
23493
|
+
abortPipeEarly: config2.abortPipeEarly
|
|
23494
|
+
};
|
|
23495
|
+
const isSchema = context.kind === "schema";
|
|
23496
|
+
const message = other?.message ?? context.message ?? getSpecificMessage(context.reference, issue.lang) ?? (isSchema ? getSchemaMessage(issue.lang) : null) ?? config2.message ?? getGlobalMessage(issue.lang);
|
|
23497
|
+
if (message) {
|
|
23498
|
+
issue.message = typeof message === "function" ? (
|
|
23499
|
+
// @ts-expect-error
|
|
23500
|
+
message(issue)
|
|
23501
|
+
) : message;
|
|
23502
|
+
}
|
|
23503
|
+
if (isSchema) {
|
|
23504
|
+
dataset.typed = false;
|
|
23505
|
+
}
|
|
23506
|
+
if (dataset.issues) {
|
|
23507
|
+
dataset.issues.push(issue);
|
|
23508
|
+
} else {
|
|
23509
|
+
dataset.issues = [issue];
|
|
23510
|
+
}
|
|
23511
|
+
}
|
|
23512
|
+
function _joinExpects(values, separator) {
|
|
23513
|
+
const list = [...new Set(values)];
|
|
23514
|
+
if (list.length > 1) {
|
|
23515
|
+
return `(${list.join(` ${separator} `)})`;
|
|
23516
|
+
}
|
|
23517
|
+
return list[0] ?? "never";
|
|
23518
|
+
}
|
|
23519
|
+
var ValiError = class extends Error {
|
|
23520
|
+
/**
|
|
23521
|
+
* The error issues.
|
|
23522
|
+
*/
|
|
23523
|
+
issues;
|
|
23524
|
+
/**
|
|
23525
|
+
* Creates a Valibot error with useful information.
|
|
23526
|
+
*
|
|
23527
|
+
* @param issues The error issues.
|
|
23528
|
+
*/
|
|
23529
|
+
constructor(issues) {
|
|
23530
|
+
super(issues[0].message);
|
|
23531
|
+
this.name = "ValiError";
|
|
23532
|
+
this.issues = issues;
|
|
23533
|
+
}
|
|
23534
|
+
};
|
|
23535
|
+
function maxValue(requirement, message) {
|
|
23536
|
+
return {
|
|
23537
|
+
kind: "validation",
|
|
23538
|
+
type: "max_value",
|
|
23539
|
+
reference: maxValue,
|
|
23540
|
+
async: false,
|
|
23541
|
+
expects: `<=${requirement instanceof Date ? requirement.toJSON() : _stringify(requirement)}`,
|
|
23542
|
+
requirement,
|
|
23543
|
+
message,
|
|
23544
|
+
_run(dataset, config2) {
|
|
23545
|
+
if (dataset.typed && dataset.value > this.requirement) {
|
|
23546
|
+
_addIssue(this, "value", dataset, config2, {
|
|
23547
|
+
received: dataset.value instanceof Date ? dataset.value.toJSON() : _stringify(dataset.value)
|
|
23548
|
+
});
|
|
23549
|
+
}
|
|
23550
|
+
return dataset;
|
|
23551
|
+
}
|
|
23552
|
+
};
|
|
23553
|
+
}
|
|
23554
|
+
function minValue(requirement, message) {
|
|
23555
|
+
return {
|
|
23556
|
+
kind: "validation",
|
|
23557
|
+
type: "min_value",
|
|
23558
|
+
reference: minValue,
|
|
23559
|
+
async: false,
|
|
23560
|
+
expects: `>=${requirement instanceof Date ? requirement.toJSON() : _stringify(requirement)}`,
|
|
23561
|
+
requirement,
|
|
23562
|
+
message,
|
|
23563
|
+
_run(dataset, config2) {
|
|
23564
|
+
if (dataset.typed && dataset.value < this.requirement) {
|
|
23565
|
+
_addIssue(this, "value", dataset, config2, {
|
|
23566
|
+
received: dataset.value instanceof Date ? dataset.value.toJSON() : _stringify(dataset.value)
|
|
23567
|
+
});
|
|
23568
|
+
}
|
|
23569
|
+
return dataset;
|
|
23570
|
+
}
|
|
23571
|
+
};
|
|
23572
|
+
}
|
|
23573
|
+
function readonly() {
|
|
23574
|
+
return {
|
|
23575
|
+
kind: "transformation",
|
|
23576
|
+
type: "readonly",
|
|
23577
|
+
reference: readonly,
|
|
23578
|
+
async: false,
|
|
23579
|
+
_run(dataset) {
|
|
23580
|
+
return dataset;
|
|
23581
|
+
}
|
|
23582
|
+
};
|
|
23583
|
+
}
|
|
23584
|
+
function transform(operation) {
|
|
23585
|
+
return {
|
|
23586
|
+
kind: "transformation",
|
|
23587
|
+
type: "transform",
|
|
23588
|
+
reference: transform,
|
|
23589
|
+
async: false,
|
|
23590
|
+
operation,
|
|
23591
|
+
_run(dataset) {
|
|
23592
|
+
dataset.value = this.operation(dataset.value);
|
|
23593
|
+
return dataset;
|
|
23594
|
+
}
|
|
23595
|
+
};
|
|
23596
|
+
}
|
|
23597
|
+
function getDefault(schema, dataset, config2) {
|
|
23598
|
+
return typeof schema.default === "function" ? (
|
|
23599
|
+
// @ts-expect-error
|
|
23600
|
+
schema.default(dataset, config2)
|
|
23601
|
+
) : (
|
|
23602
|
+
// @ts-expect-error
|
|
23603
|
+
schema.default
|
|
23604
|
+
);
|
|
23605
|
+
}
|
|
23606
|
+
function array(item, message) {
|
|
23607
|
+
return {
|
|
23608
|
+
kind: "schema",
|
|
23609
|
+
type: "array",
|
|
23610
|
+
reference: array,
|
|
23611
|
+
expects: "Array",
|
|
23612
|
+
async: false,
|
|
23613
|
+
item,
|
|
23614
|
+
message,
|
|
23615
|
+
_run(dataset, config2) {
|
|
23616
|
+
const input = dataset.value;
|
|
23617
|
+
if (Array.isArray(input)) {
|
|
23618
|
+
dataset.typed = true;
|
|
23619
|
+
dataset.value = [];
|
|
23620
|
+
for (let key = 0; key < input.length; key++) {
|
|
23621
|
+
const value2 = input[key];
|
|
23622
|
+
const itemDataset = this.item._run({ typed: false, value: value2 }, config2);
|
|
23623
|
+
if (itemDataset.issues) {
|
|
23624
|
+
const pathItem = {
|
|
23625
|
+
type: "array",
|
|
23626
|
+
origin: "value",
|
|
23627
|
+
input,
|
|
23628
|
+
key,
|
|
23629
|
+
value: value2
|
|
23630
|
+
};
|
|
23631
|
+
for (const issue of itemDataset.issues) {
|
|
23632
|
+
if (issue.path) {
|
|
23633
|
+
issue.path.unshift(pathItem);
|
|
23634
|
+
} else {
|
|
23635
|
+
issue.path = [pathItem];
|
|
23636
|
+
}
|
|
23637
|
+
dataset.issues?.push(issue);
|
|
23638
|
+
}
|
|
23639
|
+
if (!dataset.issues) {
|
|
23640
|
+
dataset.issues = itemDataset.issues;
|
|
23641
|
+
}
|
|
23642
|
+
if (config2.abortEarly) {
|
|
23643
|
+
dataset.typed = false;
|
|
23644
|
+
break;
|
|
23645
|
+
}
|
|
23646
|
+
}
|
|
23647
|
+
if (!itemDataset.typed) {
|
|
23648
|
+
dataset.typed = false;
|
|
23649
|
+
}
|
|
23650
|
+
dataset.value.push(itemDataset.value);
|
|
23651
|
+
}
|
|
23652
|
+
} else {
|
|
23653
|
+
_addIssue(this, "type", dataset, config2);
|
|
23654
|
+
}
|
|
23655
|
+
return dataset;
|
|
23656
|
+
}
|
|
23657
|
+
};
|
|
23658
|
+
}
|
|
23659
|
+
function boolean(message) {
|
|
23660
|
+
return {
|
|
23661
|
+
kind: "schema",
|
|
23662
|
+
type: "boolean",
|
|
23663
|
+
reference: boolean,
|
|
23664
|
+
expects: "boolean",
|
|
23665
|
+
async: false,
|
|
23666
|
+
message,
|
|
23667
|
+
_run(dataset, config2) {
|
|
23668
|
+
if (typeof dataset.value === "boolean") {
|
|
23669
|
+
dataset.typed = true;
|
|
23670
|
+
} else {
|
|
23671
|
+
_addIssue(this, "type", dataset, config2);
|
|
23672
|
+
}
|
|
23673
|
+
return dataset;
|
|
23674
|
+
}
|
|
23675
|
+
};
|
|
23676
|
+
}
|
|
23677
|
+
function enum_(enum__, message) {
|
|
23678
|
+
const options = Object.entries(enum__).filter(([key]) => isNaN(+key)).map(([, value2]) => value2);
|
|
23679
|
+
return {
|
|
23680
|
+
kind: "schema",
|
|
23681
|
+
type: "enum",
|
|
23682
|
+
reference: enum_,
|
|
23683
|
+
expects: _joinExpects(options.map(_stringify), "|"),
|
|
23684
|
+
async: false,
|
|
23685
|
+
enum: enum__,
|
|
23686
|
+
options,
|
|
23687
|
+
message,
|
|
23688
|
+
_run(dataset, config2) {
|
|
23689
|
+
if (this.options.includes(dataset.value)) {
|
|
23690
|
+
dataset.typed = true;
|
|
23691
|
+
} else {
|
|
23692
|
+
_addIssue(this, "type", dataset, config2);
|
|
23693
|
+
}
|
|
23694
|
+
return dataset;
|
|
23695
|
+
}
|
|
23696
|
+
};
|
|
23697
|
+
}
|
|
23698
|
+
function function_(message) {
|
|
23699
|
+
return {
|
|
23700
|
+
kind: "schema",
|
|
23701
|
+
type: "function",
|
|
23702
|
+
reference: function_,
|
|
23703
|
+
expects: "Function",
|
|
23704
|
+
async: false,
|
|
23705
|
+
message,
|
|
23706
|
+
_run(dataset, config2) {
|
|
23707
|
+
if (typeof dataset.value === "function") {
|
|
23708
|
+
dataset.typed = true;
|
|
23709
|
+
} else {
|
|
23710
|
+
_addIssue(this, "type", dataset, config2);
|
|
23711
|
+
}
|
|
23712
|
+
return dataset;
|
|
23713
|
+
}
|
|
23714
|
+
};
|
|
23715
|
+
}
|
|
23716
|
+
function _merge(value1, value2) {
|
|
23717
|
+
if (typeof value1 === typeof value2) {
|
|
23718
|
+
if (value1 === value2 || value1 instanceof Date && value2 instanceof Date && +value1 === +value2) {
|
|
23719
|
+
return { value: value1 };
|
|
23720
|
+
}
|
|
23721
|
+
if (value1 && value2 && value1.constructor === Object && value2.constructor === Object) {
|
|
23722
|
+
for (const key in value2) {
|
|
23723
|
+
if (key in value1) {
|
|
23724
|
+
const dataset = _merge(value1[key], value2[key]);
|
|
23725
|
+
if (dataset.issue) {
|
|
23726
|
+
return dataset;
|
|
23727
|
+
}
|
|
23728
|
+
value1[key] = dataset.value;
|
|
23729
|
+
} else {
|
|
23730
|
+
value1[key] = value2[key];
|
|
23731
|
+
}
|
|
23732
|
+
}
|
|
23733
|
+
return { value: value1 };
|
|
23734
|
+
}
|
|
23735
|
+
if (Array.isArray(value1) && Array.isArray(value2)) {
|
|
23736
|
+
if (value1.length === value2.length) {
|
|
23737
|
+
for (let index = 0; index < value1.length; index++) {
|
|
23738
|
+
const dataset = _merge(value1[index], value2[index]);
|
|
23739
|
+
if (dataset.issue) {
|
|
23740
|
+
return dataset;
|
|
23741
|
+
}
|
|
23742
|
+
value1[index] = dataset.value;
|
|
23743
|
+
}
|
|
23744
|
+
return { value: value1 };
|
|
23745
|
+
}
|
|
23746
|
+
}
|
|
23747
|
+
}
|
|
23748
|
+
return { issue: true };
|
|
23749
|
+
}
|
|
23750
|
+
function intersect(options, message) {
|
|
23751
|
+
return {
|
|
23752
|
+
kind: "schema",
|
|
23753
|
+
type: "intersect",
|
|
23754
|
+
reference: intersect,
|
|
23755
|
+
expects: _joinExpects(
|
|
23756
|
+
options.map((option) => option.expects),
|
|
23757
|
+
"&"
|
|
23758
|
+
),
|
|
23759
|
+
async: false,
|
|
23760
|
+
options,
|
|
23761
|
+
message,
|
|
23762
|
+
_run(dataset, config2) {
|
|
23763
|
+
if (this.options.length) {
|
|
23764
|
+
const input = dataset.value;
|
|
23765
|
+
let outputs;
|
|
23766
|
+
dataset.typed = true;
|
|
23767
|
+
for (const schema of this.options) {
|
|
23768
|
+
const optionDataset = schema._run(
|
|
23769
|
+
{ typed: false, value: input },
|
|
23770
|
+
config2
|
|
23771
|
+
);
|
|
23772
|
+
if (optionDataset.issues) {
|
|
23773
|
+
if (dataset.issues) {
|
|
23774
|
+
dataset.issues.push(...optionDataset.issues);
|
|
23775
|
+
} else {
|
|
23776
|
+
dataset.issues = optionDataset.issues;
|
|
23777
|
+
}
|
|
23778
|
+
if (config2.abortEarly) {
|
|
23779
|
+
dataset.typed = false;
|
|
23780
|
+
break;
|
|
23781
|
+
}
|
|
23782
|
+
}
|
|
23783
|
+
if (!optionDataset.typed) {
|
|
23784
|
+
dataset.typed = false;
|
|
23785
|
+
}
|
|
23786
|
+
if (dataset.typed) {
|
|
23787
|
+
if (outputs) {
|
|
23788
|
+
outputs.push(optionDataset.value);
|
|
23789
|
+
} else {
|
|
23790
|
+
outputs = [optionDataset.value];
|
|
23791
|
+
}
|
|
23792
|
+
}
|
|
23793
|
+
}
|
|
23794
|
+
if (dataset.typed) {
|
|
23795
|
+
dataset.value = outputs[0];
|
|
23796
|
+
for (let index = 1; index < outputs.length; index++) {
|
|
23797
|
+
const mergeDataset = _merge(dataset.value, outputs[index]);
|
|
23798
|
+
if (mergeDataset.issue) {
|
|
23799
|
+
_addIssue(this, "type", dataset, config2, {
|
|
23800
|
+
received: "unknown"
|
|
23801
|
+
});
|
|
23802
|
+
break;
|
|
23803
|
+
}
|
|
23804
|
+
dataset.value = mergeDataset.value;
|
|
23805
|
+
}
|
|
23806
|
+
}
|
|
23807
|
+
} else {
|
|
23808
|
+
_addIssue(this, "type", dataset, config2);
|
|
23809
|
+
}
|
|
23810
|
+
return dataset;
|
|
23811
|
+
}
|
|
23812
|
+
};
|
|
23813
|
+
}
|
|
23814
|
+
function number(message) {
|
|
23815
|
+
return {
|
|
23816
|
+
kind: "schema",
|
|
23817
|
+
type: "number",
|
|
23818
|
+
reference: number,
|
|
23819
|
+
expects: "number",
|
|
23820
|
+
async: false,
|
|
23821
|
+
message,
|
|
23822
|
+
_run(dataset, config2) {
|
|
23823
|
+
if (typeof dataset.value === "number" && !isNaN(dataset.value)) {
|
|
23824
|
+
dataset.typed = true;
|
|
23825
|
+
} else {
|
|
23826
|
+
_addIssue(this, "type", dataset, config2);
|
|
23827
|
+
}
|
|
23828
|
+
return dataset;
|
|
23829
|
+
}
|
|
23830
|
+
};
|
|
23831
|
+
}
|
|
23832
|
+
function object(entries, message) {
|
|
23833
|
+
return {
|
|
23834
|
+
kind: "schema",
|
|
23835
|
+
type: "object",
|
|
23836
|
+
reference: object,
|
|
23837
|
+
expects: "Object",
|
|
23838
|
+
async: false,
|
|
23839
|
+
entries,
|
|
23840
|
+
message,
|
|
23841
|
+
_run(dataset, config2) {
|
|
23842
|
+
const input = dataset.value;
|
|
23843
|
+
if (input && typeof input === "object") {
|
|
23844
|
+
dataset.typed = true;
|
|
23845
|
+
dataset.value = {};
|
|
23846
|
+
for (const key in this.entries) {
|
|
23847
|
+
const value2 = input[key];
|
|
23848
|
+
const valueDataset = this.entries[key]._run(
|
|
23849
|
+
{ typed: false, value: value2 },
|
|
23850
|
+
config2
|
|
23851
|
+
);
|
|
23852
|
+
if (valueDataset.issues) {
|
|
23853
|
+
const pathItem = {
|
|
23854
|
+
type: "object",
|
|
23855
|
+
origin: "value",
|
|
23856
|
+
input,
|
|
23857
|
+
key,
|
|
23858
|
+
value: value2
|
|
23859
|
+
};
|
|
23860
|
+
for (const issue of valueDataset.issues) {
|
|
23861
|
+
if (issue.path) {
|
|
23862
|
+
issue.path.unshift(pathItem);
|
|
23863
|
+
} else {
|
|
23864
|
+
issue.path = [pathItem];
|
|
23865
|
+
}
|
|
23866
|
+
dataset.issues?.push(issue);
|
|
23867
|
+
}
|
|
23868
|
+
if (!dataset.issues) {
|
|
23869
|
+
dataset.issues = valueDataset.issues;
|
|
23870
|
+
}
|
|
23871
|
+
if (config2.abortEarly) {
|
|
23872
|
+
dataset.typed = false;
|
|
23873
|
+
break;
|
|
23874
|
+
}
|
|
23875
|
+
}
|
|
23876
|
+
if (!valueDataset.typed) {
|
|
23877
|
+
dataset.typed = false;
|
|
23878
|
+
}
|
|
23879
|
+
if (valueDataset.value !== void 0 || key in input) {
|
|
23880
|
+
dataset.value[key] = valueDataset.value;
|
|
23881
|
+
}
|
|
23882
|
+
}
|
|
23883
|
+
} else {
|
|
23884
|
+
_addIssue(this, "type", dataset, config2);
|
|
23885
|
+
}
|
|
23886
|
+
return dataset;
|
|
23887
|
+
}
|
|
23888
|
+
};
|
|
23889
|
+
}
|
|
23890
|
+
function optional(wrapped, ...args) {
|
|
23891
|
+
const schema = {
|
|
23892
|
+
kind: "schema",
|
|
23893
|
+
type: "optional",
|
|
23894
|
+
reference: optional,
|
|
23895
|
+
expects: `(${wrapped.expects} | undefined)`,
|
|
23896
|
+
async: false,
|
|
23897
|
+
wrapped,
|
|
23898
|
+
_run(dataset, config2) {
|
|
23899
|
+
if (dataset.value === void 0) {
|
|
23900
|
+
if ("default" in this) {
|
|
23901
|
+
dataset.value = getDefault(
|
|
23902
|
+
this,
|
|
23903
|
+
dataset,
|
|
23904
|
+
config2
|
|
23905
|
+
);
|
|
23906
|
+
}
|
|
23907
|
+
if (dataset.value === void 0) {
|
|
23908
|
+
dataset.typed = true;
|
|
23909
|
+
return dataset;
|
|
23910
|
+
}
|
|
23911
|
+
}
|
|
23912
|
+
return this.wrapped._run(dataset, config2);
|
|
23913
|
+
}
|
|
23914
|
+
};
|
|
23915
|
+
if (0 in args) {
|
|
23916
|
+
schema.default = args[0];
|
|
23917
|
+
}
|
|
23918
|
+
return schema;
|
|
23919
|
+
}
|
|
23920
|
+
function string(message) {
|
|
23921
|
+
return {
|
|
23922
|
+
kind: "schema",
|
|
23923
|
+
type: "string",
|
|
23924
|
+
reference: string,
|
|
23925
|
+
expects: "string",
|
|
23926
|
+
async: false,
|
|
23927
|
+
message,
|
|
23928
|
+
_run(dataset, config2) {
|
|
23929
|
+
if (typeof dataset.value === "string") {
|
|
23930
|
+
dataset.typed = true;
|
|
23931
|
+
} else {
|
|
23932
|
+
_addIssue(this, "type", dataset, config2);
|
|
23933
|
+
}
|
|
23934
|
+
return dataset;
|
|
23935
|
+
}
|
|
23936
|
+
};
|
|
23937
|
+
}
|
|
23938
|
+
function undefined_(message) {
|
|
23939
|
+
return {
|
|
23940
|
+
kind: "schema",
|
|
23941
|
+
type: "undefined",
|
|
23942
|
+
reference: undefined_,
|
|
23943
|
+
expects: "undefined",
|
|
23944
|
+
async: false,
|
|
23945
|
+
message,
|
|
23946
|
+
_run(dataset, config2) {
|
|
23947
|
+
if (dataset.value === void 0) {
|
|
23948
|
+
dataset.typed = true;
|
|
23949
|
+
} else {
|
|
23950
|
+
_addIssue(this, "type", dataset, config2);
|
|
23951
|
+
}
|
|
23952
|
+
return dataset;
|
|
23953
|
+
}
|
|
23954
|
+
};
|
|
23955
|
+
}
|
|
23956
|
+
function _subIssues(datasets) {
|
|
23957
|
+
let issues;
|
|
23958
|
+
if (datasets) {
|
|
23959
|
+
for (const dataset of datasets) {
|
|
23960
|
+
if (issues) {
|
|
23961
|
+
issues.push(...dataset.issues);
|
|
23962
|
+
} else {
|
|
23963
|
+
issues = dataset.issues;
|
|
23964
|
+
}
|
|
23965
|
+
}
|
|
23966
|
+
}
|
|
23967
|
+
return issues;
|
|
23968
|
+
}
|
|
23969
|
+
function union(options, message) {
|
|
23970
|
+
return {
|
|
23971
|
+
kind: "schema",
|
|
23972
|
+
type: "union",
|
|
23973
|
+
reference: union,
|
|
23974
|
+
expects: _joinExpects(
|
|
23975
|
+
options.map((option) => option.expects),
|
|
23976
|
+
"|"
|
|
23977
|
+
),
|
|
23978
|
+
async: false,
|
|
23979
|
+
options,
|
|
23980
|
+
message,
|
|
23981
|
+
_run(dataset, config2) {
|
|
23982
|
+
let validDataset;
|
|
23983
|
+
let typedDatasets;
|
|
23984
|
+
let untypedDatasets;
|
|
23985
|
+
for (const schema of this.options) {
|
|
23986
|
+
const optionDataset = schema._run(
|
|
23987
|
+
{ typed: false, value: dataset.value },
|
|
23988
|
+
config2
|
|
23989
|
+
);
|
|
23990
|
+
if (optionDataset.typed) {
|
|
23991
|
+
if (optionDataset.issues) {
|
|
23992
|
+
if (typedDatasets) {
|
|
23993
|
+
typedDatasets.push(optionDataset);
|
|
23994
|
+
} else {
|
|
23995
|
+
typedDatasets = [optionDataset];
|
|
23996
|
+
}
|
|
23997
|
+
} else {
|
|
23998
|
+
validDataset = optionDataset;
|
|
23999
|
+
break;
|
|
24000
|
+
}
|
|
24001
|
+
} else {
|
|
24002
|
+
if (untypedDatasets) {
|
|
24003
|
+
untypedDatasets.push(optionDataset);
|
|
24004
|
+
} else {
|
|
24005
|
+
untypedDatasets = [optionDataset];
|
|
24006
|
+
}
|
|
24007
|
+
}
|
|
24008
|
+
}
|
|
24009
|
+
if (validDataset) {
|
|
24010
|
+
return validDataset;
|
|
24011
|
+
}
|
|
24012
|
+
if (typedDatasets) {
|
|
24013
|
+
if (typedDatasets.length === 1) {
|
|
24014
|
+
return typedDatasets[0];
|
|
24015
|
+
}
|
|
24016
|
+
_addIssue(this, "type", dataset, config2, {
|
|
24017
|
+
issues: _subIssues(typedDatasets)
|
|
24018
|
+
});
|
|
24019
|
+
dataset.typed = true;
|
|
24020
|
+
} else if (untypedDatasets?.length === 1) {
|
|
24021
|
+
return untypedDatasets[0];
|
|
24022
|
+
} else {
|
|
24023
|
+
_addIssue(this, "type", dataset, config2, {
|
|
24024
|
+
issues: _subIssues(untypedDatasets)
|
|
24025
|
+
});
|
|
24026
|
+
}
|
|
24027
|
+
return dataset;
|
|
24028
|
+
}
|
|
24029
|
+
};
|
|
24030
|
+
}
|
|
24031
|
+
function parse(schema, input, config2) {
|
|
24032
|
+
const dataset = schema._run(
|
|
24033
|
+
{ typed: false, value: input },
|
|
24034
|
+
getGlobalConfig(config2)
|
|
24035
|
+
);
|
|
24036
|
+
if (dataset.issues) {
|
|
24037
|
+
throw new ValiError(dataset.issues);
|
|
24038
|
+
}
|
|
24039
|
+
return dataset.value;
|
|
24040
|
+
}
|
|
24041
|
+
function pipe(...pipe2) {
|
|
24042
|
+
return {
|
|
24043
|
+
...pipe2[0],
|
|
24044
|
+
pipe: pipe2,
|
|
24045
|
+
_run(dataset, config2) {
|
|
24046
|
+
for (const item of pipe2) {
|
|
24047
|
+
if (item.kind !== "metadata") {
|
|
24048
|
+
if (dataset.issues && (item.kind === "schema" || item.kind === "transformation")) {
|
|
24049
|
+
dataset.typed = false;
|
|
24050
|
+
break;
|
|
24051
|
+
}
|
|
24052
|
+
if (!dataset.issues || !config2.abortEarly && !config2.abortPipeEarly) {
|
|
24053
|
+
dataset = item._run(dataset, config2);
|
|
24054
|
+
}
|
|
24055
|
+
}
|
|
24056
|
+
}
|
|
24057
|
+
return dataset;
|
|
24058
|
+
}
|
|
24059
|
+
};
|
|
24060
|
+
}
|
|
24061
|
+
|
|
23435
24062
|
// src/SpeechServices/resolveFunctionOrReturnValue.ts
|
|
23436
24063
|
function isFunction(value) {
|
|
23437
24064
|
return typeof value === "function";
|
|
@@ -23440,98 +24067,136 @@
|
|
|
23440
24067
|
return isFunction(fnOrValue) ? fnOrValue() : fnOrValue;
|
|
23441
24068
|
}
|
|
23442
24069
|
|
|
24070
|
+
// src/SpeechServices/SpeechSDK.ts
|
|
24071
|
+
var import_microsoft_cognitiveservices_speech = __toESM(require_microsoft_cognitiveservices_speech_sdk());
|
|
24072
|
+
var SpeechSDK_default = {
|
|
24073
|
+
AudioConfig: import_microsoft_cognitiveservices_speech.AudioConfig,
|
|
24074
|
+
OutputFormat: import_microsoft_cognitiveservices_speech.OutputFormat,
|
|
24075
|
+
ResultReason: import_microsoft_cognitiveservices_speech.ResultReason,
|
|
24076
|
+
SpeechConfig: import_microsoft_cognitiveservices_speech.SpeechConfig,
|
|
24077
|
+
SpeechRecognizer: import_microsoft_cognitiveservices_speech.SpeechRecognizer
|
|
24078
|
+
};
|
|
24079
|
+
|
|
24080
|
+
// src/SpeechServices/SpeechToText/validation/credentialsSchema.ts
|
|
24081
|
+
var credentialsSchema = pipe(
|
|
24082
|
+
intersect([
|
|
24083
|
+
union(
|
|
24084
|
+
[
|
|
24085
|
+
object({
|
|
24086
|
+
authorizationToken: string(),
|
|
24087
|
+
subscriptionKey: optional(undefined_('"subscriptionKey" must be unset when "authorizationToken" is set.'))
|
|
24088
|
+
}),
|
|
24089
|
+
object({
|
|
24090
|
+
authorizationToken: optional(undefined_('"authorizationToken" must be unset when "subscriptionKey" is set.')),
|
|
24091
|
+
subscriptionKey: string()
|
|
24092
|
+
})
|
|
24093
|
+
],
|
|
24094
|
+
'The object must either have either "authorizationToken" or "subscriptionKey" set, but not both.'
|
|
24095
|
+
),
|
|
24096
|
+
union(
|
|
24097
|
+
[
|
|
24098
|
+
object({
|
|
24099
|
+
customVoiceHostname: optional(undefined_('"customVoiceHostname" must be unest when "region" is set.')),
|
|
24100
|
+
region: string(),
|
|
24101
|
+
speechRecognitionHostname: optional(
|
|
24102
|
+
undefined_('"speechRecognitionHostname" must be unest when "region" is set.')
|
|
24103
|
+
),
|
|
24104
|
+
speechSynthesisHostname: optional(undefined_('"speechSynthesisHostname" must be unest when "region" is set.'))
|
|
24105
|
+
}),
|
|
24106
|
+
object({
|
|
24107
|
+
customVoiceHostname: optional(union([string(), undefined_()])),
|
|
24108
|
+
region: optional(undefined_('"region" must be unset when "*Hostname" is set.')),
|
|
24109
|
+
speechRecognitionHostname: string(),
|
|
24110
|
+
speechSynthesisHostname: string()
|
|
24111
|
+
})
|
|
24112
|
+
],
|
|
24113
|
+
'The object must either have either "region" or "*Hostname" set, but not both.'
|
|
24114
|
+
)
|
|
24115
|
+
]),
|
|
24116
|
+
readonly()
|
|
24117
|
+
);
|
|
24118
|
+
var credentialsSchema_default = credentialsSchema;
|
|
24119
|
+
|
|
24120
|
+
// src/SpeechServices/SpeechToText/validation/enableTelemetrySchema.ts
|
|
24121
|
+
var enableTelemetrySchema = optional(boolean());
|
|
24122
|
+
var enableTelemetrySchema_default = enableTelemetrySchema;
|
|
24123
|
+
|
|
24124
|
+
// src/SpeechServices/SpeechToText/validation/initialSilenceTimeoutSchema.ts
|
|
24125
|
+
var initialSilenceTimeoutSchema = optional(pipe(number(), minValue(1), maxValue(6e4)));
|
|
24126
|
+
var initialSilenceTimeoutSchema_default = initialSilenceTimeoutSchema;
|
|
24127
|
+
|
|
24128
|
+
// src/SpeechServices/SpeechToText/validation/looseEventsSchema.ts
|
|
24129
|
+
var looseEventsSchema = optional(boolean(), false);
|
|
24130
|
+
var looseEventsSchema_default = looseEventsSchema;
|
|
24131
|
+
|
|
24132
|
+
// src/SpeechServices/SpeechToText/validation/referenceGrammarsSchema.ts
|
|
24133
|
+
var referenceGrammarsSchema = pipe(
|
|
24134
|
+
optional(array(string()), []),
|
|
24135
|
+
// any(),
|
|
24136
|
+
// array(string()),
|
|
24137
|
+
// transform<string[], readonly string[]>(value => (Object.isFrozen(value) ? value : Object.freeze([...value])))
|
|
24138
|
+
transform((value) => Object.isFrozen(value) ? value : Object.freeze([...value]))
|
|
24139
|
+
);
|
|
24140
|
+
var referenceGrammarsSchema_default = referenceGrammarsSchema;
|
|
24141
|
+
|
|
24142
|
+
// src/SpeechServices/SpeechToText/validation/speechRecognitionEndpointIdSchema.ts
|
|
24143
|
+
var speechRecognitionEndpointIdSchema = optional(string());
|
|
24144
|
+
var speechRecognitionEndpointIdSchema_default = speechRecognitionEndpointIdSchema;
|
|
24145
|
+
|
|
24146
|
+
// src/SpeechServices/SpeechToText/validation/textNormalizationSchema.ts
|
|
24147
|
+
var textNormalizationSchema = optional(
|
|
24148
|
+
enum_({
|
|
24149
|
+
display: "display",
|
|
24150
|
+
itn: "itn",
|
|
24151
|
+
lexical: "lexical",
|
|
24152
|
+
maskeditn: "maskeditn"
|
|
24153
|
+
}),
|
|
24154
|
+
"display"
|
|
24155
|
+
);
|
|
24156
|
+
var textNormalizationSchema_default = textNormalizationSchema;
|
|
24157
|
+
|
|
23443
24158
|
// src/SpeechServices/patchOptions.ts
|
|
24159
|
+
var { AudioConfig: AudioConfig2 } = SpeechSDK_default;
|
|
23444
24160
|
var shouldWarnOnSubscriptionKey = true;
|
|
23445
24161
|
function patchOptions(init) {
|
|
23446
24162
|
const {
|
|
23447
24163
|
audioConfig,
|
|
23448
|
-
|
|
24164
|
+
credentials,
|
|
23449
24165
|
enableTelemetry,
|
|
24166
|
+
initialSilenceTimeout,
|
|
23450
24167
|
looseEvent,
|
|
23451
24168
|
referenceGrammars,
|
|
23452
|
-
region = "westus",
|
|
23453
24169
|
speechRecognitionEndpointId,
|
|
23454
|
-
subscriptionKey,
|
|
23455
24170
|
textNormalization
|
|
23456
24171
|
} = init;
|
|
23457
|
-
let {
|
|
24172
|
+
let { looseEvents } = init;
|
|
23458
24173
|
if (typeof looseEvent !== "undefined") {
|
|
23459
24174
|
console.warn('web-speech-cognitive-services: The option "looseEvent" should be named as "looseEvents".');
|
|
23460
24175
|
looseEvents = looseEvent;
|
|
23461
24176
|
}
|
|
23462
|
-
if (!credentials) {
|
|
23463
|
-
if (!authorizationToken && !subscriptionKey) {
|
|
23464
|
-
throw new Error("web-speech-cognitive-services: Credentials must be specified.");
|
|
23465
|
-
} else {
|
|
23466
|
-
console.warn(
|
|
23467
|
-
"web-speech-cognitive-services: We are deprecating authorizationToken, region, and subscriptionKey. Please use credentials instead. The deprecated option will be removed on or after 2020-11-14."
|
|
23468
|
-
);
|
|
23469
|
-
credentials = async () => typeof init.authorizationToken !== "undefined" ? { authorizationToken: await resolveFunctionOrReturnValue(init.authorizationToken), region } : { region, subscriptionKey: await resolveFunctionOrReturnValue(init.subscriptionKey) };
|
|
23470
|
-
}
|
|
23471
|
-
}
|
|
23472
24177
|
return Object.freeze({
|
|
23473
|
-
audioConfig,
|
|
23474
|
-
|
|
24178
|
+
audioConfig: audioConfig || AudioConfig2.fromDefaultMicrophoneInput(),
|
|
24179
|
+
// We set telemetry to true to honor the default telemetry settings of Speech SDK
|
|
24180
|
+
// https://github.com/Microsoft/cognitive-services-speech-sdk-js#data--telemetry
|
|
24181
|
+
enableTelemetry: parse(enableTelemetrySchema_default, enableTelemetry),
|
|
23475
24182
|
fetchCredentials: async () => {
|
|
23476
|
-
const
|
|
23477
|
-
|
|
23478
|
-
customVoiceHostname,
|
|
23479
|
-
region: region2,
|
|
23480
|
-
speechRecognitionHostname,
|
|
23481
|
-
speechSynthesisHostname,
|
|
23482
|
-
subscriptionKey: subscriptionKey2
|
|
23483
|
-
} = await resolveFunctionOrReturnValue(credentials);
|
|
23484
|
-
if (!authorizationToken2 && !subscriptionKey2 || authorizationToken2 && subscriptionKey2) {
|
|
23485
|
-
throw new Error(
|
|
23486
|
-
'web-speech-cognitive-services: Either "authorizationToken" or "subscriptionKey" must be provided.'
|
|
23487
|
-
);
|
|
23488
|
-
} else if (!region2 && !(speechRecognitionHostname && speechSynthesisHostname)) {
|
|
23489
|
-
throw new Error(
|
|
23490
|
-
'web-speech-cognitive-services: Either "region" or "speechRecognitionHostname" and "speechSynthesisHostname" must be set.'
|
|
23491
|
-
);
|
|
23492
|
-
} else if (region2 && (customVoiceHostname || speechRecognitionHostname || speechSynthesisHostname)) {
|
|
23493
|
-
throw new Error(
|
|
23494
|
-
'web-speech-cognitive-services: Only either "region" or "customVoiceHostname", "speechRecognitionHostname" and "speechSynthesisHostname" can be set.'
|
|
23495
|
-
);
|
|
23496
|
-
} else if (authorizationToken2) {
|
|
23497
|
-
if (typeof authorizationToken2 !== "string") {
|
|
23498
|
-
throw new Error('web-speech-cognitive-services: "authorizationToken" must be a string.');
|
|
23499
|
-
}
|
|
23500
|
-
} else if (typeof subscriptionKey2 !== "string") {
|
|
23501
|
-
throw new Error('web-speech-cognitive-services: "subscriptionKey" must be a string.');
|
|
23502
|
-
}
|
|
23503
|
-
if (shouldWarnOnSubscriptionKey && subscriptionKey2) {
|
|
24183
|
+
const parsedCredentials = parse(credentialsSchema_default, await resolveFunctionOrReturnValue(credentials));
|
|
24184
|
+
if (shouldWarnOnSubscriptionKey && parsedCredentials.subscriptionKey) {
|
|
23504
24185
|
console.warn(
|
|
23505
24186
|
"web-speech-cognitive-services: In production environment, subscription key should not be used, authorization token should be used instead."
|
|
23506
24187
|
);
|
|
23507
24188
|
shouldWarnOnSubscriptionKey = false;
|
|
23508
24189
|
}
|
|
23509
|
-
return
|
|
23510
|
-
...typeof authorizationToken2 !== "undefined" ? { authorizationToken: authorizationToken2 } : { subscriptionKey: subscriptionKey2 },
|
|
23511
|
-
...typeof region2 !== "undefined" ? { region: region2 } : {
|
|
23512
|
-
customVoiceHostname,
|
|
23513
|
-
speechRecognitionHostname,
|
|
23514
|
-
speechSynthesisHostname
|
|
23515
|
-
}
|
|
23516
|
-
};
|
|
24190
|
+
return parsedCredentials;
|
|
23517
24191
|
},
|
|
23518
|
-
|
|
23519
|
-
|
|
23520
|
-
|
|
23521
|
-
|
|
24192
|
+
initialSilenceTimeout: parse(initialSilenceTimeoutSchema_default, initialSilenceTimeout),
|
|
24193
|
+
looseEvents: parse(looseEventsSchema_default, looseEvents),
|
|
24194
|
+
referenceGrammars: parse(referenceGrammarsSchema_default, referenceGrammars),
|
|
24195
|
+
speechRecognitionEndpointId: parse(speechRecognitionEndpointIdSchema_default, speechRecognitionEndpointId),
|
|
24196
|
+
textNormalization: parse(textNormalizationSchema_default, textNormalization)
|
|
23522
24197
|
});
|
|
23523
24198
|
}
|
|
23524
24199
|
|
|
23525
|
-
// src/SpeechServices/SpeechSDK.ts
|
|
23526
|
-
var import_microsoft_cognitiveservices_speech = __toESM(require_microsoft_cognitiveservices_speech_sdk());
|
|
23527
|
-
var SpeechSDK_default = {
|
|
23528
|
-
AudioConfig: import_microsoft_cognitiveservices_speech.AudioConfig,
|
|
23529
|
-
OutputFormat: import_microsoft_cognitiveservices_speech.OutputFormat,
|
|
23530
|
-
ResultReason: import_microsoft_cognitiveservices_speech.ResultReason,
|
|
23531
|
-
SpeechConfig: import_microsoft_cognitiveservices_speech.SpeechConfig,
|
|
23532
|
-
SpeechRecognizer: import_microsoft_cognitiveservices_speech.SpeechRecognizer
|
|
23533
|
-
};
|
|
23534
|
-
|
|
23535
24200
|
// ../../node_modules/p-defer/index.js
|
|
23536
24201
|
function pDefer() {
|
|
23537
24202
|
const deferred = {};
|
|
@@ -23585,16 +24250,16 @@
|
|
|
23585
24250
|
|
|
23586
24251
|
// src/SpeechServices/SpeechToText/private/FakeArray.ts
|
|
23587
24252
|
var FakeArray = class {
|
|
23588
|
-
constructor(
|
|
23589
|
-
if (!
|
|
24253
|
+
constructor(array2) {
|
|
24254
|
+
if (!array2) {
|
|
23590
24255
|
throw new Error("array must be set.");
|
|
23591
24256
|
}
|
|
23592
|
-
this.#array =
|
|
23593
|
-
for (const key in
|
|
24257
|
+
this.#array = array2;
|
|
24258
|
+
for (const key in array2) {
|
|
23594
24259
|
Object.defineProperty(this, key, {
|
|
23595
24260
|
enumerable: true,
|
|
23596
24261
|
get() {
|
|
23597
|
-
return
|
|
24262
|
+
return array2[key];
|
|
23598
24263
|
}
|
|
23599
24264
|
});
|
|
23600
24265
|
}
|
|
@@ -23685,8 +24350,8 @@
|
|
|
23685
24350
|
|
|
23686
24351
|
// src/SpeechServices/SpeechToText/private/averageAmplitude.ts
|
|
23687
24352
|
function averageAmplitude(arrayBuffer) {
|
|
23688
|
-
const
|
|
23689
|
-
return
|
|
24353
|
+
const array2 = Array.from(new Int16Array(arrayBuffer));
|
|
24354
|
+
return array2.reduce((averageAmplitude2, amplitude) => averageAmplitude2 + Math.abs(amplitude), 0) / array2.length;
|
|
23690
24355
|
}
|
|
23691
24356
|
|
|
23692
24357
|
// src/SpeechServices/SpeechToText/private/prepareAudioConfig.ts
|
|
@@ -23834,6 +24499,7 @@
|
|
|
23834
24499
|
|
|
23835
24500
|
// src/SpeechServices/SpeechToText/createSpeechRecognitionPonyfillFromRecognizer.ts
|
|
23836
24501
|
var { ResultReason: ResultReason2, SpeechRecognizer: SpeechRecognizer2 } = SpeechSDK_default;
|
|
24502
|
+
var enableTelemetrySchema2 = union([boolean(), undefined_()]);
|
|
23837
24503
|
function createSpeechRecognitionPonyfillFromRecognizer({
|
|
23838
24504
|
createRecognizer,
|
|
23839
24505
|
enableTelemetry,
|
|
@@ -23841,7 +24507,12 @@
|
|
|
23841
24507
|
referenceGrammars,
|
|
23842
24508
|
textNormalization
|
|
23843
24509
|
}) {
|
|
23844
|
-
|
|
24510
|
+
createRecognizer = parse(function_(), createRecognizer);
|
|
24511
|
+
enableTelemetry = parse(enableTelemetrySchema2, enableTelemetry);
|
|
24512
|
+
looseEvents = parse(boolean(), looseEvents);
|
|
24513
|
+
referenceGrammars = parse(referenceGrammarsSchema_default, referenceGrammars);
|
|
24514
|
+
textNormalization = parse(textNormalizationSchema_default, textNormalization);
|
|
24515
|
+
typeof enableTelemetry !== "undefined" && SpeechRecognizer2.enableTelemetry(enableTelemetry);
|
|
23845
24516
|
class SpeechRecognition extends EventTarget {
|
|
23846
24517
|
#continuous = false;
|
|
23847
24518
|
#eventListenerMap = new EventListenerMap(this);
|
|
@@ -24211,18 +24882,17 @@
|
|
|
24211
24882
|
}
|
|
24212
24883
|
|
|
24213
24884
|
// src/SpeechServices/SpeechToText/createSpeechRecognitionPonyfill.ts
|
|
24214
|
-
var {
|
|
24885
|
+
var { OutputFormat: OutputFormat2, SpeechConfig: SpeechConfig2, SpeechRecognizer: SpeechRecognizer3 } = SpeechSDK_default;
|
|
24215
24886
|
function createSpeechRecognitionPonyfill(options) {
|
|
24216
24887
|
const {
|
|
24217
|
-
audioConfig
|
|
24218
|
-
|
|
24219
|
-
// https://github.com/Microsoft/cognitive-services-speech-sdk-js#data--telemetry
|
|
24220
|
-
enableTelemetry = true,
|
|
24888
|
+
audioConfig,
|
|
24889
|
+
enableTelemetry,
|
|
24221
24890
|
fetchCredentials,
|
|
24891
|
+
initialSilenceTimeout,
|
|
24222
24892
|
looseEvents,
|
|
24223
24893
|
referenceGrammars,
|
|
24224
24894
|
speechRecognitionEndpointId,
|
|
24225
|
-
textNormalization
|
|
24895
|
+
textNormalization
|
|
24226
24896
|
} = patchOptions(options);
|
|
24227
24897
|
if (!audioConfig && (!window.navigator.mediaDevices || !window.navigator.mediaDevices.getUserMedia)) {
|
|
24228
24898
|
throw new Error(
|
|
@@ -24233,7 +24903,7 @@
|
|
|
24233
24903
|
const credentials = await fetchCredentials();
|
|
24234
24904
|
let speechConfig;
|
|
24235
24905
|
if (typeof credentials.speechRecognitionHostname !== "undefined") {
|
|
24236
|
-
const host = new URL("wss://
|
|
24906
|
+
const host = new URL("wss://localhost:443");
|
|
24237
24907
|
host.hostname = credentials.speechRecognitionHostname;
|
|
24238
24908
|
if (credentials.authorizationToken) {
|
|
24239
24909
|
speechConfig = SpeechConfig2.fromHost(host);
|
|
@@ -24249,6 +24919,7 @@
|
|
|
24249
24919
|
}
|
|
24250
24920
|
speechConfig.outputFormat = OutputFormat2.Detailed;
|
|
24251
24921
|
speechConfig.speechRecognitionLanguage = lang || "en-US";
|
|
24922
|
+
typeof initialSilenceTimeout === "number" && speechConfig.setProperty(import_microsoft_cognitiveservices_speech_sdk.PropertyId.SpeechServiceConnection_InitialSilenceTimeoutMs, "" + initialSilenceTimeout);
|
|
24252
24923
|
return new SpeechRecognizer3(speechConfig, audioConfig);
|
|
24253
24924
|
};
|
|
24254
24925
|
return createSpeechRecognitionPonyfillFromRecognizer({
|
|
@@ -25734,7 +26405,7 @@
|
|
|
25734
26405
|
}
|
|
25735
26406
|
var meta = document.createElement("meta");
|
|
25736
26407
|
meta.setAttribute("name", "web-speech-cognitive-services");
|
|
25737
|
-
meta.setAttribute("content", `version=${"8.0.
|
|
26408
|
+
meta.setAttribute("content", `version=${"8.0.1-main.7b3a347"}`);
|
|
25738
26409
|
document.head.appendChild(meta);
|
|
25739
26410
|
|
|
25740
26411
|
// src/index.umd.js
|