@coasys/ad4m 0.12.0-dev-whisper-lang → 0.12.0-rc1-dev

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.
Files changed (42) hide show
  1. package/lib/index.cjs +1742 -320
  2. package/lib/index.js +1741 -321
  3. package/lib/src/ai/AIClient.d.ts +1 -1
  4. package/lib/src/ai/AIClient.js +4 -5
  5. package/lib/src/ai/AIResolver.d.ts +1 -1
  6. package/lib/src/ai/AIResolver.js +2 -3
  7. package/lib/src/index.d.ts +2 -0
  8. package/lib/src/index.js +2 -0
  9. package/lib/src/model/Ad4mModel.js +17 -5
  10. package/lib/src/model/decorators.js +196 -6
  11. package/lib/src/model/util.d.ts +1 -1
  12. package/lib/src/model/util.js +15 -12
  13. package/lib/src/perspectives/PerspectiveClient.d.ts +11 -1
  14. package/lib/src/perspectives/PerspectiveClient.js +15 -4
  15. package/lib/src/perspectives/PerspectiveProxy.d.ts +124 -8
  16. package/lib/src/perspectives/PerspectiveProxy.js +573 -274
  17. package/lib/src/perspectives/PerspectiveResolver.d.ts +1 -1
  18. package/lib/src/perspectives/PerspectiveResolver.js +5 -4
  19. package/lib/src/schema.gql +2 -2
  20. package/lib/src/shacl/SHACLFlow.d.ts +171 -0
  21. package/lib/src/shacl/SHACLFlow.js +370 -0
  22. package/lib/src/shacl/SHACLFlow.test.d.ts +1 -0
  23. package/lib/src/shacl/SHACLFlow.test.js +205 -0
  24. package/lib/src/shacl/SHACLShape.d.ts +108 -0
  25. package/lib/src/shacl/SHACLShape.js +566 -0
  26. package/lib/src/shacl/SHACLShape.test.d.ts +1 -0
  27. package/lib/src/shacl/SHACLShape.test.js +336 -0
  28. package/lib/src/typeDefs.js +2 -2
  29. package/package.json +1 -2
  30. package/src/ai/AIClient.ts +4 -6
  31. package/src/ai/AIResolver.ts +1 -2
  32. package/src/index.ts +2 -0
  33. package/src/model/Ad4mModel.ts +19 -5
  34. package/src/model/decorators.ts +221 -5
  35. package/src/model/util.ts +15 -12
  36. package/src/perspectives/PerspectiveClient.ts +15 -4
  37. package/src/perspectives/PerspectiveProxy.ts +588 -304
  38. package/src/perspectives/PerspectiveResolver.ts +1 -1
  39. package/src/shacl/SHACLFlow.test.ts +237 -0
  40. package/src/shacl/SHACLFlow.ts +503 -0
  41. package/src/shacl/SHACLShape.test.ts +400 -0
  42. package/src/shacl/SHACLShape.ts +755 -0
@@ -271,7 +271,7 @@ export default class PerspectiveResolver {
271
271
  }
272
272
 
273
273
  @Mutation(returns => Boolean)
