@coasys/ad4m 0.12.0-rc1-dev.1 → 0.12.0-rc1-dev.3

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 (124) hide show
  1. package/jest.config.js +8 -1
  2. package/lib/index.cjs +13793 -12854
  3. package/lib/index.js +13782 -12851
  4. package/lib/src/Ad4mClient.test.d.ts +1 -0
  5. package/lib/src/Ad4mClient.test.js +1204 -0
  6. package/lib/src/Literal.test.d.ts +1 -0
  7. package/lib/src/Literal.test.js +41 -0
  8. package/lib/src/model/Ad4mModel.d.ts +528 -101
  9. package/lib/src/model/Ad4mModel.js +1670 -748
  10. package/lib/src/model/Ad4mModel.test.js +140 -156
  11. package/lib/src/model/Subject.d.ts +3 -3
  12. package/lib/src/model/Subject.js +25 -25
  13. package/lib/src/model/decorators.d.ts +259 -247
  14. package/lib/src/model/decorators.js +379 -422
  15. package/lib/src/model/mutation.d.ts +81 -0
  16. package/lib/src/model/mutation.js +317 -0
  17. package/lib/src/model/parentUtils.d.ts +32 -0
  18. package/lib/src/model/parentUtils.js +64 -0
  19. package/lib/src/model/prolog/generatePrologFacts.d.ts +36 -0
  20. package/lib/src/model/prolog/generatePrologFacts.js +139 -0
  21. package/lib/src/model/prolog/index.d.ts +1 -0
  22. package/lib/src/model/prolog/index.js +1 -0
  23. package/lib/src/model/query/ModelQueryBuilder.d.ts +82 -0
  24. package/lib/src/model/query/ModelQueryBuilder.js +115 -0
  25. package/lib/src/model/query/QueryBuilder.d.ts +101 -0
  26. package/lib/src/model/query/QueryBuilder.js +193 -0
  27. package/lib/src/model/query/SurrealQueryBuilder.d.ts +48 -0
  28. package/lib/src/model/query/SurrealQueryBuilder.js +371 -0
  29. package/lib/src/model/query/fetchInstance.d.ts +24 -0
  30. package/lib/src/model/query/fetchInstance.js +144 -0
  31. package/lib/src/model/query/hydration.d.ts +54 -0
  32. package/lib/src/model/query/hydration.js +214 -0
  33. package/lib/src/model/query/operations.d.ts +59 -0
  34. package/lib/src/model/query/operations.js +384 -0
  35. package/lib/src/model/query/snapshot.d.ts +59 -0
  36. package/lib/src/model/query/snapshot.js +106 -0
  37. package/lib/src/model/query/surrealCompiler.d.ts +42 -0
  38. package/lib/src/model/query/surrealCompiler.js +304 -0
  39. package/lib/src/model/schema/fromJSONSchema.d.ts +67 -0
  40. package/lib/src/model/schema/fromJSONSchema.js +264 -0
  41. package/lib/src/model/schema/metadata.d.ts +15 -0
  42. package/lib/src/model/schema/metadata.js +112 -0
  43. package/lib/src/model/subscription.d.ts +47 -0
  44. package/lib/src/model/subscription.js +231 -0
  45. package/lib/src/model/transaction.d.ts +27 -0
  46. package/lib/src/model/transaction.js +32 -0
  47. package/lib/src/model/types.d.ts +195 -0
  48. package/lib/src/model/types.js +8 -0
  49. package/lib/src/model/util.d.ts +6 -6
  50. package/lib/src/model/util.js +22 -22
  51. package/lib/src/neighbourhood/NeighbourhoodClient.js +31 -12
  52. package/lib/src/perspectives/PerspectiveProxy.d.ts +9 -9
  53. package/lib/src/perspectives/PerspectiveProxy.js +63 -51
  54. package/lib/src/shacl/SHACLShape.d.ts +9 -0
  55. package/lib/src/shacl/SHACLShape.js +28 -4
  56. package/lib/src/shims/reflect-metadata.d.ts +0 -0
  57. package/lib/src/shims/type-graphql.d.ts +32 -0
  58. package/lib/src/src/Ad4mClient.d.ts +28 -0
  59. package/lib/src/src/Address.d.ts +1 -0
  60. package/lib/src/src/DID.d.ts +1 -0
  61. package/lib/src/src/Exception.d.ts +7 -0
  62. package/lib/src/src/Literal.d.ts +7 -0
  63. package/lib/src/src/PubSub.d.ts +17 -0
  64. package/lib/src/src/SmartLiteral.d.ts +12 -0
  65. package/lib/src/src/agent/Agent.d.ts +110 -0
  66. package/lib/src/src/agent/AgentClient.d.ts +62 -0
  67. package/lib/src/src/agent/AgentResolver.d.ts +30 -0
  68. package/lib/src/src/agent/AgentStatus.d.ts +8 -0
  69. package/lib/src/src/ai/AIClient.d.ts +32 -0
  70. package/lib/src/src/ai/AIResolver.d.ts +75 -0
  71. package/lib/src/src/ai/Tasks.d.ts +37 -0
  72. package/lib/src/src/buildSchema.d.ts +1 -0
  73. package/lib/src/src/expression/Expression.d.ts +28 -0
  74. package/lib/src/src/expression/ExpressionClient.d.ts +13 -0
  75. package/lib/src/src/expression/ExpressionRef.d.ts +9 -0
  76. package/lib/src/src/expression/ExpressionResolver.d.ts +10 -0
  77. package/lib/src/src/index.d.ts +35 -0
  78. package/lib/src/src/jestSetup.d.ts +1 -0
  79. package/lib/src/src/language/Icon.d.ts +4 -0
  80. package/lib/src/src/language/Language.d.ts +206 -0
  81. package/lib/src/src/language/LanguageClient.d.ts +17 -0
  82. package/lib/src/src/language/LanguageContext.d.ts +37 -0
  83. package/lib/src/src/language/LanguageHandle.d.ts +9 -0
  84. package/lib/src/src/language/LanguageMeta.d.ts +35 -0
  85. package/lib/src/src/language/LanguageRef.d.ts +6 -0
  86. package/lib/src/src/language/LanguageResolver.d.ts +19 -0
  87. package/lib/src/src/links/Links.d.ts +39 -0
  88. package/lib/src/src/links/Links.test.d.ts +1 -0
  89. package/lib/src/src/model/Ad4mModel.d.ts +1438 -0
  90. package/lib/src/src/model/Ad4mModel.test.d.ts +1 -0
  91. package/lib/src/src/model/Subject.d.ts +25 -0
  92. package/lib/src/src/model/decorators.d.ts +545 -0
  93. package/lib/src/src/model/util.d.ts +12 -0
  94. package/lib/src/src/neighbourhood/Neighbourhood.d.ts +10 -0
  95. package/lib/src/src/neighbourhood/NeighbourhoodClient.d.ts +25 -0
  96. package/lib/src/src/neighbourhood/NeighbourhoodProxy.d.ts +19 -0
  97. package/lib/src/src/neighbourhood/NeighbourhoodProxy.test.d.ts +1 -0
  98. package/lib/src/src/neighbourhood/NeighbourhoodResolver.d.ts +24 -0
  99. package/lib/src/src/perspectives/LinkQuery.d.ts +11 -0
  100. package/lib/src/src/perspectives/Perspective.d.ts +38 -0
  101. package/lib/src/src/perspectives/Perspective.test.d.ts +1 -0
  102. package/lib/src/src/perspectives/PerspectiveClient.d.ts +97 -0
  103. package/lib/src/src/perspectives/PerspectiveDiff.d.ts +9 -0
  104. package/lib/src/src/perspectives/PerspectiveHandle.d.ts +18 -0
  105. package/lib/src/src/perspectives/PerspectiveProxy.d.ts +865 -0
  106. package/lib/src/src/perspectives/PerspectiveResolver.d.ts +57 -0
  107. package/lib/src/src/runtime/RuntimeClient.d.ts +56 -0
  108. package/lib/src/src/runtime/RuntimeResolver.d.ts +132 -0
  109. package/lib/src/src/shacl/SHACLFlow.d.ts +171 -0
  110. package/lib/src/src/shacl/SHACLFlow.test.d.ts +1 -0
  111. package/lib/src/src/shacl/SHACLShape.d.ts +117 -0
  112. package/lib/src/src/shacl/SHACLShape.test.d.ts +1 -0
  113. package/lib/src/src/typeDefs.d.ts +1 -0
  114. package/lib/src/src/unwrapApolloResult.d.ts +2 -0
  115. package/lib/src/src/utils.d.ts +25 -0
  116. package/package.json +20 -24
  117. package/src/model/Ad4mModel.test.ts +132 -149
  118. package/src/model/Ad4mModel.ts +1930 -784
  119. package/src/model/Subject.ts +24 -24
  120. package/src/model/decorators.ts +626 -482
  121. package/src/model/util.ts +22 -22
  122. package/src/neighbourhood/NeighbourhoodClient.ts +32 -16
  123. package/src/perspectives/PerspectiveProxy.ts +69 -55
  124. package/src/shacl/SHACLShape.ts +33 -4
