agentlang 0.0.2
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/LICENSE +83 -0
- package/README.md +120 -0
- package/bin/cli.js +4 -0
- package/out/api/http.d.ts +3 -0
- package/out/api/http.d.ts.map +1 -0
- package/out/api/http.js +290 -0
- package/out/api/http.js.map +1 -0
- package/out/cli/cli-util.d.ts +7 -0
- package/out/cli/cli-util.d.ts.map +1 -0
- package/out/cli/cli-util.js +9 -0
- package/out/cli/cli-util.js.map +1 -0
- package/out/cli/docs.d.ts +2 -0
- package/out/cli/docs.d.ts.map +1 -0
- package/out/cli/docs.js +236 -0
- package/out/cli/docs.js.map +1 -0
- package/out/cli/main.d.ts +288 -0
- package/out/cli/main.d.ts.map +1 -0
- package/out/cli/main.js +119 -0
- package/out/cli/main.js.map +1 -0
- package/out/cli/openapi-docs.yml +695 -0
- package/out/extension/main.cjs +18093 -0
- package/out/extension/main.cjs.map +7 -0
- package/out/extension/main.d.ts +4 -0
- package/out/extension/main.d.ts.map +1 -0
- package/out/extension/main.js +42 -0
- package/out/extension/main.js.map +1 -0
- package/out/language/agentlang-module.d.ts +42 -0
- package/out/language/agentlang-module.d.ts.map +1 -0
- package/out/language/agentlang-module.js +42 -0
- package/out/language/agentlang-module.js.map +1 -0
- package/out/language/agentlang-validator.d.ts +15 -0
- package/out/language/agentlang-validator.d.ts.map +1 -0
- package/out/language/agentlang-validator.js +50 -0
- package/out/language/agentlang-validator.js.map +1 -0
- package/out/language/generated/ast.d.ts +491 -0
- package/out/language/generated/ast.d.ts.map +1 -0
- package/out/language/generated/ast.js +934 -0
- package/out/language/generated/ast.js.map +1 -0
- package/out/language/generated/grammar.d.ts +7 -0
- package/out/language/generated/grammar.d.ts.map +1 -0
- package/out/language/generated/grammar.js +4475 -0
- package/out/language/generated/grammar.js.map +1 -0
- package/out/language/generated/module.d.ts +14 -0
- package/out/language/generated/module.d.ts.map +1 -0
- package/out/language/generated/module.js +21 -0
- package/out/language/generated/module.js.map +1 -0
- package/out/language/main-browser.d.ts +2 -0
- package/out/language/main-browser.d.ts.map +1 -0
- package/out/language/main-browser.js +10 -0
- package/out/language/main-browser.js.map +1 -0
- package/out/language/main.cjs +36229 -0
- package/out/language/main.cjs.map +7 -0
- package/out/language/main.d.ts +2 -0
- package/out/language/main.d.ts.map +1 -0
- package/out/language/main.js +11 -0
- package/out/language/main.js.map +1 -0
- package/out/language/parser.d.ts +9 -0
- package/out/language/parser.d.ts.map +1 -0
- package/out/language/parser.js +273 -0
- package/out/language/parser.js.map +1 -0
- package/out/language/syntax.d.ts +155 -0
- package/out/language/syntax.d.ts.map +1 -0
- package/out/language/syntax.js +527 -0
- package/out/language/syntax.js.map +1 -0
- package/out/runtime/agents/common.d.ts +2 -0
- package/out/runtime/agents/common.d.ts.map +1 -0
- package/out/runtime/agents/common.js +178 -0
- package/out/runtime/agents/common.js.map +1 -0
- package/out/runtime/agents/impl/openai.d.ts +8 -0
- package/out/runtime/agents/impl/openai.d.ts.map +1 -0
- package/out/runtime/agents/impl/openai.js +15 -0
- package/out/runtime/agents/impl/openai.js.map +1 -0
- package/out/runtime/agents/provider.d.ts +21 -0
- package/out/runtime/agents/provider.d.ts.map +1 -0
- package/out/runtime/agents/provider.js +32 -0
- package/out/runtime/agents/provider.js.map +1 -0
- package/out/runtime/agents/registry.d.ts +2 -0
- package/out/runtime/agents/registry.d.ts.map +1 -0
- package/out/runtime/agents/registry.js +10 -0
- package/out/runtime/agents/registry.js.map +1 -0
- package/out/runtime/auth/cognito.d.ts +16 -0
- package/out/runtime/auth/cognito.d.ts.map +1 -0
- package/out/runtime/auth/cognito.js +186 -0
- package/out/runtime/auth/cognito.js.map +1 -0
- package/out/runtime/auth/defs.d.ts +11 -0
- package/out/runtime/auth/defs.d.ts.map +1 -0
- package/out/runtime/auth/defs.js +24 -0
- package/out/runtime/auth/defs.js.map +1 -0
- package/out/runtime/auth/interface.d.ts +22 -0
- package/out/runtime/auth/interface.d.ts.map +1 -0
- package/out/runtime/auth/interface.js +2 -0
- package/out/runtime/auth/interface.js.map +1 -0
- package/out/runtime/defs.js +24 -0
- package/out/runtime/defs.js.map +1 -0
- package/out/runtime/interpreter.d.ts +69 -0
- package/out/runtime/interpreter.d.ts.map +1 -0
- package/out/runtime/interpreter.js +1163 -0
- package/out/runtime/interpreter.js.map +1 -0
- package/out/runtime/loader.d.ts +25 -0
- package/out/runtime/loader.d.ts.map +1 -0
- package/out/runtime/loader.js +346 -0
- package/out/runtime/loader.js.map +1 -0
- package/out/runtime/logger.d.ts +2 -0
- package/out/runtime/logger.d.ts.map +1 -0
- package/out/runtime/logger.js +44 -0
- package/out/runtime/logger.js.map +1 -0
- package/out/runtime/module.d.ts +273 -0
- package/out/runtime/module.d.ts.map +1 -0
- package/out/runtime/module.js +1786 -0
- package/out/runtime/module.js.map +1 -0
- package/out/runtime/modules/ai.d.ts +26 -0
- package/out/runtime/modules/ai.d.ts.map +1 -0
- package/out/runtime/modules/ai.js +211 -0
- package/out/runtime/modules/ai.js.map +1 -0
- package/out/runtime/modules/auth.d.ts +39 -0
- package/out/runtime/modules/auth.d.ts.map +1 -0
- package/out/runtime/modules/auth.js +359 -0
- package/out/runtime/modules/auth.js.map +1 -0
- package/out/runtime/modules/core.d.ts +2 -0
- package/out/runtime/modules/core.d.ts.map +1 -0
- package/out/runtime/modules/core.js +67 -0
- package/out/runtime/modules/core.js.map +1 -0
- package/out/runtime/relgraph.d.ts +21 -0
- package/out/runtime/relgraph.d.ts.map +1 -0
- package/out/runtime/relgraph.js +156 -0
- package/out/runtime/relgraph.js.map +1 -0
- package/out/runtime/resolvers/interface.d.ts +59 -0
- package/out/runtime/resolvers/interface.d.ts.map +1 -0
- package/out/runtime/resolvers/interface.js +111 -0
- package/out/runtime/resolvers/interface.js.map +1 -0
- package/out/runtime/resolvers/registry.d.ts +8 -0
- package/out/runtime/resolvers/registry.d.ts.map +1 -0
- package/out/runtime/resolvers/registry.js +26 -0
- package/out/runtime/resolvers/registry.js.map +1 -0
- package/out/runtime/resolvers/sqldb/database.d.ts +50 -0
- package/out/runtime/resolvers/sqldb/database.d.ts.map +1 -0
- package/out/runtime/resolvers/sqldb/database.js +618 -0
- package/out/runtime/resolvers/sqldb/database.js.map +1 -0
- package/out/runtime/resolvers/sqldb/dbutil.d.ts +18 -0
- package/out/runtime/resolvers/sqldb/dbutil.d.ts.map +1 -0
- package/out/runtime/resolvers/sqldb/dbutil.js +221 -0
- package/out/runtime/resolvers/sqldb/dbutil.js.map +1 -0
- package/out/runtime/resolvers/sqldb/impl.d.ts +26 -0
- package/out/runtime/resolvers/sqldb/impl.d.ts.map +1 -0
- package/out/runtime/resolvers/sqldb/impl.js +300 -0
- package/out/runtime/resolvers/sqldb/impl.js.map +1 -0
- package/out/runtime/state.js +83 -0
- package/out/runtime/state.js.map +1 -0
- package/out/runtime/util.d.ts +43 -0
- package/out/runtime/util.d.ts.map +1 -0
- package/out/runtime/util.js +447 -0
- package/out/runtime/util.js.map +1 -0
- package/out/setupClassic.d.ts +98 -0
- package/out/setupClassic.d.ts.map +1 -0
- package/out/setupClassic.js +38 -0
- package/out/setupClassic.js.map +1 -0
- package/out/setupCommon.d.ts +2 -0
- package/out/setupCommon.d.ts.map +1 -0
- package/out/setupCommon.js +33 -0
- package/out/setupCommon.js.map +1 -0
- package/out/setupExtended.d.ts +40 -0
- package/out/setupExtended.d.ts.map +1 -0
- package/out/setupExtended.js +67 -0
- package/out/setupExtended.js.map +1 -0
- package/out/syntaxes/agentlang.monarch.d.ts +77 -0
- package/out/syntaxes/agentlang.monarch.d.ts.map +1 -0
- package/out/syntaxes/agentlang.monarch.js +31 -0
- package/out/syntaxes/agentlang.monarch.js.map +1 -0
- package/out/utils/fs/index.d.ts +14 -0
- package/out/utils/fs/index.d.ts.map +1 -0
- package/out/utils/fs/index.js +26 -0
- package/out/utils/fs/index.js.map +1 -0
- package/out/utils/fs/interfaces.d.ts +105 -0
- package/out/utils/fs/interfaces.d.ts.map +1 -0
- package/out/utils/fs/interfaces.js +5 -0
- package/out/utils/fs/interfaces.js.map +1 -0
- package/out/utils/fs/lightning-fs.d.ts +116 -0
- package/out/utils/fs/lightning-fs.d.ts.map +1 -0
- package/out/utils/fs/lightning-fs.js +243 -0
- package/out/utils/fs/lightning-fs.js.map +1 -0
- package/out/utils/fs/node-fs.d.ts +93 -0
- package/out/utils/fs/node-fs.d.ts.map +1 -0
- package/out/utils/fs/node-fs.js +169 -0
- package/out/utils/fs/node-fs.js.map +1 -0
- package/out/utils/fs-utils.d.ts +153 -0
- package/out/utils/fs-utils.d.ts.map +1 -0
- package/out/utils/fs-utils.js +271 -0
- package/out/utils/fs-utils.js.map +1 -0
- package/out/utils/runtime.d.ts +36 -0
- package/out/utils/runtime.d.ts.map +1 -0
- package/out/utils/runtime.js +39 -0
- package/out/utils/runtime.js.map +1 -0
- package/package.json +155 -0
- package/src/api/http.ts +361 -0
- package/src/cli/cli-util.ts +18 -0
- package/src/cli/main.ts +146 -0
- package/src/extension/main.ts +51 -0
- package/src/language/agentlang-module.ts +75 -0
- package/src/language/agentlang-validator.ts +60 -0
- package/src/language/agentlang.langium +178 -0
- package/src/language/generated/ast.ts +1698 -0
- package/src/language/generated/grammar.ts +4477 -0
- package/src/language/generated/module.ts +25 -0
- package/src/language/main-browser.ts +19 -0
- package/src/language/main.ts +13 -0
- package/src/language/parser.ts +329 -0
- package/src/language/syntax.ts +646 -0
- package/src/runtime/agents/common.ts +177 -0
- package/src/runtime/agents/impl/openai.ts +19 -0
- package/src/runtime/agents/provider.ts +58 -0
- package/src/runtime/agents/registry.ts +9 -0
- package/src/runtime/auth/cognito.ts +225 -0
- package/src/runtime/auth/defs.ts +33 -0
- package/src/runtime/auth/interface.ts +31 -0
- package/src/runtime/defs.ts +33 -0
- package/src/runtime/interpreter.ts +1352 -0
- package/src/runtime/loader.ts +450 -0
- package/src/runtime/logger.ts +51 -0
- package/src/runtime/module.ts +2188 -0
- package/src/runtime/modules/ai.ts +257 -0
- package/src/runtime/modules/auth.ts +489 -0
- package/src/runtime/modules/core.ts +95 -0
- package/src/runtime/relgraph.ts +195 -0
- package/src/runtime/resolvers/interface.ts +160 -0
- package/src/runtime/resolvers/registry.ts +30 -0
- package/src/runtime/resolvers/sqldb/database.ts +823 -0
- package/src/runtime/resolvers/sqldb/dbutil.ts +257 -0
- package/src/runtime/resolvers/sqldb/impl.ts +471 -0
- package/src/runtime/state.ts +87 -0
- package/src/runtime/util.ts +513 -0
- package/src/setupClassic.ts +43 -0
- package/src/setupCommon.ts +33 -0
- package/src/setupExtended.ts +79 -0
- package/src/syntaxes/agentlang.monarch.ts +31 -0
- package/src/utils/fs/index.ts +28 -0
- package/src/utils/fs/interfaces.ts +118 -0
- package/src/utils/fs/lightning-fs.ts +284 -0
- package/src/utils/fs/node-fs.ts +185 -0
- package/src/utils/fs-utils.ts +304 -0
- package/src/utils/runtime.ts +43 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fetchModule,
|
|
3
|
+
getUserModuleNames,
|
|
4
|
+
Relationship,
|
|
5
|
+
RelationshipNode,
|
|
6
|
+
Module,
|
|
7
|
+
} from './module.js';
|
|
8
|
+
import { DefaultModuleName, Path } from './util.js';
|
|
9
|
+
|
|
10
|
+
export type RelationshipGraphNode = {
|
|
11
|
+
entity: Path;
|
|
12
|
+
edges: RelationshipGraphEdge[];
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type RelationshipGraphEdge = {
|
|
16
|
+
relationship: Relationship;
|
|
17
|
+
node: RelationshipGraphNode;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type GraphEdgeEntry = {
|
|
21
|
+
relationship: string;
|
|
22
|
+
type: 'contains' | 'between';
|
|
23
|
+
to: object;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function asEdgeEntry(rge: RelationshipGraphEdge): GraphEdgeEntry {
|
|
27
|
+
const nm: Map<string, any> = new Map();
|
|
28
|
+
nm.set(rge.node.entity.asFqName(), rge.node.edges.map(asEdgeEntry));
|
|
29
|
+
const e: GraphEdgeEntry = {
|
|
30
|
+
relationship: rge.relationship.getFqName(),
|
|
31
|
+
type: rge.relationship.isContains() ? 'contains' : 'between',
|
|
32
|
+
to: Object.fromEntries(nm),
|
|
33
|
+
};
|
|
34
|
+
return e;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class RelationshipGraph {
|
|
38
|
+
nodes: RelationshipGraphNode[];
|
|
39
|
+
|
|
40
|
+
constructor(nodes: Array<RelationshipGraphNode>) {
|
|
41
|
+
this.nodes = nodes;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
getRoots(): RelationshipGraphNode[] {
|
|
45
|
+
return this.nodes;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
asObject(): object {
|
|
49
|
+
const result: Map<string, any> = new Map();
|
|
50
|
+
this.nodes.forEach((node: RelationshipGraphNode) => {
|
|
51
|
+
result.set(node.entity.asFqName(), node.edges.map(asEdgeEntry));
|
|
52
|
+
});
|
|
53
|
+
return Object.fromEntries(result);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private walkEdges(
|
|
57
|
+
node: RelationshipGraphNode,
|
|
58
|
+
onNode: Function,
|
|
59
|
+
onContainsRelationship: Function,
|
|
60
|
+
onBetweenRelationship: Function
|
|
61
|
+
) {
|
|
62
|
+
const n = node.entity.asFqName();
|
|
63
|
+
onNode(n, node.edges);
|
|
64
|
+
node.edges.forEach((edge: RelationshipGraphEdge) => {
|
|
65
|
+
const rf: Function = edge.relationship.isContains()
|
|
66
|
+
? onContainsRelationship
|
|
67
|
+
: onBetweenRelationship;
|
|
68
|
+
rf(n, edge.node.entity.asFqName(), edge.relationship);
|
|
69
|
+
this.walkEdges(edge.node, onNode, onContainsRelationship, onBetweenRelationship);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
walk(onNode: Function, onContainsRelationship: Function, onBetweenRelationship: Function) {
|
|
74
|
+
this.nodes.forEach((node: RelationshipGraphNode) => {
|
|
75
|
+
this.walkEdges(node, onNode, onContainsRelationship, onBetweenRelationship);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const NullEdge: Array<RelationshipGraphEdge> = [];
|
|
81
|
+
const EmptyGraph: RelationshipGraph = new RelationshipGraph(new Array<RelationshipGraphNode>());
|
|
82
|
+
|
|
83
|
+
export function buildGraph(moduleName: string): RelationshipGraph {
|
|
84
|
+
if (moduleName == DefaultModuleName) return EmptyGraph;
|
|
85
|
+
const rootEnts: Set<string> = new Set();
|
|
86
|
+
const inRels: Set<string> = new Set();
|
|
87
|
+
const nodes: Array<RelationshipGraphNode> = [];
|
|
88
|
+
let localMod: Module | undefined;
|
|
89
|
+
getUserModuleNames().forEach((n: string) => {
|
|
90
|
+
const m: Module = fetchModule(n);
|
|
91
|
+
if (n == moduleName) localMod = m;
|
|
92
|
+
const rels: Relationship[] = m.getRelationshipEntries();
|
|
93
|
+
rels.forEach((re: Relationship) => {
|
|
94
|
+
const n1: RelationshipNode = re.parentNode();
|
|
95
|
+
const n2: RelationshipNode = re.childNode();
|
|
96
|
+
if (n1.path.getModuleName() == moduleName) {
|
|
97
|
+
const nn: string = n1.path.getEntryName();
|
|
98
|
+
if (!inRels.has(nn)) rootEnts.add(nn);
|
|
99
|
+
if (n2.path.getModuleName() == moduleName) {
|
|
100
|
+
const en: string = n2.path.getEntryName();
|
|
101
|
+
if (rootEnts.has(en)) {
|
|
102
|
+
rootEnts.delete(en);
|
|
103
|
+
}
|
|
104
|
+
if (re.isContains()) inRels.add(en);
|
|
105
|
+
}
|
|
106
|
+
const node: RelationshipGraphNode = forceFindNode(nodes, n1.path);
|
|
107
|
+
connectEdge(node, re);
|
|
108
|
+
} else if (n2.path.getModuleName() == moduleName) {
|
|
109
|
+
const en: string = n2.path.getEntryName();
|
|
110
|
+
inRels.add(en);
|
|
111
|
+
const node: RelationshipGraphNode = forceFindNode(nodes, n1.path);
|
|
112
|
+
connectEdge(node, re);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
if (localMod == undefined) {
|
|
117
|
+
throw new Error(`Failed to find module ${moduleName}`);
|
|
118
|
+
}
|
|
119
|
+
const remEnts: Set<string> = new Set();
|
|
120
|
+
const entityNames = localMod.getEntityNames();
|
|
121
|
+
for (const name of entityNames) {
|
|
122
|
+
if (!inRels.has(name)) {
|
|
123
|
+
remEnts.add(name);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
remEnts.forEach((n: string) => {
|
|
127
|
+
if (!rootEnts.has(n)) {
|
|
128
|
+
const rn: RelationshipGraphNode = {
|
|
129
|
+
entity: new Path(moduleName, n),
|
|
130
|
+
edges: NullEdge,
|
|
131
|
+
};
|
|
132
|
+
nodes.push(rn);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
return new RelationshipGraph(nodes);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function forceFindNode(nodes: Array<RelationshipGraphNode>, path: Path) {
|
|
139
|
+
for (let i = 0; i < nodes.length; ++i) {
|
|
140
|
+
const n: RelationshipGraphNode = nodes[i];
|
|
141
|
+
if (n.entity.equals(path)) {
|
|
142
|
+
return n;
|
|
143
|
+
} else {
|
|
144
|
+
const n0: RelationshipGraphNode | undefined = findNodeInEdges(n.edges, path);
|
|
145
|
+
if (n0) return n0;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const n: RelationshipGraphNode = {
|
|
149
|
+
entity: path,
|
|
150
|
+
edges: NullEdge,
|
|
151
|
+
};
|
|
152
|
+
nodes.push(n);
|
|
153
|
+
return n;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function findNodeInEdges(
|
|
157
|
+
edges: Array<RelationshipGraphEdge>,
|
|
158
|
+
path: Path
|
|
159
|
+
): RelationshipGraphNode | undefined {
|
|
160
|
+
for (let i = 0; i < edges.length; ++i) {
|
|
161
|
+
const e: RelationshipGraphEdge = edges[i];
|
|
162
|
+
if (e.node.entity.equals(path)) {
|
|
163
|
+
return e.node;
|
|
164
|
+
}
|
|
165
|
+
const r: RelationshipGraphNode | undefined = findNodeInEdges(e.node.edges, path);
|
|
166
|
+
if (r) return r;
|
|
167
|
+
}
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function connectEdge(node: RelationshipGraphNode, re: Relationship) {
|
|
172
|
+
const cn: RelationshipNode = re.childNode();
|
|
173
|
+
const n: RelationshipGraphNode = {
|
|
174
|
+
entity: cn.path,
|
|
175
|
+
edges: NullEdge,
|
|
176
|
+
};
|
|
177
|
+
const e: RelationshipGraphEdge = {
|
|
178
|
+
relationship: re,
|
|
179
|
+
node: n,
|
|
180
|
+
};
|
|
181
|
+
if (node.edges == NullEdge) {
|
|
182
|
+
node.edges = new Array<RelationshipGraphEdge>();
|
|
183
|
+
}
|
|
184
|
+
node.edges.push(e);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function findEdgeForRelationship(
|
|
188
|
+
relName: string,
|
|
189
|
+
moduleName: string,
|
|
190
|
+
edges: RelationshipGraphEdge[]
|
|
191
|
+
): RelationshipGraphEdge | undefined {
|
|
192
|
+
return edges.find((v: RelationshipGraphEdge) => {
|
|
193
|
+
return v.relationship.moduleName == moduleName && v.relationship.name == relName;
|
|
194
|
+
});
|
|
195
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { Instance, InstanceAttributes, Relationship } from '../module.js';
|
|
2
|
+
|
|
3
|
+
export class ResolverAuthInfo {
|
|
4
|
+
userId: string;
|
|
5
|
+
readForUpdate: boolean = false;
|
|
6
|
+
readForDelete: boolean = false;
|
|
7
|
+
|
|
8
|
+
constructor(userId: string, readForUpdate?: boolean, readForDelete?: boolean) {
|
|
9
|
+
this.userId = userId;
|
|
10
|
+
if (readForUpdate != undefined) this.readForUpdate = readForUpdate;
|
|
11
|
+
if (readForDelete != undefined) this.readForDelete = readForDelete;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const DefaultAuthInfo = new ResolverAuthInfo(
|
|
16
|
+
// This user-id is only for testing, per-session user-id needs to be set from
|
|
17
|
+
// the HTTP layer.
|
|
18
|
+
'9459a305-5ee6-415d-986d-caaf6d6e2828'
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export type JoinInfo = {
|
|
22
|
+
relationship: Relationship;
|
|
23
|
+
queryInstance: Instance;
|
|
24
|
+
subJoins: JoinInfo[] | undefined;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export class Resolver {
|
|
28
|
+
protected authInfo: ResolverAuthInfo = DefaultAuthInfo;
|
|
29
|
+
protected userData: any;
|
|
30
|
+
protected name: string = 'default';
|
|
31
|
+
|
|
32
|
+
static Default = new Resolver();
|
|
33
|
+
|
|
34
|
+
public setAuthInfo(authInfo: ResolverAuthInfo): Resolver {
|
|
35
|
+
this.authInfo = authInfo;
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public setUserData(userData: any): Resolver {
|
|
40
|
+
this.userData = userData;
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public getUserData(): any {
|
|
45
|
+
return this.userData;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public getName(): string {
|
|
49
|
+
return this.name;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private notImpl(method: string) {
|
|
53
|
+
throw new Error(`Resolver method ${method} not implemented`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public onSetPath(moduleName: string, entryName: string): any {
|
|
57
|
+
this.notImpl(`onSetPath(${moduleName}, ${entryName})`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public async createInstance(inst: Instance): Promise<any> {
|
|
61
|
+
this.notImpl(`createInstance(${inst})`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public async upsertInstance(inst: Instance): Promise<any> {
|
|
65
|
+
return this.notImpl(`upsertInstance(${inst})`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @param {Instance} inst - an Instance with query and update attributes
|
|
70
|
+
* @param {InstanceAttributes} newAttrs - updated attributes to set in instance
|
|
71
|
+
*/
|
|
72
|
+
public async updateInstance(inst: Instance, newAttrs: InstanceAttributes): Promise<any> {
|
|
73
|
+
return this.notImpl(`updateInstance(${inst}, ${newAttrs})`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @param {Instance} inst - an Instance with query attributes
|
|
78
|
+
* @param {boolean} queryAll - if this flag is set, fetch all instances
|
|
79
|
+
*/
|
|
80
|
+
public async queryInstances(inst: Instance, queryAll: boolean): Promise<any> {
|
|
81
|
+
return this.notImpl(`queryInstances(${inst}, ${queryAll})`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Return all instances under the given parent-path.
|
|
86
|
+
* @param {string} parentPath - path of the parent with the relevant relationship name as the last component
|
|
87
|
+
* @param {Instance} inst - child Instance with query attributes
|
|
88
|
+
*/
|
|
89
|
+
public async queryChildInstances(parentPath: string, inst: Instance): Promise<any> {
|
|
90
|
+
return this.notImpl(`queryChildInstances(${parentPath}, ${inst})`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Return all instances connected to connectedInstance via the given between-relationship
|
|
95
|
+
* @param relationship Between relationship
|
|
96
|
+
* @param connectedInstance The instance to traveres the relationship from
|
|
97
|
+
* @param inst Target instance with query attributes
|
|
98
|
+
*/
|
|
99
|
+
public async queryConnectedInstances(
|
|
100
|
+
relationship: Relationship,
|
|
101
|
+
connectedInstance: Instance,
|
|
102
|
+
inst: Instance
|
|
103
|
+
): Promise<any> {
|
|
104
|
+
return this.notImpl(`queryConnectedInstances(${relationship}, ${connectedInstance}, ${inst})`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public async queryByJoin(
|
|
108
|
+
inst: Instance,
|
|
109
|
+
joinsSpec: JoinInfo[],
|
|
110
|
+
intoSpec: Map<string, string>
|
|
111
|
+
): Promise<any> {
|
|
112
|
+
return this.notImpl(`queryByJoin(${inst}, ${joinsSpec}, ${intoSpec})`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @param {Instance} inst - an Instance with query attributes
|
|
117
|
+
*/
|
|
118
|
+
public async deleteInstance(inst: Instance | Instance[], purge: boolean): Promise<any> {
|
|
119
|
+
return this.notImpl(`deleteInstance(${inst}, ${purge})`);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Connect instances via a between relationship
|
|
124
|
+
* @param node1 The main node to connect
|
|
125
|
+
* @param otherNodeOrNodes Nodes to be connected to node1
|
|
126
|
+
* @param relEntry Details of the repationship
|
|
127
|
+
*/
|
|
128
|
+
public async connectInstances(
|
|
129
|
+
node1: Instance,
|
|
130
|
+
otherNodeOrNodes: Instance | Instance[],
|
|
131
|
+
relEntry: Relationship,
|
|
132
|
+
orUpdate: boolean
|
|
133
|
+
): Promise<any> {
|
|
134
|
+
return this.notImpl(
|
|
135
|
+
`connectInstances(${node1}, ${otherNodeOrNodes}, ${relEntry}, ${orUpdate})`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
public async fullTextSearch(
|
|
140
|
+
entryName: string,
|
|
141
|
+
moduleName: string,
|
|
142
|
+
query: string,
|
|
143
|
+
options?: Map<string, any>
|
|
144
|
+
): Promise<any> {
|
|
145
|
+
return this.notImpl(`fullTextSearch(${entryName}, ${moduleName}, ${query}, ${options})`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Return a transactionId
|
|
149
|
+
public async startTransaction(): Promise<any> {
|
|
150
|
+
return this.notImpl('startTransaction()');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
public async commitTransaction(txnId: string): Promise<any> {
|
|
154
|
+
return this.notImpl(`commitTransaction(${txnId})`);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public async rollbackTransaction(txtIn: string): Promise<any> {
|
|
158
|
+
return this.notImpl(`rollbackTransaction(${txtIn})`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Resolver } from './interface.js';
|
|
2
|
+
|
|
3
|
+
type MakeResolver = () => Resolver;
|
|
4
|
+
const resolverDb: Map<string, MakeResolver> = new Map<string, MakeResolver>();
|
|
5
|
+
const resolverPathMappings: Map<string, string> = new Map<string, string>();
|
|
6
|
+
|
|
7
|
+
export function registerResolver(name: string, r: MakeResolver) {
|
|
8
|
+
resolverDb.set(name, r);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function setResolver(fqEntryName: string, resolverName: string) {
|
|
12
|
+
if (resolverDb.has(resolverName)) {
|
|
13
|
+
resolverPathMappings.set(fqEntryName, resolverName);
|
|
14
|
+
} else {
|
|
15
|
+
throw new Error(`Resolver not found - ${resolverName}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getResolverNameForPath(fqEntryName: string): string | undefined {
|
|
20
|
+
return resolverPathMappings.get(fqEntryName);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getResolver(fqEntryName: string): Resolver {
|
|
24
|
+
const resName: string | undefined = resolverPathMappings.get(fqEntryName);
|
|
25
|
+
if (resName != undefined) {
|
|
26
|
+
const f: MakeResolver | undefined = resolverDb.get(resName);
|
|
27
|
+
if (f) return f();
|
|
28
|
+
}
|
|
29
|
+
throw new Error(`No resolver registered for ${fqEntryName}`);
|
|
30
|
+
}
|