arcane-os 0.5.16 → 0.5.18
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/CHANGELOG.md +44 -0
- package/README.md +42 -19
- package/bin/arcane-test.mjs +16 -13
- package/browser-runtime/ai/browser-speech-artifacts.mjs +41 -38
- package/browser-runtime/ai/browser-speech-providers.mjs +53 -46
- package/browser-runtime/ai/browser-wasm-llm-provider.mjs +127 -124
- package/browser-runtime/ai/browser-wasm.mjs +6 -3
- package/browser-runtime/ai/browser-wllama-runtime.mjs +26 -23
- package/browser-runtime/ai/model-controller.mjs +94 -91
- package/browser-runtime/ai/speech-worker-client.mjs +12 -9
- package/browser-runtime/ai/speech-worker-runtime.mjs +56 -53
- package/browser-runtime/dependencies/strong-type/index.js +207 -82
- package/browser-runtime/dependencies/strong-type/package.json +15 -6
- package/browser-runtime/dom-event-instrumentation.mjs +24 -20
- package/browser-runtime/event-manager.mjs +111 -108
- package/browser-runtime/speech-text.mjs +35 -0
- package/docs/architecture.md +1 -1
- package/docs/reference/README.md +8 -8
- package/docs/reference/ai/browser-speech.md +230 -16
- package/docs/reference/ai/twin-cloud.md +1 -1
- package/docs/reference/availability-and-normalization.md +42 -1
- package/docs/reference/cli.md +1 -1
- package/docs/reference/core/arcane-ai-contracts.md +1 -1
- package/docs/reference/inventory/package-api.json +60 -4
- package/docs/reference/inventory/runtime-components.json +2 -2
- package/docs/reference/inventory/runtime-modules.json +29 -31
- package/docs/reference/protocols.md +17 -13
- package/docs/reference/runtime-components.md +6 -5
- package/docs/reference/runtime-modules.md +212 -70
- package/docs/reference/sdk-api.md +197 -11
- package/examples/wasm-ai-demo/index.html +1 -0
- package/node_modules/event-pubsub/node_modules/strong-type/README.md +408 -0
- package/node_modules/event-pubsub/node_modules/strong-type/assets/strong-type-header.png +0 -0
- package/node_modules/event-pubsub/node_modules/strong-type/index.js +1151 -0
- package/node_modules/event-pubsub/node_modules/strong-type/licence +21 -0
- package/node_modules/event-pubsub/node_modules/strong-type/node.js +125 -0
- package/node_modules/event-pubsub/node_modules/strong-type/package.json +61 -0
- package/node_modules/strong-type/README.md +42 -24
- package/node_modules/strong-type/benchmark/core.js +324 -0
- package/node_modules/strong-type/index.js +207 -82
- package/node_modules/strong-type/package.json +14 -6
- package/package.json +4 -3
- package/runtime/arcane/components/app-bar.html +5 -2
- package/runtime/arcane/components/assistant-panel.html +5 -2
- package/runtime/arcane/components/chart.html +15 -12
- package/runtime/arcane/components/chat.html +118 -141
- package/runtime/arcane/components/dashboard-config.html +6 -3
- package/runtime/arcane/components/data-view.html +4 -1
- package/runtime/arcane/components/directory-picker.html +5 -2
- package/runtime/arcane/components/document-inspector.html +6 -3
- package/runtime/arcane/components/file-drop.html +5 -2
- package/runtime/arcane/components/file-inspector.html +9 -6
- package/runtime/arcane/components/file-manager.html +16 -13
- package/runtime/arcane/components/local-ai-status.html +5 -2
- package/runtime/arcane/components/markdown-document.html +14 -11
- package/runtime/arcane/components/markdown-editor.html +4 -1
- package/runtime/arcane/components/modal.html +4 -1
- package/runtime/arcane/components/output-panel.html +6 -3
- package/runtime/arcane/components/preferences-form.html +4 -1
- package/runtime/arcane/components/record-timeline.html +8 -5
- package/runtime/arcane/components/relationship-board.html +9 -6
- package/runtime/arcane/components/source-code-viewer.html +12 -9
- package/runtime/arcane/components/source-explanation.html +8 -5
- package/runtime/arcane/components/speech.html +24 -21
- package/runtime/arcane/components/summary-strip.html +4 -1
- package/runtime/arcane/components/task-progress.html +6 -3
- package/runtime/arcane/components/terminal-workspace.html +4 -1
- package/runtime/arcane/components/voice-transcription.html +11 -8
- package/runtime/arcane/components/web-navigator.html +5 -2
- package/runtime/arcane/entities/ApiModelRecord.js +5 -2
- package/runtime/arcane/entities/Calculation.js +5 -2
- package/runtime/arcane/entities/Chat.js +33 -33
- package/runtime/arcane/entities/CommunicationMessage.js +4 -1
- package/runtime/arcane/entities/CommunicationThread.js +4 -1
- package/runtime/arcane/entities/File.js +1 -1
- package/runtime/arcane/entities/Image.js +8 -5
- package/runtime/arcane/entities/IntentEnvelope.js +20 -17
- package/runtime/arcane/entities/Preference.js +9 -6
- package/runtime/arcane/entities/Theme.js +5 -2
- package/runtime/arcane/entities/User.js +11 -11
- package/runtime/arcane/entities/Weather.js +5 -2
- package/runtime/arcane/modules/AI.js +503 -187
- package/runtime/arcane/modules/AIPreferenceRuntime.js +5 -2
- package/runtime/arcane/modules/AIPreferenceTuple.js +9 -6
- package/runtime/arcane/modules/AIProviderRuntime.js +117 -92
- package/runtime/arcane/modules/AIResponseURLPolicy.js +148 -62
- package/runtime/arcane/modules/AIRuntimeState.js +29 -26
- package/runtime/arcane/modules/AnsiText.js +4 -1
- package/runtime/arcane/modules/ApiModelDatabase.js +22 -19
- package/runtime/arcane/modules/AppDataScope.js +8 -5
- package/runtime/arcane/modules/ArcaneCommunicationBridge.js +4 -1
- package/runtime/arcane/modules/ArcaneNavigationPolicy.js +8 -5
- package/runtime/arcane/modules/ArcaneNetworkPolicy.js +18 -15
- package/runtime/arcane/modules/AsyncBoundary.js +13 -10
- package/runtime/arcane/modules/BrowserTestSuite.js +19 -16
- package/runtime/arcane/modules/CalculatorEngine.js +5 -2
- package/runtime/arcane/modules/ChatRecords.js +18 -15
- package/runtime/arcane/modules/CommunicationAppController.js +9 -6
- package/runtime/arcane/modules/CommunicationHub.js +9 -6
- package/runtime/arcane/modules/CommunicationPreferences.js +4 -1
- package/runtime/arcane/modules/CommunicationProviderRegistry.js +4 -1
- package/runtime/arcane/modules/ComponentContracts.js +56 -53
- package/runtime/arcane/modules/ConfiguredAIChatSession.js +30 -27
- package/runtime/arcane/modules/ConversationActionItems.js +15 -12
- package/runtime/arcane/modules/ConversationClosingReport.js +11 -8
- package/runtime/arcane/modules/ConversationTimebox.js +28 -25
- package/runtime/arcane/modules/CoreLocalModelCatalog.js +17 -14
- package/runtime/arcane/modules/DBLS.js +7 -4
- package/runtime/arcane/modules/DBOPFS.js +7 -7
- package/runtime/arcane/modules/DBOPFSDocumentLibrary.js +34 -31
- package/runtime/arcane/modules/DevelopmentWorkspace.js +4 -1
- package/runtime/arcane/modules/DirectoryPicker.js +8 -5
- package/runtime/arcane/modules/DocumentLexicalSearch.js +11 -8
- package/runtime/arcane/modules/DocumentNavigation.js +7 -4
- package/runtime/arcane/modules/Errors.js +28 -25
- package/runtime/arcane/modules/HTMLImport.js +7 -4
- package/runtime/arcane/modules/IsolatedModelQuestionRunner.js +15 -12
- package/runtime/arcane/modules/LocalAIReadiness.js +21 -18
- package/runtime/arcane/modules/LocalAIReadinessController.js +6 -3
- package/runtime/arcane/modules/MD.js +1 -1
- package/runtime/arcane/modules/Mail.js +46 -43
- package/runtime/arcane/modules/MailOutbox.mjs +48 -45
- package/runtime/arcane/modules/MailTransport.mjs +29 -26
- package/runtime/arcane/modules/MarkdownSpeech.js +1 -50
- package/runtime/arcane/modules/MemoryRecords.js +7 -4
- package/runtime/arcane/modules/MessageAdvisory.js +6 -3
- package/runtime/arcane/modules/ModelDefinition.js +7 -4
- package/runtime/arcane/modules/Ollama.js +6 -3
- package/runtime/arcane/modules/OllamaModelIdentifier.js +4 -1
- package/runtime/arcane/modules/OpenMeteoWeatherProvider.js +18 -15
- package/runtime/arcane/modules/PersistentAIChatSession.js +33 -30
- package/runtime/arcane/modules/PreferenceStore.js +20 -17
- package/runtime/arcane/modules/PreparedSpeech.js +485 -0
- package/runtime/arcane/modules/Questionnaire.js +6 -3
- package/runtime/arcane/modules/RecordLinkIndex.js +4 -1
- package/runtime/arcane/modules/RecordPassageIndex.js +9 -6
- package/runtime/arcane/modules/RecordReviewStore.js +12 -9
- package/runtime/arcane/modules/RiskSignalAnalyzer.js +4 -1
- package/runtime/arcane/modules/ScopedOPFSCache.js +6 -3
- package/runtime/arcane/modules/ScreenCapture.js +20 -17
- package/runtime/arcane/modules/SpeechPlayback.js +61 -28
- package/runtime/arcane/modules/StaticDocumentCatalog.js +33 -30
- package/runtime/arcane/modules/SystemAppearance.js +5 -2
- package/runtime/arcane/modules/SystemToolRegistry.js +6 -3
- package/runtime/arcane/modules/TerminalClient.js +14 -11
- package/runtime/arcane/modules/TerminalCommandRegistry.js +4 -1
- package/runtime/arcane/modules/ThemeBootstrap.js +9 -6
- package/runtime/arcane/modules/ThemeManager.js +5 -2
- package/runtime/arcane/modules/TimeGuard.js +1 -1
- package/runtime/arcane/modules/ToolCallRouter.js +11 -8
- package/runtime/arcane/modules/WaitForComponent.js +19 -16
- package/runtime/arcane/modules/YouTubeMedia.js +4 -1
- package/runtime/strong-type/index.js +1276 -352
- package/runtime/strong-type/package.json +69 -45
- package/src/app-descriptor.mjs +17 -14
- package/src/application-tests.mjs +4 -1
- package/src/cli/main.mjs +8 -5
- package/src/constants.mjs +4 -1
- package/src/dev-server.mjs +8 -5
- package/src/doctor.mjs +5 -2
- package/src/dom-event-instrumentation.mjs +24 -20
- package/src/errors.mjs +7 -3
- package/src/event-manager.mjs +111 -108
- package/src/event-queue.mjs +8 -5
- package/src/events.mjs +12 -9
- package/src/import-map.mjs +36 -27
- package/src/installed-sdk-runtime.mjs +4 -1
- package/src/integrated-provider-loader.mjs +9 -6
- package/src/mail-credentials.mjs +16 -13
- package/src/mail-server.mjs +53 -50
- package/src/mail.mjs +18 -15
- package/src/native-plan.mjs +12 -9
- package/src/native-provider-loader.mjs +7 -4
- package/src/packager/core.mjs +18 -15
- package/src/process.mjs +6 -3
- package/src/release-bundle.mjs +14 -11
- package/src/runtime.mjs +4 -1
- package/src/scaffold.mjs +9 -6
- package/src/sdk-browser-runtime.mjs +4 -1
- package/src/source-server.mjs +17 -14
- package/src/targets/index.mjs +5 -2
- package/src/templates/workspace-template.mjs +13 -6
- package/src/testing-loader.mjs +7 -4
- package/src/testing.mjs +10 -7
- package/src/toolchain.mjs +13 -10
- package/src/update-check.mjs +9 -6
- package/src/workspace-operation-lock.mjs +14 -11
- package/src/workspace-runtime.mjs +4 -1
- package/src/workspace.mjs +17 -14
- package/runtime/arcane/modules/AIResponseLength.js +0 -32
|
@@ -7,44 +7,70 @@ class FakeCore{
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
const brandProbe={};
|
|
10
|
+
const brandFailure=Symbol('strong-type brand failure');
|
|
11
|
+
const noArguments=Object.freeze([]);
|
|
12
|
+
const brandProbeArguments=Object.freeze([brandProbe]);
|
|
13
|
+
const emptyStringArguments=Object.freeze(['']);
|
|
14
|
+
const segmentProbeArguments=Object.freeze([-1]);
|
|
15
|
+
const functionToString=Function.prototype.toString;
|
|
16
|
+
const objectConstructorSource=functionToString.call(Object);
|
|
17
|
+
const objectGetPrototypeOf=Object.getPrototypeOf;
|
|
18
|
+
const reflectApply=Reflect.apply;
|
|
19
|
+
|
|
20
|
+
const getterFor=function(prototype,property){
|
|
21
|
+
if(!prototype){
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
10
24
|
|
|
11
|
-
const tryBrand=function(check){
|
|
12
25
|
try{
|
|
13
|
-
|
|
14
|
-
return
|
|
26
|
+
const descriptor=Object.getOwnPropertyDescriptor(prototype,property);
|
|
27
|
+
return descriptor && typeof descriptor.get === 'function' ? descriptor.get : false;
|
|
15
28
|
}catch(err){
|
|
16
29
|
return false;
|
|
17
30
|
}
|
|
18
31
|
};
|
|
19
32
|
|
|
20
|
-
const
|
|
21
|
-
if(
|
|
33
|
+
const applyBrand=function(value,check,args=noArguments){
|
|
34
|
+
if(typeof check !== 'function'){
|
|
22
35
|
return false;
|
|
23
36
|
}
|
|
24
37
|
|
|
25
|
-
|
|
38
|
+
try{
|
|
39
|
+
reflectApply(check,value,args);
|
|
40
|
+
return true;
|
|
41
|
+
}catch(err){
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
26
44
|
};
|
|
27
45
|
|
|
28
|
-
const
|
|
46
|
+
const applyValue=function(value,check,args=noArguments){
|
|
47
|
+
if(typeof check !== 'function'){
|
|
48
|
+
return brandFailure;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
try{
|
|
52
|
+
return reflectApply(check,value,args);
|
|
53
|
+
}catch(err){
|
|
54
|
+
return brandFailure;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const methodBrand=function(value,prototype,method,args=noArguments){
|
|
29
59
|
if(!prototype){
|
|
30
60
|
return false;
|
|
31
61
|
}
|
|
32
62
|
|
|
33
|
-
|
|
34
|
-
|
|
63
|
+
let check;
|
|
64
|
+
try{
|
|
65
|
+
check=prototype[method];
|
|
66
|
+
}catch(err){
|
|
35
67
|
return false;
|
|
36
68
|
}
|
|
37
|
-
|
|
38
|
-
return tryBrand(()=>Reflect.apply(descriptor.get,value,[]));
|
|
69
|
+
return applyBrand(value,check,args);
|
|
39
70
|
};
|
|
40
71
|
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
if(!descriptor || typeof descriptor.get !== 'function'){
|
|
44
|
-
return undefined;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return Reflect.apply(descriptor.get,value,[]);
|
|
72
|
+
const getterBrand=function(value,prototype,property){
|
|
73
|
+
return applyBrand(value,getterFor(prototype,property));
|
|
48
74
|
};
|
|
49
75
|
|
|
50
76
|
const instanceOf=function(value,constructor){
|
|
@@ -67,17 +93,36 @@ const stringTagCheck=function(value,type){
|
|
|
67
93
|
}
|
|
68
94
|
};
|
|
69
95
|
|
|
96
|
+
const arrayBufferByteLengthGetter=getterFor(globalThis.ArrayBuffer && globalThis.ArrayBuffer.prototype,'byteLength');
|
|
97
|
+
const arrayBufferResizableGetter=getterFor(globalThis.ArrayBuffer && globalThis.ArrayBuffer.prototype,'resizable');
|
|
98
|
+
const sharedArrayBufferByteLengthGetter=getterFor(globalThis.SharedArrayBuffer && globalThis.SharedArrayBuffer.prototype,'byteLength');
|
|
99
|
+
const sharedArrayBufferGrowableGetter=getterFor(globalThis.SharedArrayBuffer && globalThis.SharedArrayBuffer.prototype,'growable');
|
|
100
|
+
const dataViewByteLengthGetter=getterFor(globalThis.DataView && globalThis.DataView.prototype,'byteLength');
|
|
101
|
+
const regExpSourceGetter=getterFor(globalThis.RegExp && globalThis.RegExp.prototype,'source');
|
|
102
|
+
const intlDateTimeFormatGetter=getterFor(globalThis.Intl && globalThis.Intl.DateTimeFormat && globalThis.Intl.DateTimeFormat.prototype,'format');
|
|
103
|
+
const intlCollatorCompareGetter=getterFor(globalThis.Intl && globalThis.Intl.Collator && globalThis.Intl.Collator.prototype,'compare');
|
|
104
|
+
const intlNumberFormatGetter=getterFor(globalThis.Intl && globalThis.Intl.NumberFormat && globalThis.Intl.NumberFormat.prototype,'format');
|
|
105
|
+
const dateGetTime=Date.prototype.getTime;
|
|
106
|
+
const mapHas=Map.prototype.has;
|
|
107
|
+
const weakMapHas=WeakMap.prototype.has;
|
|
108
|
+
const setHas=Set.prototype.has;
|
|
109
|
+
const weakSetHas=WeakSet.prototype.has;
|
|
110
|
+
const booleanValueOf=Boolean.prototype.valueOf;
|
|
111
|
+
const numberValueOf=Number.prototype.valueOf;
|
|
112
|
+
const bigIntValueOf=globalThis.BigInt && globalThis.BigInt.prototype.valueOf;
|
|
113
|
+
const stringValueOf=String.prototype.valueOf;
|
|
114
|
+
const symbolValueOf=globalThis.Symbol && globalThis.Symbol.prototype.valueOf;
|
|
115
|
+
|
|
70
116
|
const arrayBufferCheck=function(value){
|
|
71
|
-
return
|
|
117
|
+
return applyBrand(value,arrayBufferByteLengthGetter);
|
|
72
118
|
};
|
|
73
119
|
|
|
74
120
|
const sharedArrayBufferCheck=function(value){
|
|
75
|
-
|
|
76
|
-
return getterBrand(value,constructor && constructor.prototype,'byteLength');
|
|
121
|
+
return applyBrand(value,sharedArrayBufferByteLengthGetter);
|
|
77
122
|
};
|
|
78
123
|
|
|
79
124
|
const dataViewCheck=function(value){
|
|
80
|
-
return
|
|
125
|
+
return applyBrand(value,dataViewByteLengthGetter);
|
|
81
126
|
};
|
|
82
127
|
|
|
83
128
|
const arrayBufferViewCheck=function(value){
|
|
@@ -95,69 +140,61 @@ const typedArrayTagGetter=(function(){
|
|
|
95
140
|
})();
|
|
96
141
|
|
|
97
142
|
const typedArrayName=function(value){
|
|
98
|
-
if(!arrayBufferViewCheck(value) ||
|
|
143
|
+
if(!arrayBufferViewCheck(value) || typeof typedArrayTagGetter !== 'function'){
|
|
99
144
|
return false;
|
|
100
145
|
}
|
|
101
146
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}catch(err){
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
147
|
+
const name=applyValue(value,typedArrayTagGetter);
|
|
148
|
+
return name === brandFailure ? false : name;
|
|
107
149
|
};
|
|
108
150
|
|
|
109
151
|
const dateCheck=function(value){
|
|
110
|
-
return
|
|
152
|
+
return applyBrand(value,dateGetTime);
|
|
111
153
|
};
|
|
112
154
|
|
|
113
155
|
const validDateCheck=function(value){
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return !Number.isNaN(Reflect.apply(Date.prototype.getTime,value,[]));
|
|
156
|
+
const time=applyValue(value,dateGetTime);
|
|
157
|
+
return time !== brandFailure && !Number.isNaN(time);
|
|
119
158
|
};
|
|
120
159
|
|
|
121
160
|
const mapCheck=function(value){
|
|
122
|
-
return
|
|
161
|
+
return applyBrand(value,mapHas,brandProbeArguments);
|
|
123
162
|
};
|
|
124
163
|
|
|
125
164
|
const weakMapCheck=function(value){
|
|
126
|
-
return
|
|
165
|
+
return applyBrand(value,weakMapHas,brandProbeArguments);
|
|
127
166
|
};
|
|
128
167
|
|
|
129
168
|
const setCheck=function(value){
|
|
130
|
-
return
|
|
169
|
+
return applyBrand(value,setHas,brandProbeArguments);
|
|
131
170
|
};
|
|
132
171
|
|
|
133
172
|
const weakSetCheck=function(value){
|
|
134
|
-
return
|
|
173
|
+
return applyBrand(value,weakSetHas,brandProbeArguments);
|
|
135
174
|
};
|
|
136
175
|
|
|
137
176
|
const regExpCheck=function(value){
|
|
138
|
-
return
|
|
177
|
+
return applyBrand(value,regExpSourceGetter);
|
|
139
178
|
};
|
|
140
179
|
|
|
141
180
|
const boxedBooleanCheck=function(value){
|
|
142
|
-
return typeof value === 'object' && value !== null &&
|
|
181
|
+
return typeof value === 'object' && value !== null && applyBrand(value,booleanValueOf);
|
|
143
182
|
};
|
|
144
183
|
|
|
145
184
|
const boxedNumberCheck=function(value){
|
|
146
|
-
return typeof value === 'object' && value !== null &&
|
|
185
|
+
return typeof value === 'object' && value !== null && applyBrand(value,numberValueOf);
|
|
147
186
|
};
|
|
148
187
|
|
|
149
188
|
const boxedBigIntCheck=function(value){
|
|
150
|
-
|
|
151
|
-
return typeof value === 'object' && value !== null && methodBrand(value,prototype,'valueOf');
|
|
189
|
+
return typeof value === 'object' && value !== null && applyBrand(value,bigIntValueOf);
|
|
152
190
|
};
|
|
153
191
|
|
|
154
192
|
const boxedStringCheck=function(value){
|
|
155
|
-
return typeof value === 'object' && value !== null &&
|
|
193
|
+
return typeof value === 'object' && value !== null && applyBrand(value,stringValueOf);
|
|
156
194
|
};
|
|
157
195
|
|
|
158
196
|
const boxedSymbolCheck=function(value){
|
|
159
|
-
|
|
160
|
-
return typeof value === 'object' && value !== null && methodBrand(value,prototype,'valueOf');
|
|
197
|
+
return typeof value === 'object' && value !== null && applyBrand(value,symbolValueOf);
|
|
161
198
|
};
|
|
162
199
|
|
|
163
200
|
const plainObjectCheck=function(value){
|
|
@@ -180,7 +217,7 @@ const plainObjectCheck=function(value){
|
|
|
180
217
|
}
|
|
181
218
|
|
|
182
219
|
const constructor=prototype.constructor;
|
|
183
|
-
return typeof constructor === 'function' &&
|
|
220
|
+
return typeof constructor === 'function' && functionToString.call(constructor) === objectConstructorSource;
|
|
184
221
|
};
|
|
185
222
|
|
|
186
223
|
const protocolCheck=function(value,symbol,method){
|
|
@@ -215,6 +252,82 @@ const blockedUnionMethods=new Set([
|
|
|
215
252
|
'union'
|
|
216
253
|
]);
|
|
217
254
|
|
|
255
|
+
const unionNamesCache=new Map;
|
|
256
|
+
const unionNamesCacheLimit=128;
|
|
257
|
+
|
|
258
|
+
const normalizeUnionNames=function(types){
|
|
259
|
+
if(typeof types === 'string' && unionNamesCache.has(types)){
|
|
260
|
+
return unionNamesCache.get(types);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const source=Array.isArray(types) ? types : typeof types === 'string' ? types.split('|') : [];
|
|
264
|
+
const names=[];
|
|
265
|
+
const length=source.length;
|
|
266
|
+
for(let index=0;index<length;index++){
|
|
267
|
+
const type=source[index];
|
|
268
|
+
if(typeof type !== 'string'){
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
const name=type.trim();
|
|
272
|
+
if(name){
|
|
273
|
+
names.push(name);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if(typeof types === 'string'){
|
|
278
|
+
if(unionNamesCache.size >= unionNamesCacheLimit){
|
|
279
|
+
unionNamesCache.delete(unionNamesCache.keys().next().value);
|
|
280
|
+
}
|
|
281
|
+
Object.freeze(names);
|
|
282
|
+
unionNamesCache.set(types,names);
|
|
283
|
+
}
|
|
284
|
+
return names;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
let cachedSegmenterConstructor;
|
|
288
|
+
let cachedSegmentMethod;
|
|
289
|
+
let cachedSegmentsPrototype;
|
|
290
|
+
let cachedSegmentsContaining;
|
|
291
|
+
const segmentsContainingFor=function(constructor){
|
|
292
|
+
if(typeof constructor !== 'function'){
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
let segment;
|
|
297
|
+
try{
|
|
298
|
+
segment=constructor.prototype && constructor.prototype.segment;
|
|
299
|
+
}catch(err){
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
302
|
+
if(typeof segment !== 'function'){
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
if(constructor === cachedSegmenterConstructor && segment === cachedSegmentMethod && typeof cachedSegmentsContaining === 'function'){
|
|
306
|
+
try{
|
|
307
|
+
if(cachedSegmentsPrototype && cachedSegmentsPrototype.containing === cachedSegmentsContaining){
|
|
308
|
+
return cachedSegmentsContaining;
|
|
309
|
+
}
|
|
310
|
+
}catch(err){
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
try{
|
|
316
|
+
const prototype=objectGetPrototypeOf(reflectApply(segment,new constructor,emptyStringArguments));
|
|
317
|
+
const containing=prototype && prototype.containing;
|
|
318
|
+
if(typeof containing === 'function'){
|
|
319
|
+
cachedSegmenterConstructor=constructor;
|
|
320
|
+
cachedSegmentMethod=segment;
|
|
321
|
+
cachedSegmentsPrototype=prototype;
|
|
322
|
+
cachedSegmentsContaining=containing;
|
|
323
|
+
return containing;
|
|
324
|
+
}
|
|
325
|
+
}catch(err){
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
return false;
|
|
329
|
+
};
|
|
330
|
+
|
|
218
331
|
const validatorFor=function(target,name){
|
|
219
332
|
if(blockedUnionMethods.has(name)){
|
|
220
333
|
return false;
|
|
@@ -239,11 +352,12 @@ class Is{
|
|
|
239
352
|
|
|
240
353
|
//core
|
|
241
354
|
throw(valueType,expectedType){
|
|
242
|
-
const err=new TypeError;
|
|
243
|
-
err.message=`expected type of ${valueType} to be ${expectedType}`;
|
|
244
355
|
if(!this.strict){
|
|
245
356
|
return false;
|
|
246
357
|
}
|
|
358
|
+
|
|
359
|
+
const err=new TypeError;
|
|
360
|
+
err.message=`expected type of ${valueType} to be ${expectedType}`;
|
|
247
361
|
throw err;
|
|
248
362
|
}
|
|
249
363
|
|
|
@@ -268,8 +382,13 @@ class Is{
|
|
|
268
382
|
return this.check(value,stringTagCheck(value,type),`[object ${type}]`);
|
|
269
383
|
}
|
|
270
384
|
|
|
271
|
-
compare(value,targetValue,typeName
|
|
272
|
-
|
|
385
|
+
compare(value,targetValue,typeName){
|
|
386
|
+
if(Object.is(value,targetValue)){
|
|
387
|
+
return this.check(value,true,typeName);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const expectedType=typeName === undefined ? String(targetValue) : typeName;
|
|
391
|
+
return this.check(value,false,expectedType);
|
|
273
392
|
}
|
|
274
393
|
|
|
275
394
|
globalInstanceCheck(value,type){
|
|
@@ -304,16 +423,18 @@ class Is{
|
|
|
304
423
|
}
|
|
305
424
|
|
|
306
425
|
union(value,typesString){
|
|
307
|
-
const
|
|
308
|
-
const names=types.map(type=>typeof type === 'string' ? type.trim() : '').filter(Boolean);
|
|
426
|
+
const names=normalizeUnionNames(typesString);
|
|
309
427
|
if(!names.length){
|
|
310
428
|
return this.throw(typeof typesString,'a pipe-delimited string or array of strong-type methods');
|
|
311
429
|
}
|
|
312
430
|
|
|
313
|
-
const validators=names.
|
|
314
|
-
|
|
315
|
-
const
|
|
316
|
-
|
|
431
|
+
const validators=new Array(names.length);
|
|
432
|
+
for(let index=0;index<names.length;index++){
|
|
433
|
+
const validator=validatorFor(this,names[index]);
|
|
434
|
+
if(!validator){
|
|
435
|
+
return this.throw(names[index],'a method available on strong-type');
|
|
436
|
+
}
|
|
437
|
+
validators[index]=validator;
|
|
317
438
|
}
|
|
318
439
|
|
|
319
440
|
const weakIs=Object.create(this);
|
|
@@ -328,7 +449,11 @@ class Is{
|
|
|
328
449
|
}
|
|
329
450
|
}
|
|
330
451
|
|
|
331
|
-
|
|
452
|
+
const fail=this.throw;
|
|
453
|
+
if(fail === defaultThrow && !this.strict){
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
return reflectApply(fail,this,[typeof value,names.join('|')]);
|
|
332
457
|
}
|
|
333
458
|
|
|
334
459
|
//values and primitives
|
|
@@ -450,11 +575,13 @@ class Is{
|
|
|
450
575
|
|
|
451
576
|
//objects and collections
|
|
452
577
|
array(value){
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
578
|
+
let pass=false;
|
|
579
|
+
try{
|
|
580
|
+
pass=Array.isArray(value);
|
|
581
|
+
}catch(err){
|
|
582
|
+
pass=false;
|
|
583
|
+
}
|
|
584
|
+
return this.check(value,pass,'Array');
|
|
458
585
|
}
|
|
459
586
|
|
|
460
587
|
date(value){
|
|
@@ -486,11 +613,14 @@ class Is{
|
|
|
486
613
|
}
|
|
487
614
|
|
|
488
615
|
nullPrototypeObject(value){
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
616
|
+
let pass=false;
|
|
617
|
+
if(value !== null && typeof value === 'object'){
|
|
618
|
+
try{
|
|
619
|
+
pass=Object.getPrototypeOf(value) === null;
|
|
620
|
+
}catch(err){
|
|
621
|
+
pass=false;
|
|
492
622
|
}
|
|
493
|
-
}
|
|
623
|
+
}
|
|
494
624
|
return this.check(value,pass,'null-prototype object');
|
|
495
625
|
}
|
|
496
626
|
|
|
@@ -713,15 +843,12 @@ class Is{
|
|
|
713
843
|
}
|
|
714
844
|
|
|
715
845
|
resizableArrayBuffer(value){
|
|
716
|
-
const
|
|
717
|
-
const pass=arrayBufferCheck(value) && getterBrand(value,prototype,'resizable') && getterValue(value,prototype,'resizable') === true;
|
|
846
|
+
const pass=applyValue(value,arrayBufferResizableGetter) === true;
|
|
718
847
|
return this.check(value,pass,'resizable ArrayBuffer');
|
|
719
848
|
}
|
|
720
849
|
|
|
721
850
|
growableSharedArrayBuffer(value){
|
|
722
|
-
const
|
|
723
|
-
const prototype=constructor && constructor.prototype;
|
|
724
|
-
const pass=sharedArrayBufferCheck(value) && getterBrand(value,prototype,'growable') && getterValue(value,prototype,'growable') === true;
|
|
851
|
+
const pass=applyValue(value,sharedArrayBufferGrowableGetter) === true;
|
|
725
852
|
return this.check(value,pass,'growable SharedArrayBuffer');
|
|
726
853
|
}
|
|
727
854
|
|
|
@@ -733,7 +860,7 @@ class Is{
|
|
|
733
860
|
const prototype=globalThis.ArrayBuffer.prototype;
|
|
734
861
|
const descriptor=Object.getOwnPropertyDescriptor(prototype,'detached');
|
|
735
862
|
if(descriptor && typeof descriptor.get === 'function'){
|
|
736
|
-
return this.check(value,
|
|
863
|
+
return this.check(value,reflectApply(descriptor.get,value,noArguments) === true,'detached ArrayBuffer');
|
|
737
864
|
}
|
|
738
865
|
|
|
739
866
|
let detached=false;
|
|
@@ -748,13 +875,13 @@ class Is{
|
|
|
748
875
|
//Intl
|
|
749
876
|
intlDateTimeFormat(value){
|
|
750
877
|
const constructor=globalThis.Intl && globalThis.Intl.DateTimeFormat;
|
|
751
|
-
const pass=constructor &&
|
|
878
|
+
const pass=constructor && applyBrand(value,intlDateTimeFormatGetter);
|
|
752
879
|
return this.check(value,pass,'Intl.DateTimeFormat');
|
|
753
880
|
}
|
|
754
881
|
|
|
755
882
|
intlCollator(value){
|
|
756
883
|
const constructor=globalThis.Intl && globalThis.Intl.Collator;
|
|
757
|
-
const pass=constructor &&
|
|
884
|
+
const pass=constructor && applyBrand(value,intlCollatorCompareGetter);
|
|
758
885
|
return this.check(value,pass,'Intl.Collator');
|
|
759
886
|
}
|
|
760
887
|
|
|
@@ -778,7 +905,7 @@ class Is{
|
|
|
778
905
|
|
|
779
906
|
intlNumberFormat(value){
|
|
780
907
|
const constructor=globalThis.Intl && globalThis.Intl.NumberFormat;
|
|
781
|
-
const pass=constructor &&
|
|
908
|
+
const pass=constructor && applyBrand(value,intlNumberFormatGetter);
|
|
782
909
|
return this.check(value,pass,'Intl.NumberFormat');
|
|
783
910
|
}
|
|
784
911
|
|
|
@@ -802,11 +929,7 @@ class Is{
|
|
|
802
929
|
|
|
803
930
|
intlSegments(value){
|
|
804
931
|
const constructor=globalThis.Intl && globalThis.Intl.Segmenter;
|
|
805
|
-
|
|
806
|
-
if(constructor){
|
|
807
|
-
const prototype=Object.getPrototypeOf(new constructor().segment(''));
|
|
808
|
-
pass=methodBrand(value,prototype,'containing',[0]);
|
|
809
|
-
}
|
|
932
|
+
const pass=applyBrand(value,segmentsContainingFor(constructor),segmentProbeArguments);
|
|
810
933
|
return this.check(value,pass,'Intl Segments');
|
|
811
934
|
}
|
|
812
935
|
|
|
@@ -819,7 +942,7 @@ class Is{
|
|
|
819
942
|
//garbage collection and resource management
|
|
820
943
|
finalizationRegistry(value){
|
|
821
944
|
const constructor=globalThis.FinalizationRegistry;
|
|
822
|
-
const pass=constructor && methodBrand(value,constructor.prototype,'unregister',
|
|
945
|
+
const pass=constructor && methodBrand(value,constructor.prototype,'unregister',brandProbeArguments);
|
|
823
946
|
return this.check(value,pass,'FinalizationRegistry');
|
|
824
947
|
}
|
|
825
948
|
|
|
@@ -1148,4 +1271,6 @@ class Is{
|
|
|
1148
1271
|
}
|
|
1149
1272
|
}
|
|
1150
1273
|
|
|
1274
|
+
const defaultThrow=Is.prototype.throw;
|
|
1275
|
+
|
|
1151
1276
|
export {Is as default,Is};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "strong-type",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Dependency-free native ESM type enforcement for JavaScript values, objects, classes, browsers, and Node.",
|
|
6
6
|
"main": "index.js",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"files": [
|
|
15
15
|
"index.js",
|
|
16
16
|
"node.js",
|
|
17
|
+
"benchmark/core.js",
|
|
17
18
|
"assets/strong-type-header.png",
|
|
18
19
|
"README.md",
|
|
19
20
|
"licence"
|
|
@@ -26,11 +27,16 @@
|
|
|
26
27
|
"node": ">=12.21.0"
|
|
27
28
|
},
|
|
28
29
|
"scripts": {
|
|
30
|
+
"benchmark": "node benchmark/core.js",
|
|
31
|
+
"benchmark:baseline": "node benchmark/core.js --baseline",
|
|
32
|
+
"benchmark:historical": "node benchmark/core.js --historical",
|
|
29
33
|
"test": "node scripts/test.js",
|
|
30
|
-
"test:
|
|
31
|
-
"test:
|
|
32
|
-
"test:
|
|
33
|
-
"
|
|
34
|
+
"test:unit": "node scripts/test.js unit",
|
|
35
|
+
"test:functional": "node scripts/test.js functional",
|
|
36
|
+
"test:integration": "node scripts/test.js integration",
|
|
37
|
+
"test:regression": "node scripts/test.js regression",
|
|
38
|
+
"test:legacy": "node scripts/test.js legacy",
|
|
39
|
+
"coverage": "vanilla-test coverage node",
|
|
34
40
|
"start": "node scripts/serve.js",
|
|
35
41
|
"nodeExample": "node ./example/node/typecheck.js",
|
|
36
42
|
"check": "npm test"
|
|
@@ -56,5 +62,8 @@
|
|
|
56
62
|
"bugs": {
|
|
57
63
|
"url": "https://github.com/RIAEvangelist/strong-type/issues"
|
|
58
64
|
},
|
|
59
|
-
"homepage": "https://riaevangelist.github.io/strong-type/"
|
|
65
|
+
"homepage": "https://riaevangelist.github.io/strong-type/",
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"vanilla-test": "2.1.0"
|
|
68
|
+
}
|
|
60
69
|
}
|