@@ -0,0 +1,57 @@
1
+ import { LinkExpression, LinkExpressionInput, LinkExpressionMutations, LinkExpressionUpdated, LinkInput, LinkMutations } from "../links/Links";
2
+ import { LinkQuery } from "./LinkQuery";
3
+ import { Perspective } from "./Perspective";
4
+ import { LinkStatus } from "./PerspectiveProxy";
5
+ import { PerspectiveHandle, PerspectiveState } from "./PerspectiveHandle";
6
+ export declare const testLink: LinkExpression;
7
+ export declare const PERSPECTIVE_QUERY_SUBSCRIPTION = "PERSPECTIVE_QUERY_SUBSCRIPTION";
8
+ export declare class QuerySubscription {
9
+ subscriptionId: string;
10
+ result: string;
11
+ }
12
+ /**
13
+ * Resolver classes are used here to define the GraphQL schema
14
+ * (through the type-graphql annotations)
15
+ * and are spawned in the client tests in Ad4mClient.test.ts.
16
+ * For the latter, they return test fixtures.
17
+ */
18
+ export default class PerspectiveResolver {
19
+ perspectives(): PerspectiveHandle[];
20
+ perspective(uuid: string): PerspectiveHandle | null;
21
+ perspectiveSnapshot(uuid: string): Perspective | null;
22
+ perspectivePublishSnapshot(uuid: string): String | null;
23
+ perspectiveQueryLinks(uuid: string, query: LinkQuery): LinkExpression[];
24
+ perspectiveQueryProlog(uuid: string, query: string): Promise<string>;
25
+ perspectiveQuerySurrealDB(uuid: string, query: string): Promise<string>;
26
+ perspectiveSubscribeQuery(uuid: string, query: string): Promise<QuerySubscription>;
27
+ perspectiveAdd(name: string, pubSub: any): PerspectiveHandle;
28
+ perspectiveUpdate(uuid: string, name: string, pubSub: any): PerspectiveHandle;
29
+ perspectiveRemove(uuid: string, pubSub: any): boolean;
30
+ perspectiveCreateBatch(uuid: string): Promise<string>;
31
+ perspectiveCommitBatch(uuid: string, batchId: string): Promise<LinkExpressionMutations>;
32
+ perspectiveAddLink(uuid: string, link: LinkInput, status: LinkStatus, batchId: string, pubSub: any): LinkExpression;
33
+ perspectiveAddLinks(uuid: string, links: LinkInput[], status: LinkStatus, batchId: string, pubSub: any): LinkExpression[];
34
+ perspectiveRemoveLink(uuid: string, link: LinkExpressionInput, batchId: string, pubSub: any): Boolean;
35
+ perspectiveRemoveLinks(uuid: string, links: LinkExpressionInput[], batchId: string, pubSub: any): LinkExpression[];
36
+ perspectiveLinkMutations(uuid: string, mutations: LinkMutations, status: LinkStatus, pubSub: any): LinkExpressionMutations;
37
+ perspectiveUpdateLink(uuid: string, oldLink: LinkExpressionInput, newLink: LinkInput, batchId: string, pubSub: any): LinkExpression;
38
+ perspectiveAddLinkExpression(uuid: string, link: LinkExpressionInput, status: LinkStatus, batchId: string, pubSub: any): LinkExpression;
39
+ perspectiveAddSdna(uuid: string, name: string, sdnaCode: string, sdnaType: string, shaclJson: string, pubSub: any): Boolean;
40
+ perspectiveExecuteCommands(uuid: string, commands: string, expression: string, parameters: string, batchId?: string): Boolean;
41
+ perspectiveCreateSubject(uuid: string, SubjectClass: string, expressionAddress: string, initialValues?: string, batchId?: string): Boolean;
42
+ perspectiveGetSubjectData(uuid: string, SubjectClass: string, expressionAddress: string): String;
43
+ perspectiveAdded(): PerspectiveHandle;
44
+ perspectiveUpdated(): PerspectiveHandle;
45
+ perspectiveRemoved(): string;
46
+ perspectiveLinkAdded(uuid: string): LinkExpression;
47
+ perspectiveLinkRemoved(uuid: string): LinkExpression;
48
+ perspectiveLinkUpdated(uuid: string): LinkExpressionUpdated;
49
+ perspectiveSyncStateChange(uuid: string): PerspectiveState;
50
+ perspectiveKeepAliveQuery(uuid: string, subscriptionId: string): boolean;
51
+ perspectiveQuerySubscription(subscriptionId: string, payload: {
52
+ subscriptionId: string;
53
+ uuid: string;
54
+ result: string;
55
+ }): string;
56
+ perspectiveDisposeQuerySubscription(uuid: string, subscriptionId: string): Promise<boolean>;
57
+ }
@@ -0,0 +1,56 @@
1
+ import { ApolloClient } from "@apollo/client/core";
2
+ import { Perspective, PerspectiveExpression } from "../perspectives/Perspective";
3
+ import { RuntimeInfo, ExceptionInfo, SentMessage, NotificationInput, Notification, TriggeredNotification, ImportResult, UserStatistics } from "./RuntimeResolver";
4
+ export type MessageCallback = (message: PerspectiveExpression) => null;
5
+ export type ExceptionCallback = (info: ExceptionInfo) => null;
6
+ export type NotificationTriggeredCallback = (notification: TriggeredNotification) => null;
7
+ export type NotificationRequestedCallback = (notification: Notification) => null;
8
+ export declare class RuntimeClient {
9
+ #private;
10
+ constructor(client: ApolloClient<any>, subscribe?: boolean);
11
+ info(): Promise<RuntimeInfo>;
12
+ quit(): Promise<Boolean>;
13
+ openLink(url: string): Promise<Boolean>;
14
+ addTrustedAgents(agents: string[]): Promise<string[]>;
15
+ deleteTrustedAgents(agents: string[]): Promise<string[]>;
16
+ getTrustedAgents(): Promise<string[]>;
17
+ addKnownLinkLanguageTemplates(addresses: string[]): Promise<string[]>;
18
+ removeKnownLinkLanguageTemplates(addresses: string[]): Promise<string[]>;
19
+ knownLinkLanguageTemplates(): Promise<string[]>;
20
+ addFriends(dids: string[]): Promise<string[]>;
21
+ removeFriends(dids: string[]): Promise<string[]>;
22
+ friends(): Promise<string[]>;
23
+ hcAgentInfos(): Promise<string>;
24
+ getNetworkMetrics(): Promise<string>;
25
+ restartHolochain(): Promise<boolean>;
26
+ hcAddAgentInfos(agentInfos: String): Promise<void>;
27
+ verifyStringSignedByDid(did: string, didSigningKeyId: string, data: string, signedData: string): Promise<boolean>;
28
+ setStatus(perspective: Perspective): Promise<boolean>;
29
+ friendStatus(did: string): Promise<PerspectiveExpression>;
30
+ friendSendMessage(did: string, message: Perspective): Promise<boolean>;
31
+ messageInbox(filter?: string): Promise<PerspectiveExpression[]>;
32
+ messageOutbox(filter?: string): Promise<SentMessage[]>;
33
+ requestInstallNotification(notification: NotificationInput): Promise<any>;
34
+ grantNotification(id: string): Promise<boolean>;
35
+ exportDb(filePath: string): Promise<boolean>;
36
+ importDb(filePath: string): Promise<ImportResult>;
37
+ notifications(): Promise<Notification[]>;
38
+ updateNotification(id: string, notification: NotificationInput): Promise<boolean>;
39
+ removeNotification(id: string): Promise<boolean>;
40
+ exportPerspective(uuid: string, filePath: string): Promise<boolean>;
41
+ importPerspective(filePath: string): Promise<boolean>;
42
+ multiUserEnabled(): Promise<boolean>;
43
+ setMultiUserEnabled(enabled: boolean): Promise<boolean>;
44
+ listUsers(): Promise<UserStatistics[]>;
45
+ emailTestModeEnable(): Promise<boolean>;
46
+ emailTestModeDisable(): Promise<boolean>;
47
+ emailTestGetCode(email: string): Promise<string | null>;
48
+ emailTestClearCodes(): Promise<boolean>;
49
+ emailTestSetExpiry(email: string, verificationType: string, expiresAt: number): Promise<boolean>;
50
+ addNotificationTriggeredCallback(cb: NotificationTriggeredCallback): void;
51
+ subscribeNotificationTriggered(): void;
52
+ addMessageCallback(cb: MessageCallback): void;
53
+ subscribeMessageReceived(): void;
54
+ addExceptionCallback(cb: ExceptionCallback): void;
55
+ subscribeExceptionOccurred(): void;
56
+ }
@@ -0,0 +1,132 @@
1
+ import { Perspective, PerspectiveExpression, PerspectiveInput } from "../perspectives/Perspective";
2
+ import { ExceptionType } from "../Exception";
3
+ import { UserCreationResult, AuthInfoInput } from "../agent/Agent";
4
+ export declare class SentMessage {
5
+ recipient: string;
6
+ message: PerspectiveExpression;
7
+ }
8
+ export declare class RuntimeInfo {
9
+ ad4mExecutorVersion: string;
10
+ isInitialized: Boolean;
11
+ isUnlocked: Boolean;
12
+ }
13
+ export declare class ExceptionInfo {
14
+ title: string;
15
+ message: string;
16
+ type: ExceptionType;
17
+ addon?: string;
18
+ }
19
+ export declare class NotificationInput {
20
+ description: string;
21
+ appName: string;
22
+ appUrl: string;
23
+ appIconPath: string;
24
+ trigger: string;
25
+ perspectiveIds: string[];
26
+ webhookUrl: string;
27
+ webhookAuth: string;
28
+ }
29
+ export declare class Notification {
30
+ id: string;
31
+ granted: boolean;
32
+ description: string;
33
+ appName: string;
34
+ appUrl: string;
35
+ appIconPath: string;
36
+ trigger: string;
37
+ perspectiveIds: string[];
38
+ webhookUrl: string;
39
+ webhookAuth: string;
40
+ }
41
+ export declare class TriggeredNotification {
42
+ notification: Notification;
43
+ perspectiveId: string;
44
+ triggerMatch: string;
45
+ }
46
+ export declare class ImportStats {
47
+ total: number;
48
+ imported: number;
49
+ failed: number;
50
+ omitted: number;
51
+ errors: string[];
52
+ }
53
+ export declare class ImportResult {
54
+ perspectives: ImportStats;
55
+ links: ImportStats;
56
+ expressions: ImportStats;
57
+ perspectiveDiffs: ImportStats;
58
+ notifications: ImportStats;
59
+ models: ImportStats;
60
+ defaultModels: ImportStats;
61
+ tasks: ImportStats;
62
+ friends: ImportStats;
63
+ trustedAgents: ImportStats;
64
+ knownLinkLanguages: ImportStats;
65
+ }
66
+ export declare class UserStatistics {
67
+ email: string;
68
+ did: string;
69
+ lastSeen?: string;
70
+ perspectiveCount: number;
71
+ }
72
+ export declare class VerificationRequestResult {
73
+ success: boolean;
74
+ message: string;
75
+ requiresPassword: boolean;
76
+ isExistingUser: boolean;
77
+ }
78
+ /**
79
+ * Resolver classes are used here to define the GraphQL schema
80
+ * (through the type-graphql annotations)
81
+ * and are spawned in the client tests in Ad4mClient.test.ts.
82
+ * For the latter, they return test fixtures.
83
+ */
84
+ export default class RuntimeResolver {
85
+ runtimeQuit(): Boolean;
86
+ runtimeOpenLink(url: string): Boolean;
87
+ runtimeInfo(): RuntimeInfo;
88
+ addTrustedAgents(agents: string[]): string[];
89
+ deleteTrustedAgents(agents: string[]): string[];
90
+ getTrustedAgents(): string[];
91
+ runtimeKnownLinkLanguageTemplates(): string[];
92
+ runtimeAddKnownLinkLanguageTemplates(addresses: string[]): string[];
93
+ runtimeRemoveKnownLinkLanguageTemplates(addresses: string[]): string[];
94
+ runtimeFriends(): string[];
95
+ runtimeAddFriends(dids: string[]): string[];
96
+ runtimeRemoveFriends(dids: string[]): string[];
97
+ runtimeHcAgentInfos(): string;
98
+ runtimeGetNetworkMetrics(): string;
99
+ runtimeRestartHolochain(): boolean;
100
+ runtimeHcAddAgentInfos(agentInfos: any): boolean;
101
+ runtimeVerifyStringSignedByDid(did: string, didSigningKeyId: string, data: string, signedData: string): boolean;
102
+ runtimeSetStatus(status: Perspective): boolean;
103
+ runtimeFriendStatus(did: string): PerspectiveExpression;
104
+ runtimeFriendSendMessage(did: string, message: PerspectiveInput): boolean;
105
+ runtimeMessageInbox(filter?: string): PerspectiveExpression[];
106
+ runtimeMessageOutbox(filter?: string): SentMessage[];
107
+ runtimeMessageReceived(): PerspectiveExpression;
108
+ exceptionOccurred(): ExceptionInfo;
109
+ runtimeRequestInstallNotification(notification: NotificationInput): string;
110
+ runtimeNotifications(): Notification[];
111
+ runtimeUpdateNotification(id: string, notification: NotificationInput): boolean;
112
+ runtimeRemoveNotification(id: string): boolean;
113
+ runtimeGrantNotification(id: string): boolean;
114
+ runtimeNotificationTriggered(): TriggeredNotification;
115
+ runtimeExportDb(filePath: string): boolean;
116
+ runtimeImportDb(filePath: string): boolean;
117
+ runtimeExportPerspective(perspectiveUuid: string, filePath: string): boolean;
118
+ runtimeImportPerspective(filePath: string): boolean;
119
+ runtimeMultiUserEnabled(): boolean;
120
+ runtimeSetMultiUserEnabled(enabled: boolean): boolean;
121
+ runtimeListUsers(): UserStatistics[];
122
+ runtimeRequestLoginVerification(email: string, appInfo?: AuthInfoInput): VerificationRequestResult;
123
+ runtimeVerifyEmailCode(email: string, code: string, verificationType: string): string;
124
+ runtimeTestEmail(to: string): boolean;
125
+ runtimeCreateUser(email: string, password: string, appInfo?: AuthInfoInput): UserCreationResult;
126
+ runtimeLoginUser(email: string, password: string): string;
127
+ runtimeEmailTestModeEnable(): boolean;
128
+ runtimeEmailTestModeDisable(): boolean;
129
+ runtimeEmailTestGetCode(email: string): string | null;
130
+ runtimeEmailTestClearCodes(): boolean;
131
+ runtimeEmailTestSetExpiry(email: string, verificationType: string, expiresAt: number): boolean;
132
+ }
@@ -0,0 +1,171 @@
1
+ import { Link } from "../links/Links";
2
+ import { AD4MAction } from "./SHACLShape";
3
+ export { AD4MAction };
4
+ /**
5
+ * Link pattern for state detection
6
+ * Used to check if an expression is in a particular state
7
+ */
8
+ export interface LinkPattern {
9
+ /** Optional source pattern (if omitted, uses the expression address) */
10
+ source?: string;
11
+ /** Required predicate to match */
12
+ predicate: string;
13
+ /** Required target value to match */
14
+ target: string;
15
+ }
16
+ /**
17
+ * Flow State definition
18
+ * Represents a single state in the flow state machine
19
+ */
20
+ export interface FlowState {
21
+ /** State name (e.g., "ready", "doing", "done") */
22
+ name: string;
23
+ /** Numeric state value for ordering (e.g., 0, 0.5, 1) */
24
+ value: number;
25
+ /** Link pattern that indicates this state */
26
+ stateCheck: LinkPattern;
27
+ }
28
+ /**
29
+ * Flow Transition definition
30
+ * Represents a transition between two states
31
+ */
32
+ export interface FlowTransition {
33
+ /** Name of this action (shown to users, e.g., "Start", "Finish") */
34
+ actionName: string;
35
+ /** State to transition from */
36
+ fromState: string;
37
+ /** State to transition to */
38
+ toState: string;
39
+ /** Actions to execute for this transition */
40
+ actions: AD4MAction[];
41
+ }
42
+ /**
43
+ * Flowable condition - determines which expressions can enter this flow
44
+ * "any" means all expressions can start this flow
45
+ * Otherwise, a link pattern to check
46
+ */
47
+ export type FlowableCondition = "any" | LinkPattern;
48
+ /**
49
+ * SHACL Flow - represents a state machine for AD4M expressions
50
+ *
51
+ * Flows define:
52
+ * - Which expressions can enter the flow (flowable condition)
53
+ * - What states exist and how to detect them (via link patterns)
54
+ * - How to transition between states (via actions)
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * const todoFlow = new SHACLFlow('todo://TODO', 'todo://');
59
+ *
60
+ * // Any expression can become a TODO
61
+ * todoFlow.flowable = 'any';
62
+ *
63
+ * // Define states
64
+ * todoFlow.addState({
65
+ * name: 'ready',
66
+ * value: 0,
67
+ * stateCheck: { predicate: 'todo://state', target: 'todo://ready' }
68
+ * });
69
+ * todoFlow.addState({
70
+ * name: 'doing',
71
+ * value: 0.5,
72
+ * stateCheck: { predicate: 'todo://state', target: 'todo://doing' }
73
+ * });
74
+ * todoFlow.addState({
75
+ * name: 'done',
76
+ * value: 1,
77
+ * stateCheck: { predicate: 'todo://state', target: 'todo://done' }
78
+ * });
79
+ *
80
+ * // Define start action
81
+ * todoFlow.startAction = [{
82
+ * action: 'addLink',
83
+ * source: 'this',
84
+ * predicate: 'todo://state',
85
+ * target: 'todo://ready'
86
+ * }];
87
+ *
88
+ * // Define transitions
89
+ * todoFlow.addTransition({
90
+ * actionName: 'Start',
91
+ * fromState: 'ready',
92
+ * toState: 'doing',
93
+ * actions: [
94
+ * { action: 'addLink', source: 'this', predicate: 'todo://state', target: 'todo://doing' },
95
+ * { action: 'removeLink', source: 'this', predicate: 'todo://state', target: 'todo://ready' }
96
+ * ]
97
+ * });
98
+ *
99
+ * // Store in perspective
100
+ * await perspective.addFlow('TODO', todoFlow);
101
+ * ```
102
+ */
103
+ export declare class SHACLFlow {
104
+ /** Flow name (e.g., "TODO") */
105
+ name: string;
106
+ /** Namespace for generated URIs */
107
+ namespace: string;
108
+ /** Condition for which expressions can start this flow */
109
+ flowable: FlowableCondition;
110
+ /** Actions to execute when starting the flow */
111
+ startAction: AD4MAction[];
112
+ /** States in this flow */
113
+ private _states;
114
+ /** Transitions between states */
115
+ private _transitions;
116
+ /**
117
+ * Create a new SHACL Flow
118
+ * @param name - Flow name (e.g., "TODO")
119
+ * @param namespace - Namespace for URIs (e.g., "todo://")
120
+ */
121
+ constructor(name: string, namespace: string);
122
+ /** Get all states */
123
+ get states(): FlowState[];
124
+ /** Get all transitions */
125
+ get transitions(): FlowTransition[];
126
+ /**
127
+ * Add a state to the flow
128
+ * @param state - State definition
129
+ */
130
+ addState(state: FlowState): void;
131
+ /**
132
+ * Add a transition to the flow
133
+ * @param transition - Transition definition
134
+ */
135
+ addTransition(transition: FlowTransition): void;
136
+ /**
137
+ * Get the flow shape URI
138
+ */
139
+ get flowUri(): string;
140
+ /**
141
+ * Get a state URI
142
+ */
143
+ stateUri(stateName: string): string;
144
+ /**
145
+ * Get a transition URI
146
+ */
147
+ transitionUri(fromState: string, toState: string): string;
148
+ /**
149
+ * Serialize the flow to AD4M links
150
+ * These links can be stored in a perspective and queried via SurrealDB
151
+ *
152
+ * @returns Array of Link objects representing the flow
153
+ */
154
+ toLinks(): Link[];
155
+ /**
156
+ * Reconstruct a SHACLFlow from links
157
+ *
158
+ * @param links - Array of links containing the flow definition
159
+ * @param flowUri - The URI of the flow to reconstruct
160
+ * @returns Reconstructed SHACLFlow
161
+ */
162
+ static fromLinks(links: Link[], flowUri: string): SHACLFlow;
163
+ /**
164
+ * Convert to JSON representation
165
+ */
166
+ toJSON(): object;
167
+ /**
168
+ * Create from JSON representation
169
+ */
170
+ static fromJSON(json: any): SHACLFlow;
171
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,117 @@
1
+ import { Link } from "../links/Links";
2
+ /**
3
+ * AD4M Action - represents a link operation
4
+ */
5
+ export interface AD4MAction {
6
+ action: string;
7
+ source: string;
8
+ predicate: string;
9
+ target: string;
10
+ local?: boolean;
11
+ }
12
+ /**
13
+ * SHACL Property Shape
14
+ * Represents constraints on a single property path
15
+ */
16
+ export interface SHACLPropertyShape {
17
+ /** Property name (e.g., "name", "ingredients") - used for generating named URIs */
18
+ name?: string;
19
+ /** The property path (predicate URI) */
20
+ path: string;
21
+ /** Expected datatype (e.g., xsd:string, xsd:integer) */
22
+ datatype?: string;
23
+ /** Node kind constraint (IRI, Literal, BlankNode) */
24
+ nodeKind?: 'IRI' | 'Literal' | 'BlankNode';
25
+ /** Minimum cardinality (required if >= 1) */
26
+ minCount?: number;
27
+ /** Maximum cardinality (single-valued if 1, omit for collections) */
28
+ maxCount?: number;
29
+ /** Regex pattern for string validation */
30
+ pattern?: string;
31
+ /** Minimum value (inclusive) for numeric properties */
32
+ minInclusive?: number;
33
+ /** Maximum value (inclusive) for numeric properties */
34
+ maxInclusive?: number;
35
+ /** Fixed value constraint (for Flag properties) */
36
+ hasValue?: string;
37
+ /** AD4M-specific: Local-only property */
38
+ local?: boolean;
39
+ /** AD4M-specific: Writable property */
40
+ writable?: boolean;
41
+ /** AD4M-specific: Language to resolve property values through */
42
+ resolveLanguage?: string;
43
+ /** AD4M-specific: Setter action for this property */
44
+ setter?: AD4MAction[];
45
+ /** AD4M-specific: Adder action for collection properties */
46
+ adder?: AD4MAction[];
47
+ /** AD4M-specific: Remover action for collection properties */
48
+ remover?: AD4MAction[];
49
+ }
50
+ /**
51
+ * SHACL Node Shape
52
+ * Defines constraints for instances of a class
53
+ */
54
+ export declare class SHACLShape {
55
+ /** URI of this shape (e.g., recipe:RecipeShape) */
56
+ nodeShapeUri: string;
57
+ /** Target class this shape applies to (e.g., recipe:Recipe) */
58
+ targetClass?: string;
59
+ /** Property constraints */
60
+ properties: SHACLPropertyShape[];
61
+ /** AD4M-specific: Constructor actions for creating instances */
62
+ constructor_actions?: AD4MAction[];
63
+ /** AD4M-specific: Destructor actions for removing instances */
64
+ destructor_actions?: AD4MAction[];
65
+ /** Parent shape URIs for model inheritance (sh:node references) */
66
+ parentShapes: string[];
67
+ /**
68
+ * Create a new SHACL Shape
69
+ * @param targetClassOrShapeUri - If one argument: the target class (shape URI auto-derived as {class}Shape)
70
+ * If two arguments: first is shape URI, second is target class
71
+ * @param targetClass - Optional target class when first arg is shape URI
72
+ */
73
+ constructor(targetClassOrShapeUri: string, targetClass?: string);
74
+ /**
75
+ * Add a parent shape reference (sh:node) for model inheritance.
76
+ * When a @Model class extends another @Model, the child shape
77
+ * references the parent shape so SHACL validators can walk the
78
+ * class hierarchy.
79
+ */
80
+ addParentShape(parentShapeUri: string): void;
81
+ /**
82
+ * Add a property constraint to this shape
83
+ */
84
+ addProperty(prop: SHACLPropertyShape): void;
85
+ /**
86
+ * Set constructor actions for this shape
87
+ */
88
+ setConstructorActions(actions: AD4MAction[]): void;
89
+ /**
90
+ * Set destructor actions for this shape
91
+ */
92
+ setDestructorActions(actions: AD4MAction[]): void;
93
+ /**
94
+ * Serialize shape to Turtle (RDF) format
95
+ */
96
+ toTurtle(): string;
97
+ /**
98
+ * Serialize shape to AD4M Links (RDF triples)
99
+ * Stores the shape as a graph of links in a Perspective
100
+ */
101
+ toLinks(): Link[];
102
+ /**
103
+ * Reconstruct shape from AD4M Links
104
+ */
105
+ static fromLinks(links: Link[], shapeUri: string): SHACLShape;
106
+ /**
107
+ * Convert the shape to a JSON-serializable object.
108
+ * Useful for passing to addSdna() as shaclJson parameter.
109
+ *
110
+ * @returns JSON-serializable object representing the shape
111
+ */
112
+ toJSON(): object;
113
+ /**
114
+ * Create a shape from a JSON object (inverse of toJSON)
115
+ */
116
+ static fromJSON(json: any): SHACLShape;
117
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare const typeDefsString = "";
@@ -0,0 +1,2 @@
1
+ import { ApolloQueryResult, FetchResult } from "@apollo/client/core";
2
+ export default function unwrapApolloResult(result: ApolloQueryResult<any> | FetchResult<any>): any;
@@ -0,0 +1,25 @@
1
+ export declare function formatList(list: any): any;
2
+ export declare function capSentence(cap: any): string;
3
+ /**
4
+ * Escapes a string value for safe use in SurrealQL queries.
5
+ *
6
+ * @description
7
+ * Prevents SQL injection by properly escaping special characters in string values
8
+ * that will be interpolated into SurrealQL queries. This handles the most common
9
+ * special characters that could break SQL queries or enable injection attacks.
10
+ *
11
+ * Single quotes, backslashes, and other special characters are escaped using
12
+ * backslash notation, which is the standard escaping mechanism for SurrealQL.
13
+ *
14
+ * @param value - The string value to escape
15
+ * @returns The escaped string safe for SurrealQL interpolation (without surrounding quotes)
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const userInput = "user's input with 'quotes'";
20
+ * const escaped = escapeSurrealString(userInput);
21
+ * const query = `SELECT * FROM link WHERE uri = '${escaped}'`;
22
+ * // Results in: SELECT * FROM link WHERE uri = 'user\'s input with \'quotes\''
23
+ * ```
24
+ */
25
+ export declare function escapeSurrealString(value: string): string;
package/package.json CHANGED
@@ -5,12 +5,6 @@
5
5
  "module": "lib/index.js",
6
6
  "types": "lib/src/index.d.ts",
7
7
  "type": "module",
8
- "scripts": {
9
- "build": "patch-package && tsc && pnpm run buildSchema && pnpm run bundle",
10
- "buildSchema": "node --es-module-specifier-resolution=node lib/src/buildSchema.js",
11
- "bundle": "rollup -c rollup.config.js",
12
- "test": "jest --forceExit"
13
- },
14
8
  "repository": {
15
9
  "type": "git",
16
10
  "url": "git+https://github.com/coasys/ad4m.git"
@@ -33,40 +27,42 @@
33
27
  "dependencies": {
34
28
  "@apollo/client": "3.7.10",
35
29
  "@holochain/client": "0.16.0",
36
- "@types/jest": "^26.0.14",
30
+ "base64-js": "*",
37
31
  "class-validator": "^0.13.1",
38
32
  "express": "4.18.2",
39
33
  "graphql": "15.7.2",
40
- "reflect-metadata": "^0.1.13",
41
34
  "pako": "*",
42
- "base64-js": "*"
35
+ "reflect-metadata": "^0.1.13"
43
36
  },
44
37
  "devDependencies": {
45
38
  "@apollo/server": "^4.9.4",
46
39
  "@rollup/plugin-alias": "^3.1.5",
47
40
  "@rollup/plugin-commonjs": "^20.0.0",
48
41
  "@rollup/plugin-node-resolve": "^13.0.4",
42
+ "@types/jest": "^29",
43
+ "@types/node": "*",
44
+ "@types/yargs": "*",
49
45
  "concat-md": "^0.5.0",
50
46
  "cross-fetch": "^3.1.4",
51
47
  "graphql-ws": "5.12.0",
52
48
  "honkit": "^4.0.0",
53
- "jest": "^26.6.0",
54
- "type-graphql": "1.1.1",
49
+ "jest": "^29",
55
50
  "patch-package": "^8.0.0",
51
+ "react": "*",
52
+ "react-dom": "*",
56
53
  "rollup": "^2.56.3",
57
- "ts-jest": "^26.5.6",
54
+ "ts-jest": "^29",
55
+ "tsx": "^4.21.0",
56
+ "type-graphql": "1.1.1",
58
57
  "typescript": "^4.6.2",
59
- "ws": "8.13.0",
60
- "@types/node": "*",
61
- "@types/yargs": "*",
62
- "react": "*",
63
- "react-dom": "*"
58
+ "ws": "8.13.0"
64
59
  },
65
60
  "patchedDependencies": {},
66
- "pnpm": {
67
- "patchedDependencies": {
68
- "graphql@15.7.2": "patches/graphql@15.7.2.patch"
69
- }
70
- },
71
- "version": "0.12.0-rc1-dev.1"
72
- }
61
+ "version": "0.12.0-rc1-dev.3",
62
+ "scripts": {
63
+ "build": "patch-package && tsc && pnpm run buildSchema && pnpm run bundle",
64
+ "buildSchema": "tsx lib/src/buildSchema.js",
65
+ "bundle": "rollup -c rollup.config.js",
66
+ "test": "jest --forceExit"
67
+ }
68
+ }