274
- perspectiveAddSdna(@Arg('uuid') uuid: string, @Arg('name') name: string, @Arg('sdnaCode') sdnaCode: string, @Arg('sdnaType') sdnaType: string, @PubSub() pubSub: any): Boolean {
274
+ perspectiveAddSdna(@Arg('uuid') uuid: string, @Arg('name') name: string, @Arg('sdnaCode', { nullable: true }) sdnaCode: string, @Arg('sdnaType') sdnaType: string, @Arg('shaclJson', { nullable: true }) shaclJson: string, @PubSub() pubSub: any): Boolean {
275
275
  return true
276
276
  }
277
277
 
@@ -0,0 +1,237 @@
1
+ import { SHACLFlow, FlowState, FlowTransition, AD4MAction } from './SHACLFlow';
2
+
3
+ describe('SHACLFlow', () => {
4
+ describe('basic construction', () => {
5
+ it('creates a flow with name and namespace', () => {
6
+ const flow = new SHACLFlow('TODO', 'todo://');
7
+ expect(flow.name).toBe('TODO');
8
+ expect(flow.namespace).toBe('todo://');
9
+ expect(flow.flowUri).toBe('todo://TODOFlow');
10
+ });
11
+
12
+ it('generates correct state URIs', () => {
13
+ const flow = new SHACLFlow('TODO', 'todo://');
14
+ expect(flow.stateUri('ready')).toBe('todo://TODO.ready');
15
+ expect(flow.stateUri('done')).toBe('todo://TODO.done');
16
+ });
17
+
18
+ it('generates correct transition URIs', () => {
19
+ const flow = new SHACLFlow('TODO', 'todo://');
20
+ expect(flow.transitionUri('ready', 'doing')).toBe('todo://TODO.readyTodoing');
21
+ });
22
+ });
23
+
24
+ describe('state management', () => {
25
+ it('adds and retrieves states', () => {
26
+ const flow = new SHACLFlow('TODO', 'todo://');
27
+
28
+ flow.addState({
29
+ name: 'ready',
30
+ value: 0,
31
+ stateCheck: { predicate: 'todo://state', target: 'todo://ready' }
32
+ });
33
+
34
+ flow.addState({
35
+ name: 'done',
36
+ value: 1,
37
+ stateCheck: { predicate: 'todo://state', target: 'todo://done' }
38
+ });
39
+
40
+ expect(flow.states.length).toBe(2);
41
+ expect(flow.states[0].name).toBe('ready');
42
+ expect(flow.states[1].name).toBe('done');
43
+ });
44
+ });
45
+
46
+ describe('transition management', () => {
47
+ it('adds and retrieves transitions', () => {
48
+ const flow = new SHACLFlow('TODO', 'todo://');
49
+
50
+ flow.addTransition({
51
+ actionName: 'Complete',
52
+ fromState: 'ready',
53
+ toState: 'done',
54
+ actions: [
55
+ { action: 'addLink', source: 'this', predicate: 'todo://state', target: 'todo://done' },
56
+ { action: 'removeLink', source: 'this', predicate: 'todo://state', target: 'todo://ready' }
57
+ ]
58
+ });
59
+
60
+ expect(flow.transitions.length).toBe(1);
61
+ expect(flow.transitions[0].actionName).toBe('Complete');
62
+ expect(flow.transitions[0].actions.length).toBe(2);
63
+ });
64
+ });
65
+
66
+ describe('toLinks()', () => {
67
+ it('serializes flow to links', () => {
68
+ const flow = new SHACLFlow('TODO', 'todo://');
69
+ flow.flowable = 'any';
70
+ flow.startAction = [
71
+ { action: 'addLink', source: 'this', predicate: 'todo://state', target: 'todo://ready' }
72
+ ];
73
+
74
+ flow.addState({
75
+ name: 'ready',
76
+ value: 0,
77
+ stateCheck: { predicate: 'todo://state', target: 'todo://ready' }
78
+ });
79
+
80
+ flow.addTransition({
81
+ actionName: 'Start',
82
+ fromState: 'ready',
83
+ toState: 'doing',
84
+ actions: [{ action: 'addLink', source: 'this', predicate: 'todo://state', target: 'todo://doing' }]
85
+ });
86
+
87
+ const links = flow.toLinks();
88
+
89
+ // Check flow type link
90
+ const typeLink = links.find(l => l.predicate === 'rdf://type' && l.target === 'ad4m://Flow');
91
+ expect(typeLink).toBeDefined();
92
+ expect(typeLink!.source).toBe('todo://TODOFlow');
93
+
94
+ // Check flowable link
95
+ const flowableLink = links.find(l => l.predicate === 'ad4m://flowable');
96
+ expect(flowableLink).toBeDefined();
97
+ expect(flowableLink!.target).toBe('ad4m://any');
98
+
99
+ // Check start action link
100
+ const startActionLink = links.find(l => l.predicate === 'ad4m://startAction');
101
+ expect(startActionLink).toBeDefined();
102
+ expect(startActionLink!.target).toContain('addLink');
103
+
104
+ // Check state link
105
+ const stateLink = links.find(l => l.predicate === 'ad4m://hasState');
106
+ expect(stateLink).toBeDefined();
107
+ expect(stateLink!.target).toBe('todo://TODO.ready');
108
+
109
+ // Check transition link
110
+ const transitionLink = links.find(l => l.predicate === 'ad4m://hasTransition');
111
+ expect(transitionLink).toBeDefined();
112
+ });
113
+ });
114
+
115
+ describe('fromLinks()', () => {
116
+ it('reconstructs flow from links', () => {
117
+ const original = new SHACLFlow('TODO', 'todo://');
118
+ original.flowable = 'any';
119
+ original.startAction = [
120
+ { action: 'addLink', source: 'this', predicate: 'todo://state', target: 'todo://ready' }
121
+ ];
122
+ original.addState({
123
+ name: 'ready',
124
+ value: 0,
125
+ stateCheck: { predicate: 'todo://state', target: 'todo://ready' }
126
+ });
127
+ original.addState({
128
+ name: 'done',
129
+ value: 1,
130
+ stateCheck: { predicate: 'todo://state', target: 'todo://done' }
131
+ });
132
+ original.addTransition({
133
+ actionName: 'Complete',
134
+ fromState: 'ready',
135
+ toState: 'done',
136
+ actions: [{ action: 'addLink', source: 'this', predicate: 'todo://state', target: 'todo://done' }]
137
+ });
138
+
139
+ const links = original.toLinks();
140
+ const reconstructed = SHACLFlow.fromLinks(links, 'todo://TODOFlow');
141
+
142
+ expect(reconstructed.name).toBe('TODO');
143
+ expect(reconstructed.namespace).toBe('todo://');
144
+ expect(reconstructed.flowable).toBe('any');
145
+ expect(reconstructed.startAction.length).toBe(1);
146
+ expect(reconstructed.states.length).toBe(2);
147
+ expect(reconstructed.transitions.length).toBe(1);
148
+ expect(reconstructed.transitions[0].actionName).toBe('Complete');
149
+ });
150
+ });
151
+
152
+ describe('JSON serialization', () => {
153
+ it('converts to and from JSON', () => {
154
+ const original = new SHACLFlow('TODO', 'todo://');
155
+ original.addState({
156
+ name: 'ready',
157
+ value: 0,
158
+ stateCheck: { predicate: 'todo://state', target: 'todo://ready' }
159
+ });
160
+ original.addTransition({
161
+ actionName: 'Start',
162
+ fromState: 'ready',
163
+ toState: 'doing',
164
+ actions: []
165
+ });
166
+
167
+ const json = original.toJSON();
168
+ const reconstructed = SHACLFlow.fromJSON(json);
169
+
170
+ expect(reconstructed.name).toBe('TODO');
171
+ expect(reconstructed.states.length).toBe(1);
172
+ expect(reconstructed.transitions.length).toBe(1);
173
+ });
174
+ });
175
+
176
+ describe('full TODO example', () => {
177
+ it('creates complete TODO flow matching Prolog example', () => {
178
+ const flow = new SHACLFlow('TODO', 'todo://');
179
+ flow.flowable = 'any';
180
+
181
+ // Start action - renders expression as TODO in 'ready' state
182
+ flow.startAction = [
183
+ { action: 'addLink', source: 'this', predicate: 'todo://state', target: 'todo://ready' }
184
+ ];
185
+
186
+ // Three states
187
+ flow.addState({
188
+ name: 'ready',
189
+ value: 0,
190
+ stateCheck: { predicate: 'todo://state', target: 'todo://ready' }
191
+ });
192
+ flow.addState({
193
+ name: 'doing',
194
+ value: 0.5,
195
+ stateCheck: { predicate: 'todo://state', target: 'todo://doing' }
196
+ });
197
+ flow.addState({
198
+ name: 'done',
199
+ value: 1,
200
+ stateCheck: { predicate: 'todo://state', target: 'todo://done' }
201
+ });
202
+
203
+ // Transitions
204
+ flow.addTransition({
205
+ actionName: 'Start',
206
+ fromState: 'ready',
207
+ toState: 'doing',
208
+ actions: [
209
+ { action: 'addLink', source: 'this', predicate: 'todo://state', target: 'todo://doing' },
210
+ { action: 'removeLink', source: 'this', predicate: 'todo://state', target: 'todo://ready' }
211
+ ]
212
+ });
213
+ flow.addTransition({
214
+ actionName: 'Finish',
215
+ fromState: 'doing',
216
+ toState: 'done',
217
+ actions: [
218
+ { action: 'addLink', source: 'this', predicate: 'todo://state', target: 'todo://done' },
219
+ { action: 'removeLink', source: 'this', predicate: 'todo://state', target: 'todo://doing' }
220
+ ]
221
+ });
222
+
223
+ // Verify structure
224
+ expect(flow.states.length).toBe(3);
225
+ expect(flow.transitions.length).toBe(2);
226
+
227
+ // Verify links generation
228
+ const links = flow.toLinks();
229
+ expect(links.length).toBeGreaterThan(15); // Flow + 3 states + 2 transitions = many links
230
+
231
+ // Verify round-trip
232
+ const reconstructed = SHACLFlow.fromLinks(links, flow.flowUri);
233
+ expect(reconstructed.states.length).toBe(3);
234
+ expect(reconstructed.transitions.length).toBe(2);
235
+ });
236
+ });
237
+ });