@coasys/ad4m 0.13.0-postmessage-ws-proxy.0 → 0.13.0-postmessage-ws-proxy.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.cjs +825 -653
- package/lib/index.js +812 -654
- package/lib/src/Ad4mClient.d.ts +1 -0
- package/lib/src/Ad4mClient.js +1 -1
- package/lib/src/ai/AIClient.js +1 -1
- package/lib/src/apiClient.d.ts +4 -1
- package/lib/src/apiClient.js +6 -1
- package/lib/src/index.d.ts +4 -0
- package/lib/src/index.js +4 -0
- package/lib/src/model/Ad4mModel.d.ts +9 -32
- package/lib/src/model/Ad4mModel.js +36 -266
- package/lib/src/model/ModelQueryBuilder.d.ts +5 -10
- package/lib/src/model/ModelQueryBuilder.js +20 -36
- package/lib/src/model/decorators.d.ts +7 -4
- package/lib/src/model/shacl-gen.js +120 -47
- package/lib/src/model/types.d.ts +140 -4
- package/lib/src/perspectives/PerspectiveClient.d.ts +4 -4
- package/lib/src/perspectives/PerspectiveClient.js +5 -6
- package/lib/src/perspectives/PerspectiveProxy.d.ts +8 -7
- package/lib/src/perspectives/PerspectiveProxy.js +10 -9
- package/lib/src/perspectives/SparqlBindings.d.ts +47 -0
- package/lib/src/perspectives/SparqlBindings.js +65 -0
- package/lib/src/shacl/NodeExpression.d.ts +44 -0
- package/lib/src/shacl/NodeExpression.js +39 -0
- package/lib/src/shacl/SHACLShape.d.ts +23 -0
- package/lib/src/shacl/SHACLShape.js +115 -1
- package/lib/src/shacl/builders.d.ts +58 -0
- package/lib/src/shacl/builders.js +76 -0
- package/lib/src/shacl/index.d.ts +36 -0
- package/lib/src/shacl/index.js +33 -0
- package/package.json +8 -11
- package/src/Ad4mClient.ts +2 -2
- package/src/ai/AIClient.ts +1 -1
- package/src/apiClient.ts +8 -1
- package/src/index.ts +4 -0
- package/src/model/Ad4mModel.test.ts +33 -74
- package/src/model/Ad4mModel.ts +54 -272
- package/src/model/ModelQueryBuilder.ts +29 -46
- package/src/model/decorators.ts +7 -4
- package/src/model/relation-filtering.test.ts +46 -39
- package/src/model/shacl-gen.ts +128 -54
- package/src/model/shacl-roundtrip.test.ts +197 -0
- package/src/model/types-typed-query.test.ts +360 -0
- package/src/model/types.ts +196 -4
- package/src/perspectives/PerspectiveClient.ts +6 -8
- package/src/perspectives/PerspectiveProxy.ts +13 -13
- package/src/perspectives/SparqlBindings.ts +79 -0
- package/src/shacl/NodeExpression.ts +54 -0
- package/src/shacl/SHACLShape.test.ts +172 -0
- package/src/shacl/SHACLShape.ts +173 -1
- package/src/shacl/builders.ts +86 -0
- package/src/shacl/index.ts +72 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builder functions for SHACL-AF Node Expressions.
|
|
3
|
+
*
|
|
4
|
+
* These functions construct JSON-serializable expression trees for property transforms.
|
|
5
|
+
* All builders return frozen objects to prevent accidental mutation.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { NodeExpression } from './NodeExpression';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Identity expression: pass the focus node through unchanged.
|
|
12
|
+
*/
|
|
13
|
+
export function focus(): NodeExpression {
|
|
14
|
+
return Object.freeze({ type: 'focus' });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Literal constant expression.
|
|
19
|
+
*/
|
|
20
|
+
export function literal(value: string | number | boolean): NodeExpression {
|
|
21
|
+
return Object.freeze({ type: 'literal', value });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Path expression: navigate to a property on the resolved object.
|
|
26
|
+
* The predicate can be a full IRI (e.g., "file_storage://data_base64")
|
|
27
|
+
* or a simple property name. The Rust evaluator will strip the namespace.
|
|
28
|
+
*/
|
|
29
|
+
export function path(predicate: string): NodeExpression {
|
|
30
|
+
return Object.freeze({ type: 'path', predicate });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Existence check: returns true if the inner expression is non-null and non-empty.
|
|
35
|
+
*/
|
|
36
|
+
export function exists(expr: NodeExpression): NodeExpression {
|
|
37
|
+
return Object.freeze({ type: 'exists', expr });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Conditional expression with optional else branch.
|
|
42
|
+
* Returns a chainable builder that supports `.then()` and `.else()`.
|
|
43
|
+
*/
|
|
44
|
+
export function ifExpr(cond: NodeExpression) {
|
|
45
|
+
return {
|
|
46
|
+
then: (thenExpr: NodeExpression) => ({
|
|
47
|
+
else: (elseExpr?: NodeExpression) => {
|
|
48
|
+
return Object.freeze({
|
|
49
|
+
type: 'if',
|
|
50
|
+
cond,
|
|
51
|
+
then: thenExpr,
|
|
52
|
+
...(elseExpr !== undefined && { else: elseExpr }),
|
|
53
|
+
} as const);
|
|
54
|
+
},
|
|
55
|
+
// Allow chaining without explicit else()
|
|
56
|
+
toExpression: () => Object.freeze({
|
|
57
|
+
type: 'if',
|
|
58
|
+
cond,
|
|
59
|
+
then: thenExpr,
|
|
60
|
+
} as const),
|
|
61
|
+
}),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* String concatenation: joins evaluated arguments as strings.
|
|
67
|
+
* Null/undefined arguments are skipped.
|
|
68
|
+
*/
|
|
69
|
+
export function concat(...args: NodeExpression[]): NodeExpression {
|
|
70
|
+
return Object.freeze({ type: 'concat', args });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Coalesce: returns the first non-null evaluated argument.
|
|
75
|
+
*/
|
|
76
|
+
export function coalesce(...args: NodeExpression[]): NodeExpression {
|
|
77
|
+
return Object.freeze({ type: 'coalesce', args });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Function call: invoke a named transform function by IRI.
|
|
82
|
+
* Primarily used for built-in functions like "ad4m://fn/defaultFileDecode".
|
|
83
|
+
*/
|
|
84
|
+
export function fn(iri: string, args: NodeExpression[] = []): NodeExpression {
|
|
85
|
+
return Object.freeze({ type: 'function', iri, args });
|
|
86
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SHACL-AF Transform DSL — public API
|
|
3
|
+
*
|
|
4
|
+
* Re-exports builder functions and provides common built-in transforms.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
focus,
|
|
9
|
+
literal,
|
|
10
|
+
path,
|
|
11
|
+
exists,
|
|
12
|
+
ifExpr,
|
|
13
|
+
concat,
|
|
14
|
+
coalesce,
|
|
15
|
+
fn,
|
|
16
|
+
} from './builders';
|
|
17
|
+
|
|
18
|
+
export type { NodeExpression } from './NodeExpression';
|
|
19
|
+
export { isNodeExpression } from './NodeExpression';
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
focus,
|
|
23
|
+
literal,
|
|
24
|
+
path,
|
|
25
|
+
exists,
|
|
26
|
+
ifExpr,
|
|
27
|
+
concat,
|
|
28
|
+
coalesce,
|
|
29
|
+
fn,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Built-in transform: FileData → data: URI
|
|
34
|
+
*
|
|
35
|
+
* Converts a file stored via FILE_STORAGE_LANGUAGE into a data: URL.
|
|
36
|
+
* If the object has a `data_base64` field, returns:
|
|
37
|
+
* `data:{file_type};base64,{data_base64}`
|
|
38
|
+
* Otherwise passes through the input unchanged.
|
|
39
|
+
*
|
|
40
|
+
* This is the Rust equivalent of the JS `defaultFileDecode` function.
|
|
41
|
+
*
|
|
42
|
+
* Usage:
|
|
43
|
+
* ```typescript
|
|
44
|
+
* @Property({
|
|
45
|
+
* through: 'we://image',
|
|
46
|
+
* resolveLanguage: FILE_STORAGE_LANGUAGE,
|
|
47
|
+
* transform: fileToDataUri,
|
|
48
|
+
* })
|
|
49
|
+
* avatar?: string;
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export const fileToDataUri = ifExpr(exists(path('file_storage://data_base64')))
|
|
53
|
+
.then(
|
|
54
|
+
concat(
|
|
55
|
+
literal('data:'),
|
|
56
|
+
coalesce(
|
|
57
|
+
path('file_storage://file_type'),
|
|
58
|
+
literal('image/png'),
|
|
59
|
+
),
|
|
60
|
+
literal(';base64,'),
|
|
61
|
+
path('file_storage://data_base64'),
|
|
62
|
+
),
|
|
63
|
+
)
|
|
64
|
+
.else(focus());
|
|
65
|
+
|
|
66
|
+
// Re-export SHACL types for convenience
|
|
67
|
+
export {
|
|
68
|
+
SHACLShape,
|
|
69
|
+
SHACLPropertyShape,
|
|
70
|
+
AD4MAction,
|
|
71
|
+
ConformanceCondition,
|
|
72
|
+
} from './SHACLShape';
|