@holoscript/core 6.0.3 → 7.0.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/README.md +40 -40
- package/dist/codebase/index.d.ts +25 -0
- package/dist/compiler/index.d.ts +82 -0
- package/dist/constants.d.ts +4 -0
- package/dist/coordinators/index.d.ts +189 -0
- package/dist/entries/interop.d.ts +9 -0
- package/dist/entries/scripting.d.ts +7 -0
- package/dist/index.d.ts +520 -19
- package/dist/paper-0c-spike/index.d.ts +29 -0
- package/dist/reconstruction/index.d.ts +78 -0
- package/dist/self-improvement/index.d.ts +0 -48
- package/dist/storage/index.d.ts +24 -0
- package/dist/tools/index.d.ts +33 -0
- package/dist/traitDocs/traitDocs.d.ts +69 -0
- package/dist/traits/index.d.ts +61 -0
- package/package.json +102 -19
- package/dist/GLTFPipeline-3KLWWUQO.cjs +0 -34
- package/dist/GLTFPipeline-LYII2ZVQ.js +0 -13
- package/dist/HoloScriptPlusParser-BZR5DELQ.js +0 -692
- package/dist/HoloScriptPlusParser-SBMYDNXO.cjs +0 -697
- package/dist/USDZExporter-MHEHXZB4.cjs +0 -709
- package/dist/USDZExporter-YA55ZS35.js +0 -707
- package/dist/chunk-26TLYBFD.js +0 -309
- package/dist/chunk-27LWW5FU.cjs +0 -410
- package/dist/chunk-2UX5LRAP.cjs +0 -833
- package/dist/chunk-32TWR3HE.js +0 -70
- package/dist/chunk-3FXV5S25.cjs +0 -633
- package/dist/chunk-3FYZOR7S.cjs +0 -69
- package/dist/chunk-3KEU5QYY.cjs +0 -175
- package/dist/chunk-4FCZDTD5.js +0 -610
- package/dist/chunk-4KJ2R7VP.cjs +0 -507
- package/dist/chunk-4SMUJFHL.js +0 -1213
- package/dist/chunk-54FHG2MX.js +0 -655
- package/dist/chunk-56IF4NTA.js +0 -56
- package/dist/chunk-5GLCTO44.js +0 -161
- package/dist/chunk-5TOFIR6L.js +0 -407
- package/dist/chunk-65RFOWZI.js +0 -765
- package/dist/chunk-6OQBLABR.js +0 -5240
- package/dist/chunk-6WNCRE6F.js +0 -126
- package/dist/chunk-74YCHHTE.js +0 -1872
- package/dist/chunk-7H5UNJZD.cjs +0 -1973
- package/dist/chunk-7KPI4EKH.cjs +0 -701
- package/dist/chunk-7LCYLPW2.cjs +0 -663
- package/dist/chunk-7N3JIJMT.js +0 -1395
- package/dist/chunk-7X2IEJIE.cjs +0 -2526
- package/dist/chunk-A6GO3DPZ.cjs +0 -1002
- package/dist/chunk-AC4BSHFV.js +0 -765
- package/dist/chunk-AIUXRS74.cjs +0 -3681
- package/dist/chunk-ARNKA274.cjs +0 -130
- package/dist/chunk-AW7WAELW.js +0 -975
- package/dist/chunk-BKIGPPVM.js +0 -629
- package/dist/chunk-BO2OKHIY.js +0 -6055
- package/dist/chunk-BU5ZAFMC.js +0 -115
- package/dist/chunk-BY3B7ZYV.cjs +0 -457
- package/dist/chunk-C2QHVHZF.js +0 -4066
- package/dist/chunk-C7BNX4XJ.js +0 -1043
- package/dist/chunk-CLYEIWA5.cjs +0 -408
- package/dist/chunk-CMYAWUX3.js +0 -4455
- package/dist/chunk-CN4NOESF.cjs +0 -416
- package/dist/chunk-CNVM7J3M.js +0 -883
- package/dist/chunk-CO2VM2DK.js +0 -1965
- package/dist/chunk-CQDOF3G7.cjs +0 -1404
- package/dist/chunk-DH5G2JUA.cjs +0 -614
- package/dist/chunk-DIEDKX5B.cjs +0 -660
- package/dist/chunk-DN7UFU63.cjs +0 -172
- package/dist/chunk-DXVCEFZB.js +0 -2027
- package/dist/chunk-EGIZHYJP.cjs +0 -85
- package/dist/chunk-EJA7G2C4.cjs +0 -428
- package/dist/chunk-ELLQPFAF.js +0 -830
- package/dist/chunk-EMO7HAKJ.cjs +0 -1875
- package/dist/chunk-ENV7K6XA.js +0 -282
- package/dist/chunk-EPWRXL6S.js +0 -2522
- package/dist/chunk-EUFLX2PI.js +0 -56956
- package/dist/chunk-F5LVGHNT.js +0 -449
- package/dist/chunk-FEFHPUEM.cjs +0 -6122
- package/dist/chunk-FF3Q7ADR.js +0 -380
- package/dist/chunk-GC3YU46J.js +0 -762
- package/dist/chunk-H6WMMLQK.cjs +0 -4492
- package/dist/chunk-H7XMORZI.js +0 -2731
- package/dist/chunk-HAN4V3PF.cjs +0 -2037
- package/dist/chunk-HBZYCASG.js +0 -4208
- package/dist/chunk-HF4OFY25.cjs +0 -4097
- package/dist/chunk-HHS6FMOU.cjs +0 -3813
- package/dist/chunk-HJJLD366.js +0 -1169
- package/dist/chunk-HKCVM6OK.cjs +0 -2237
- package/dist/chunk-HUFNKFA6.js +0 -698
- package/dist/chunk-I3XGTIHM.cjs +0 -1505
- package/dist/chunk-I6XZ5DZF.cjs +0 -488
- package/dist/chunk-IHOUYQIA.js +0 -406
- package/dist/chunk-ILRBGFVD.cjs +0 -72
- package/dist/chunk-KDB6BUMB.js +0 -3666
- package/dist/chunk-KUJRR4FJ.js +0 -657
- package/dist/chunk-KYM4XRFG.js +0 -421
- package/dist/chunk-L3Z2HIWJ.cjs +0 -793
- package/dist/chunk-LBPEZQAF.js +0 -2232
- package/dist/chunk-LER4WXW5.cjs +0 -286
- package/dist/chunk-LK5IAVH6.cjs +0 -1173
- package/dist/chunk-M6FU6S22.js +0 -2911
- package/dist/chunk-MWEFR6YQ.js +0 -1857
- package/dist/chunk-N5FTS757.cjs +0 -415
- package/dist/chunk-NCUHGRTZ.js +0 -752
- package/dist/chunk-NKRKT6V2.js +0 -69
- package/dist/chunk-NLPSZT4C.js +0 -630
- package/dist/chunk-NRUB55IT.cjs +0 -771
- package/dist/chunk-NTMZSDXM.cjs +0 -633
- package/dist/chunk-ODGMVILH.js +0 -9662
- package/dist/chunk-PBA6NXCT.cjs +0 -1216
- package/dist/chunk-PHENW4MQ.js +0 -65
- package/dist/chunk-PJMOXFPR.cjs +0 -1861
- package/dist/chunk-PLMYCCA4.js +0 -504
- package/dist/chunk-PPULB4GG.cjs +0 -9728
- package/dist/chunk-PQLGZKMC.cjs +0 -755
- package/dist/chunk-Q56TT7IL.js +0 -483
- package/dist/chunk-QHVVVN47.cjs +0 -2033
- package/dist/chunk-QWKUKVRE.js +0 -2026
- package/dist/chunk-RE3OKSYF.cjs +0 -424
- package/dist/chunk-RT7LJRSF.cjs +0 -57378
- package/dist/chunk-SPDELRRV.cjs +0 -319
- package/dist/chunk-SUCBB66F.js +0 -229
- package/dist/chunk-TSWTWZ42.cjs +0 -4214
- package/dist/chunk-UITWA6DV.cjs +0 -2829
- package/dist/chunk-UQW6SLM5.js +0 -172
- package/dist/chunk-V2ILLPHK.cjs +0 -237
- package/dist/chunk-V42NTCFH.js +0 -3645
- package/dist/chunk-VJ3L7CHT.cjs +0 -169
- package/dist/chunk-VJVCD5T5.cjs +0 -769
- package/dist/chunk-VK5AXKO3.js +0 -746
- package/dist/chunk-VSXOIUCF.cjs +0 -473
- package/dist/chunk-VZNKJZTT.cjs +0 -749
- package/dist/chunk-W76ETJTI.js +0 -678
- package/dist/chunk-WFJIDI2N.cjs +0 -424
- package/dist/chunk-WN3YF33G.cjs +0 -118
- package/dist/chunk-WUXIRGZP.cjs +0 -2915
- package/dist/chunk-WYH4GVZ5.js +0 -1488
- package/dist/chunk-X4YVN7H3.cjs +0 -888
- package/dist/chunk-X67XRI2T.js +0 -410
- package/dist/chunk-XDXZM3ZP.cjs +0 -1046
- package/dist/chunk-XH7SE4HH.cjs +0 -72
- package/dist/chunk-XNMEH2BI.js +0 -126
- package/dist/chunk-XSF76QRU.js +0 -468
- package/dist/chunk-XSUZMPVQ.cjs +0 -682
- package/dist/chunk-XUILI4KB.cjs +0 -430
- package/dist/chunk-Y5MUAYTO.js +0 -167
- package/dist/chunk-Y7VK5TH3.cjs +0 -129
- package/dist/chunk-YCMQQQ5U.cjs +0 -5244
- package/dist/chunk-YYXH45E2.js +0 -426
- package/dist/chunk-ZGTGVSTZ.js +0 -422
- package/dist/chunk-ZL6VJ6SN.js +0 -421
- package/dist/cli/holoscript-runner.cjs +0 -2258
- package/dist/cli/holoscript-runner.js +0 -2233
- package/dist/codebase/index.cjs +0 -336
- package/dist/codebase/index.js +0 -331
- package/dist/compiler/agent-inference.cjs +0 -29
- package/dist/compiler/agent-inference.js +0 -6
- package/dist/compiler/android-xr.cjs +0 -20
- package/dist/compiler/android-xr.js +0 -10
- package/dist/compiler/android.cjs +0 -21
- package/dist/compiler/android.js +0 -11
- package/dist/compiler/ar.cjs +0 -21
- package/dist/compiler/ar.js +0 -9
- package/dist/compiler/babylon.cjs +0 -18
- package/dist/compiler/babylon.js +0 -12
- package/dist/compiler/coco.cjs +0 -27
- package/dist/compiler/coco.js +0 -4
- package/dist/compiler/domain-block-utils.cjs +0 -595
- package/dist/compiler/domain-block-utils.js +0 -9
- package/dist/compiler/dtdl.cjs +0 -25
- package/dist/compiler/dtdl.js +0 -9
- package/dist/compiler/gltf-pipeline.cjs +0 -39
- package/dist/compiler/gltf-pipeline.js +0 -4
- package/dist/compiler/godot.cjs +0 -16
- package/dist/compiler/godot.js +0 -10
- package/dist/compiler/incremental.cjs +0 -30
- package/dist/compiler/incremental.js +0 -5
- package/dist/compiler/index.cjs +0 -1522
- package/dist/compiler/index.js +0 -1321
- package/dist/compiler/ios.cjs +0 -21
- package/dist/compiler/ios.js +0 -11
- package/dist/compiler/multi-layer.cjs +0 -27
- package/dist/compiler/multi-layer.js +0 -12
- package/dist/compiler/nodetoy.cjs +0 -23
- package/dist/compiler/nodetoy.js +0 -4
- package/dist/compiler/openxr.cjs +0 -16
- package/dist/compiler/openxr.js +0 -10
- package/dist/compiler/playcanvas.cjs +0 -17
- package/dist/compiler/playcanvas.js +0 -11
- package/dist/compiler/r3f.cjs +0 -35
- package/dist/compiler/r3f.js +0 -13
- package/dist/compiler/remotion.cjs +0 -23
- package/dist/compiler/remotion.js +0 -4
- package/dist/compiler/reproducibility.cjs +0 -39
- package/dist/compiler/reproducibility.js +0 -4
- package/dist/compiler/sdf.cjs +0 -22
- package/dist/compiler/sdf.js +0 -10
- package/dist/compiler/semantic-scene.cjs +0 -31
- package/dist/compiler/semantic-scene.js +0 -4
- package/dist/compiler/state.cjs +0 -18
- package/dist/compiler/state.js +0 -8
- package/dist/compiler/trait-composition.cjs +0 -27
- package/dist/compiler/trait-composition.js +0 -6
- package/dist/compiler/unity.cjs +0 -16
- package/dist/compiler/unity.js +0 -10
- package/dist/compiler/unreal.cjs +0 -20
- package/dist/compiler/unreal.js +0 -10
- package/dist/compiler/urdf.cjs +0 -46
- package/dist/compiler/urdf.js +0 -10
- package/dist/compiler/usd-physics.cjs +0 -24
- package/dist/compiler/usd-physics.js +0 -7
- package/dist/compiler/visionos.cjs +0 -16
- package/dist/compiler/visionos.js +0 -10
- package/dist/compiler/vrchat.cjs +0 -20
- package/dist/compiler/vrchat.js +0 -10
- package/dist/compiler/vrr.cjs +0 -22
- package/dist/compiler/vrr.js +0 -10
- package/dist/compiler/wasm.cjs +0 -34
- package/dist/compiler/wasm.js +0 -10
- package/dist/compiler/webgpu.cjs +0 -16
- package/dist/compiler/webgpu.js +0 -10
- package/dist/debugger.cjs +0 -21
- package/dist/debugger.js +0 -8
- package/dist/entries/interop.cjs +0 -62
- package/dist/entries/interop.js +0 -5
- package/dist/entries/scripting.cjs +0 -67
- package/dist/entries/scripting.js +0 -10
- package/dist/index.cjs +0 -61703
- package/dist/index.js +0 -58652
- package/dist/math/vec3.cjs +0 -57
- package/dist/math/vec3.js +0 -4
- package/dist/parser.cjs +0 -26
- package/dist/parser.js +0 -9
- package/dist/playwright-7DTEQCBD.cjs +0 -98673
- package/dist/playwright-BIZXMLD2.js +0 -98660
- package/dist/post-quantum-JTTAAGO3.cjs +0 -6
- package/dist/post-quantum-RVPVDEPI.js +0 -4
- package/dist/runtime.cjs +0 -16
- package/dist/runtime.js +0 -7
- package/dist/storage/index.cjs +0 -37
- package/dist/storage/index.js +0 -4
- package/dist/traits/index.cjs +0 -14331
- package/dist/traits/index.js +0 -12126
- package/dist/type-checker.cjs +0 -18
- package/dist/type-checker.js +0 -5
- package/dist/wot/index.cjs +0 -29
- package/dist/wot/index.js +0 -4
package/dist/chunk-CN4NOESF.cjs
DELETED
|
@@ -1,416 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// src/wot/ThingDescriptionGenerator.ts
|
|
4
|
-
var ThingDescriptionGenerator = class {
|
|
5
|
-
constructor(options = {}) {
|
|
6
|
-
this.options = {
|
|
7
|
-
baseUrl: options.baseUrl || "",
|
|
8
|
-
contentType: options.contentType || "application/json",
|
|
9
|
-
defaultObservable: options.defaultObservable ?? true,
|
|
10
|
-
securityDefinitions: options.securityDefinitions
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Generate a Thing Description from a HoloScript node with @wot_thing trait
|
|
15
|
-
*/
|
|
16
|
-
generate(node) {
|
|
17
|
-
const wotTrait = this.findWoTTrait(node);
|
|
18
|
-
if (!wotTrait) {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
const config = this.parseWoTConfig(wotTrait);
|
|
22
|
-
const stateProperties = this.extractStateProperties(node);
|
|
23
|
-
const actions = this.extractActions(node);
|
|
24
|
-
const events = this.extractEvents(node);
|
|
25
|
-
const td = {
|
|
26
|
-
"@context": "https://www.w3.org/2022/wot/td/v1.1",
|
|
27
|
-
id: config.id || `urn:holoscript:${node.name || "thing"}`,
|
|
28
|
-
title: config.title || node.name || "Unnamed Thing",
|
|
29
|
-
security: "default",
|
|
30
|
-
securityDefinitions: this.buildSecurityDefinitions(config.security)
|
|
31
|
-
};
|
|
32
|
-
if (config.description) {
|
|
33
|
-
td.description = config.description;
|
|
34
|
-
}
|
|
35
|
-
if (config.base || this.options.baseUrl) {
|
|
36
|
-
td.base = config.base || this.options.baseUrl;
|
|
37
|
-
}
|
|
38
|
-
if (config.version) {
|
|
39
|
-
td.version = { instance: config.version };
|
|
40
|
-
}
|
|
41
|
-
if (Object.keys(stateProperties).length > 0) {
|
|
42
|
-
td.properties = stateProperties;
|
|
43
|
-
}
|
|
44
|
-
if (Object.keys(actions).length > 0) {
|
|
45
|
-
td.actions = actions;
|
|
46
|
-
}
|
|
47
|
-
if (Object.keys(events).length > 0) {
|
|
48
|
-
td.events = events;
|
|
49
|
-
}
|
|
50
|
-
return td;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Generate Thing Descriptions for all nodes with @wot_thing trait
|
|
54
|
-
*/
|
|
55
|
-
generateAll(nodes) {
|
|
56
|
-
const results = [];
|
|
57
|
-
const processNode = (node) => {
|
|
58
|
-
const td = this.generate(node);
|
|
59
|
-
if (td) {
|
|
60
|
-
results.push(td);
|
|
61
|
-
}
|
|
62
|
-
if (node.children) {
|
|
63
|
-
for (const child of node.children) {
|
|
64
|
-
processNode(child);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
for (const node of nodes) {
|
|
69
|
-
processNode(node);
|
|
70
|
-
}
|
|
71
|
-
return results;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Find @wot_thing directive in node
|
|
75
|
-
*/
|
|
76
|
-
findWoTTrait(node) {
|
|
77
|
-
if (!node.directives) {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
return node.directives.find(
|
|
81
|
-
(d) => d.type === "trait" && d.name === "wot_thing" || d.type === "directive" && d.name === "wot_thing"
|
|
82
|
-
) || null;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Parse @wot_thing config from directive
|
|
86
|
-
*/
|
|
87
|
-
parseWoTConfig(directive) {
|
|
88
|
-
const dir = directive;
|
|
89
|
-
const args = dir.args || dir.config || {};
|
|
90
|
-
return {
|
|
91
|
-
title: String(args.title || ""),
|
|
92
|
-
description: args.description ? String(args.description) : void 0,
|
|
93
|
-
security: args.security || "nosec",
|
|
94
|
-
base: args.base ? String(args.base) : void 0,
|
|
95
|
-
id: args.id ? String(args.id) : void 0,
|
|
96
|
-
version: args.version ? String(args.version) : void 0
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Extract TD properties from @state block
|
|
101
|
-
*/
|
|
102
|
-
extractStateProperties(node) {
|
|
103
|
-
const properties = {};
|
|
104
|
-
if (!node.directives) {
|
|
105
|
-
return properties;
|
|
106
|
-
}
|
|
107
|
-
const stateDirective = node.directives.find(
|
|
108
|
-
(d) => d.type === "state" || d.type === "directive" && d.name === "state"
|
|
109
|
-
);
|
|
110
|
-
if (!stateDirective || !stateDirective.body) {
|
|
111
|
-
if (node.properties?.state && typeof node.properties.state === "object") {
|
|
112
|
-
return this.mapStateToProperties(node.properties.state);
|
|
113
|
-
}
|
|
114
|
-
return properties;
|
|
115
|
-
}
|
|
116
|
-
const rawBody = stateDirective.body;
|
|
117
|
-
const stateBody = typeof rawBody === "object" && rawBody !== null ? rawBody : {};
|
|
118
|
-
return this.mapStateToProperties(stateBody);
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Map state object to TD properties
|
|
122
|
-
*/
|
|
123
|
-
mapStateToProperties(state) {
|
|
124
|
-
const properties = {};
|
|
125
|
-
for (const [key, value] of Object.entries(state)) {
|
|
126
|
-
const property = {
|
|
127
|
-
type: this.inferType(value),
|
|
128
|
-
observable: this.options.defaultObservable,
|
|
129
|
-
forms: [
|
|
130
|
-
{
|
|
131
|
-
href: `${this.options.baseUrl}/properties/${key}`,
|
|
132
|
-
contentType: this.options.contentType,
|
|
133
|
-
op: ["readproperty", "writeproperty"]
|
|
134
|
-
}
|
|
135
|
-
]
|
|
136
|
-
};
|
|
137
|
-
if (value !== void 0 && value !== null) {
|
|
138
|
-
property.default = value;
|
|
139
|
-
}
|
|
140
|
-
if (typeof value === "number") {
|
|
141
|
-
if (Number.isInteger(value)) {
|
|
142
|
-
property.type = "integer";
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
if (Array.isArray(value)) {
|
|
146
|
-
property.type = "array";
|
|
147
|
-
if (value.length > 0) {
|
|
148
|
-
property.items = { type: this.inferType(value[0]) };
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
152
|
-
property.type = "object";
|
|
153
|
-
property.properties = {};
|
|
154
|
-
for (const [subKey, subValue] of Object.entries(value)) {
|
|
155
|
-
property.properties[subKey] = { type: this.inferType(subValue) };
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
properties[key] = property;
|
|
159
|
-
}
|
|
160
|
-
return properties;
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Extract TD actions from @on_* handlers
|
|
164
|
-
*/
|
|
165
|
-
extractActions(node) {
|
|
166
|
-
const actions = {};
|
|
167
|
-
if (!node.directives) {
|
|
168
|
-
return actions;
|
|
169
|
-
}
|
|
170
|
-
const actionPatterns = [
|
|
171
|
-
/^on_click$/,
|
|
172
|
-
/^on_grab$/,
|
|
173
|
-
/^on_release$/,
|
|
174
|
-
/^on_hover$/,
|
|
175
|
-
/^on_action$/,
|
|
176
|
-
/^on_command$/,
|
|
177
|
-
/^on_invoke$/,
|
|
178
|
-
/^on_call$/
|
|
179
|
-
];
|
|
180
|
-
for (const directive of node.directives) {
|
|
181
|
-
const d = directive;
|
|
182
|
-
if (directive.type !== "lifecycle" && d.hook === void 0) {
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
const hookName = d.hook || d.name;
|
|
186
|
-
if (!hookName) continue;
|
|
187
|
-
const isAction = actionPatterns.some((pattern) => pattern.test(hookName));
|
|
188
|
-
if (!isAction) continue;
|
|
189
|
-
const actionName = hookName.replace(/^on_/, "");
|
|
190
|
-
actions[actionName] = {
|
|
191
|
-
title: this.toTitleCase(actionName),
|
|
192
|
-
description: `Invoke ${actionName} action`,
|
|
193
|
-
safe: false,
|
|
194
|
-
idempotent: false,
|
|
195
|
-
forms: [
|
|
196
|
-
{
|
|
197
|
-
href: `${this.options.baseUrl}/actions/${actionName}`,
|
|
198
|
-
contentType: this.options.contentType,
|
|
199
|
-
op: "invokeaction"
|
|
200
|
-
}
|
|
201
|
-
]
|
|
202
|
-
};
|
|
203
|
-
if (d.args && typeof d.args === "object") {
|
|
204
|
-
actions[actionName].input = {
|
|
205
|
-
type: "object",
|
|
206
|
-
properties: this.extractInputSchema(d.args)
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
return actions;
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Extract TD events from emit() calls
|
|
214
|
-
*/
|
|
215
|
-
extractEvents(node) {
|
|
216
|
-
const events = {};
|
|
217
|
-
if (!node.directives) {
|
|
218
|
-
return events;
|
|
219
|
-
}
|
|
220
|
-
const observableDirectives = node.directives.filter(
|
|
221
|
-
(d) => d.type === "directive" && (d.name === "observable" || d.name === "event" || d.name === "emit")
|
|
222
|
-
);
|
|
223
|
-
for (const directive of observableDirectives) {
|
|
224
|
-
const dirExt = directive;
|
|
225
|
-
const args = dirExt.args || dirExt.config || {};
|
|
226
|
-
const eventName = args.name || args.event || "change";
|
|
227
|
-
events[String(eventName)] = {
|
|
228
|
-
title: this.toTitleCase(String(eventName)),
|
|
229
|
-
description: `${eventName} event`,
|
|
230
|
-
forms: [
|
|
231
|
-
{
|
|
232
|
-
href: `${this.options.baseUrl}/events/${eventName}`,
|
|
233
|
-
contentType: this.options.contentType,
|
|
234
|
-
subprotocol: "sse",
|
|
235
|
-
op: "subscribeevent"
|
|
236
|
-
}
|
|
237
|
-
]
|
|
238
|
-
};
|
|
239
|
-
if (args.data && typeof args.data === "object") {
|
|
240
|
-
events[String(eventName)].data = {
|
|
241
|
-
type: "object",
|
|
242
|
-
properties: this.extractInputSchema(args.data)
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
const emitPattern = /emit\s*\(\s*['"]([^'"]+)['"]/g;
|
|
247
|
-
for (const directive of node.directives) {
|
|
248
|
-
const dirBody = directive.body;
|
|
249
|
-
if (dirBody && typeof dirBody === "string") {
|
|
250
|
-
let match;
|
|
251
|
-
while ((match = emitPattern.exec(dirBody)) !== null) {
|
|
252
|
-
const eventName = match[1];
|
|
253
|
-
if (!events[eventName]) {
|
|
254
|
-
events[eventName] = {
|
|
255
|
-
title: this.toTitleCase(eventName),
|
|
256
|
-
description: `${eventName} event`,
|
|
257
|
-
forms: [
|
|
258
|
-
{
|
|
259
|
-
href: `${this.options.baseUrl}/events/${eventName}`,
|
|
260
|
-
contentType: this.options.contentType,
|
|
261
|
-
subprotocol: "sse",
|
|
262
|
-
op: "subscribeevent"
|
|
263
|
-
}
|
|
264
|
-
]
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
return events;
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Build security definitions based on config
|
|
274
|
-
*/
|
|
275
|
-
buildSecurityDefinitions(security) {
|
|
276
|
-
if (this.options.securityDefinitions) {
|
|
277
|
-
return this.options.securityDefinitions;
|
|
278
|
-
}
|
|
279
|
-
const definitions = {};
|
|
280
|
-
switch (security) {
|
|
281
|
-
case "basic":
|
|
282
|
-
definitions.default = {
|
|
283
|
-
scheme: "basic",
|
|
284
|
-
in: "header"
|
|
285
|
-
};
|
|
286
|
-
break;
|
|
287
|
-
case "bearer":
|
|
288
|
-
definitions.default = {
|
|
289
|
-
scheme: "bearer",
|
|
290
|
-
in: "header",
|
|
291
|
-
format: "jwt"
|
|
292
|
-
};
|
|
293
|
-
break;
|
|
294
|
-
case "oauth2":
|
|
295
|
-
definitions.default = {
|
|
296
|
-
scheme: "oauth2",
|
|
297
|
-
flow: "code"
|
|
298
|
-
};
|
|
299
|
-
break;
|
|
300
|
-
case "apikey":
|
|
301
|
-
definitions.default = {
|
|
302
|
-
scheme: "apikey",
|
|
303
|
-
in: "header",
|
|
304
|
-
name: "X-API-Key"
|
|
305
|
-
};
|
|
306
|
-
break;
|
|
307
|
-
case "nosec":
|
|
308
|
-
default:
|
|
309
|
-
definitions.default = {
|
|
310
|
-
scheme: "nosec"
|
|
311
|
-
};
|
|
312
|
-
break;
|
|
313
|
-
}
|
|
314
|
-
return definitions;
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Extract input schema from args object
|
|
318
|
-
*/
|
|
319
|
-
extractInputSchema(args) {
|
|
320
|
-
const schema = {};
|
|
321
|
-
for (const [key, value] of Object.entries(args)) {
|
|
322
|
-
schema[key] = { type: this.inferType(value) };
|
|
323
|
-
}
|
|
324
|
-
return schema;
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Infer JSON Schema type from value
|
|
328
|
-
*/
|
|
329
|
-
inferType(value) {
|
|
330
|
-
if (value === null) return "null";
|
|
331
|
-
if (typeof value === "boolean") return "boolean";
|
|
332
|
-
if (typeof value === "number") {
|
|
333
|
-
return Number.isInteger(value) ? "integer" : "number";
|
|
334
|
-
}
|
|
335
|
-
if (typeof value === "string") return "string";
|
|
336
|
-
if (Array.isArray(value)) return "array";
|
|
337
|
-
if (typeof value === "object") return "object";
|
|
338
|
-
return "string";
|
|
339
|
-
}
|
|
340
|
-
/**
|
|
341
|
-
* Convert snake_case or camelCase to Title Case
|
|
342
|
-
*/
|
|
343
|
-
toTitleCase(str) {
|
|
344
|
-
return str.replace(/_/g, " ").replace(/([A-Z])/g, " $1").replace(/^\s+/, "").split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
|
345
|
-
}
|
|
346
|
-
};
|
|
347
|
-
function generateThingDescription(node, options) {
|
|
348
|
-
const generator = new ThingDescriptionGenerator(options);
|
|
349
|
-
return generator.generate(node);
|
|
350
|
-
}
|
|
351
|
-
function generateAllThingDescriptions(nodes, options) {
|
|
352
|
-
const generator = new ThingDescriptionGenerator(options);
|
|
353
|
-
return generator.generateAll(nodes);
|
|
354
|
-
}
|
|
355
|
-
function serializeThingDescription(td, pretty = true) {
|
|
356
|
-
return JSON.stringify(td, null, pretty ? 2 : 0);
|
|
357
|
-
}
|
|
358
|
-
function validateThingDescription(td) {
|
|
359
|
-
const errors = [];
|
|
360
|
-
if (!td["@context"]) {
|
|
361
|
-
errors.push("Missing required field '@context'");
|
|
362
|
-
}
|
|
363
|
-
if (!td.title) {
|
|
364
|
-
errors.push("Missing required field 'title'");
|
|
365
|
-
}
|
|
366
|
-
if (!td.security) {
|
|
367
|
-
errors.push("Missing required field 'security'");
|
|
368
|
-
}
|
|
369
|
-
if (!td.securityDefinitions) {
|
|
370
|
-
errors.push("Missing required field 'securityDefinitions'");
|
|
371
|
-
}
|
|
372
|
-
if (td.security && td.securityDefinitions) {
|
|
373
|
-
const securityNames = Array.isArray(td.security) ? td.security : [td.security];
|
|
374
|
-
for (const name of securityNames) {
|
|
375
|
-
if (!td.securityDefinitions[name]) {
|
|
376
|
-
errors.push(`Security definition '${name}' not found in securityDefinitions`);
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
const validateForms = (forms) => {
|
|
381
|
-
if (forms) {
|
|
382
|
-
for (const form of forms) {
|
|
383
|
-
if (!form.href) {
|
|
384
|
-
errors.push("Form missing required href");
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
};
|
|
389
|
-
if (td.properties) {
|
|
390
|
-
for (const prop of Object.values(td.properties)) {
|
|
391
|
-
validateForms(prop.forms);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
if (td.actions) {
|
|
395
|
-
for (const action of Object.values(td.actions)) {
|
|
396
|
-
validateForms(action.forms);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
if (td.events) {
|
|
400
|
-
for (const event of Object.values(td.events)) {
|
|
401
|
-
validateForms(event.forms);
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
return {
|
|
405
|
-
valid: errors.length === 0,
|
|
406
|
-
errors
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
exports.ThingDescriptionGenerator = ThingDescriptionGenerator;
|
|
411
|
-
exports.generateAllThingDescriptions = generateAllThingDescriptions;
|
|
412
|
-
exports.generateThingDescription = generateThingDescription;
|
|
413
|
-
exports.serializeThingDescription = serializeThingDescription;
|
|
414
|
-
exports.validateThingDescription = validateThingDescription;
|
|
415
|
-
//# sourceMappingURL=chunk-CN4NOESF.cjs.map
|
|
416
|
-
//# sourceMappingURL=chunk-CN4NOESF.cjs.map
|