@coasys/ad4m 0.8.0-fix
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 +229 -0
- package/jest-setup.ts +1 -0
- package/jest.config.js +6 -0
- package/jsdoc.json +28 -0
- package/lib/index.cjs +8165 -0
- package/lib/index.js +8130 -0
- package/lib/shims/reflect-metadata.d.ts +0 -0
- package/lib/shims/reflect-metadata.js +0 -0
- package/lib/shims/type-graphql.d.ts +32 -0
- package/lib/shims/type-graphql.js +70 -0
- package/lib/src/Ad4mClient.d.ts +26 -0
- package/lib/src/Ad4mClient.js +66 -0
- package/lib/src/Address.d.ts +1 -0
- package/lib/src/Address.js +1 -0
- package/lib/src/DID.d.ts +1 -0
- package/lib/src/DID.js +1 -0
- package/lib/src/Exception.d.ts +6 -0
- package/lib/src/Exception.js +7 -0
- package/lib/src/Literal.d.ts +7 -0
- package/lib/src/Literal.js +76 -0
- package/lib/src/PubSub.d.ts +14 -0
- package/lib/src/PubSub.js +14 -0
- package/lib/src/SmartLiteral.d.ts +12 -0
- package/lib/src/SmartLiteral.js +74 -0
- package/lib/src/agent/Agent.d.ts +104 -0
- package/lib/src/agent/Agent.js +337 -0
- package/lib/src/agent/AgentClient.d.ts +57 -0
- package/lib/src/agent/AgentClient.js +431 -0
- package/lib/src/agent/AgentResolver.d.ts +30 -0
- package/lib/src/agent/AgentResolver.js +325 -0
- package/lib/src/agent/AgentStatus.d.ts +8 -0
- package/lib/src/agent/AgentStatus.js +61 -0
- package/lib/src/buildSchema.d.ts +1 -0
- package/lib/src/buildSchema.js +36 -0
- package/lib/src/expression/Expression.d.ts +28 -0
- package/lib/src/expression/Expression.js +143 -0
- package/lib/src/expression/ExpressionClient.d.ts +13 -0
- package/lib/src/expression/ExpressionClient.js +102 -0
- package/lib/src/expression/ExpressionRef.d.ts +9 -0
- package/lib/src/expression/ExpressionRef.js +67 -0
- package/lib/src/expression/ExpressionResolver.d.ts +10 -0
- package/lib/src/expression/ExpressionResolver.js +106 -0
- package/lib/src/index.d.ts +30 -0
- package/lib/src/index.js +30 -0
- package/lib/src/jestSetup.d.ts +1 -0
- package/lib/src/jestSetup.js +1 -0
- package/lib/src/language/Icon.d.ts +4 -0
- package/lib/src/language/Icon.js +24 -0
- package/lib/src/language/Language.d.ts +195 -0
- package/lib/src/language/Language.js +79 -0
- package/lib/src/language/LanguageClient.d.ts +17 -0
- package/lib/src/language/LanguageClient.js +137 -0
- package/lib/src/language/LanguageContext.d.ts +37 -0
- package/lib/src/language/LanguageContext.js +2 -0
- package/lib/src/language/LanguageHandle.d.ts +9 -0
- package/lib/src/language/LanguageHandle.js +41 -0
- package/lib/src/language/LanguageMeta.d.ts +35 -0
- package/lib/src/language/LanguageMeta.js +89 -0
- package/lib/src/language/LanguageRef.d.ts +6 -0
- package/lib/src/language/LanguageRef.js +30 -0
- package/lib/src/language/LanguageResolver.d.ts +19 -0
- package/lib/src/language/LanguageResolver.js +143 -0
- package/lib/src/links/Links.d.ts +39 -0
- package/lib/src/links/Links.js +148 -0
- package/lib/src/links/Links.test.d.ts +1 -0
- package/lib/src/links/Links.test.js +33 -0
- package/lib/src/neighbourhood/Neighbourhood.d.ts +10 -0
- package/lib/src/neighbourhood/Neighbourhood.js +38 -0
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +25 -0
- package/lib/src/neighbourhood/NeighbourhoodClient.js +256 -0
- package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +19 -0
- package/lib/src/neighbourhood/NeighbourhoodProxy.js +54 -0
- package/lib/src/neighbourhood/NeighbourhoodResolver.d.ts +24 -0
- package/lib/src/neighbourhood/NeighbourhoodResolver.js +180 -0
- package/lib/src/perspectives/LinkQuery.d.ts +11 -0
- package/lib/src/perspectives/LinkQuery.js +80 -0
- package/lib/src/perspectives/Perspective.d.ts +38 -0
- package/lib/src/perspectives/Perspective.js +144 -0
- package/lib/src/perspectives/Perspective.test.d.ts +1 -0
- package/lib/src/perspectives/Perspective.test.js +20 -0
- package/lib/src/perspectives/PerspectiveClient.d.ts +54 -0
- package/lib/src/perspectives/PerspectiveClient.js +410 -0
- package/lib/src/perspectives/PerspectiveDiff.d.ts +9 -0
- package/lib/src/perspectives/PerspectiveDiff.js +33 -0
- package/lib/src/perspectives/PerspectiveHandle.d.ts +16 -0
- package/lib/src/perspectives/PerspectiveHandle.js +59 -0
- package/lib/src/perspectives/PerspectiveProxy.d.ts +178 -0
- package/lib/src/perspectives/PerspectiveProxy.js +540 -0
- package/lib/src/perspectives/PerspectiveResolver.d.ts +37 -0
- package/lib/src/perspectives/PerspectiveResolver.js +362 -0
- package/lib/src/runtime/RuntimeClient.d.ts +33 -0
- package/lib/src/runtime/RuntimeClient.js +263 -0
- package/lib/src/runtime/RuntimeResolver.d.ts +47 -0
- package/lib/src/runtime/RuntimeResolver.js +328 -0
- package/lib/src/schema.gql +382 -0
- package/lib/src/subject/SDNADecorators.d.ts +45 -0
- package/lib/src/subject/SDNADecorators.js +250 -0
- package/lib/src/subject/Subject.d.ts +7 -0
- package/lib/src/subject/Subject.js +160 -0
- package/lib/src/subject/SubjectEntity.d.ts +31 -0
- package/lib/src/subject/SubjectEntity.js +250 -0
- package/lib/src/subject/util.d.ts +12 -0
- package/lib/src/subject/util.js +73 -0
- package/lib/src/typeDefs.d.ts +1 -0
- package/lib/src/typeDefs.js +379 -0
- package/lib/src/unwrapApolloResult.d.ts +2 -0
- package/lib/src/unwrapApolloResult.js +12 -0
- package/lib/src/utils.d.ts +2 -0
- package/lib/src/utils.js +21 -0
- package/package.json +61 -0
- package/rollup.config.js +27 -0
- package/shims/reflect-metadata.ts +0 -0
- package/shims/type-graphql.ts +75 -0
- package/src/Ad4mClient.test.ts +1085 -0
- package/src/Ad4mClient.ts +63 -0
- package/src/Address.ts +1 -0
- package/src/DID.ts +1 -0
- package/src/Exception.ts +6 -0
- package/src/Literal.test.ts +31 -0
- package/src/Literal.ts +81 -0
- package/src/PubSub.ts +14 -0
- package/src/SmartLiteral.ts +75 -0
- package/src/agent/Agent.ts +293 -0
- package/src/agent/AgentClient.ts +531 -0
- package/src/agent/AgentResolver.ts +263 -0
- package/src/agent/AgentStatus.ts +44 -0
- package/src/buildSchema.ts +41 -0
- package/src/expression/Expression.ts +99 -0
- package/src/expression/ExpressionClient.ts +99 -0
- package/src/expression/ExpressionRef.ts +63 -0
- package/src/expression/ExpressionResolver.ts +64 -0
- package/src/index.ts +30 -0
- package/src/jestSetup.ts +1 -0
- package/src/language/Icon.ts +11 -0
- package/src/language/Language.ts +266 -0
- package/src/language/LanguageClient.ts +160 -0
- package/src/language/LanguageContext.ts +37 -0
- package/src/language/LanguageHandle.ts +23 -0
- package/src/language/LanguageMeta.ts +70 -0
- package/src/language/LanguageRef.ts +18 -0
- package/src/language/LanguageResolver.ts +98 -0
- package/src/links/Links.test.ts +40 -0
- package/src/links/Links.ts +107 -0
- package/src/neighbourhood/Neighbourhood.ts +22 -0
- package/src/neighbourhood/NeighbourhoodClient.ts +276 -0
- package/src/neighbourhood/NeighbourhoodProxy.ts +58 -0
- package/src/neighbourhood/NeighbourhoodResolver.ts +100 -0
- package/src/perspectives/LinkQuery.ts +66 -0
- package/src/perspectives/Perspective.test.ts +23 -0
- package/src/perspectives/Perspective.ts +118 -0
- package/src/perspectives/PerspectiveClient.ts +444 -0
- package/src/perspectives/PerspectiveDiff.ts +15 -0
- package/src/perspectives/PerspectiveHandle.ts +39 -0
- package/src/perspectives/PerspectiveProxy.ts +611 -0
- package/src/perspectives/PerspectiveResolver.ts +220 -0
- package/src/runtime/RuntimeClient.ts +283 -0
- package/src/runtime/RuntimeResolver.ts +193 -0
- package/src/subject/SDNADecorators.ts +334 -0
- package/src/subject/Subject.ts +153 -0
- package/src/subject/SubjectEntity.ts +292 -0
- package/src/subject/util.ts +85 -0
- package/src/typeDefs.ts +6 -0
- package/src/unwrapApolloResult.ts +14 -0
- package/src/utils.ts +25 -0
- package/tsconfig-browser.json +82 -0
- package/tsconfig.json +80 -0
- package/yarn-error.log +22814 -0
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { Literal } from "../Literal";
|
|
2
|
+
import { Link } from "../links/Links";
|
|
3
|
+
import { PerspectiveProxy } from "../perspectives/PerspectiveProxy";
|
|
4
|
+
import { makeRandomPrologAtom } from "./SDNADecorators";
|
|
5
|
+
import { singularToPlural } from "./util";
|
|
6
|
+
|
|
7
|
+
export type QueryPartialEntity<T> = {
|
|
8
|
+
[P in keyof T]?: T[P] | (() => string);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export class SubjectEntity {
|
|
13
|
+
#baseExpression: string;
|
|
14
|
+
#subjectClass: string;
|
|
15
|
+
#source: string;
|
|
16
|
+
#perspective: PerspectiveProxy
|
|
17
|
+
author: string;
|
|
18
|
+
timestamp: string;
|
|
19
|
+
|
|
20
|
+
constructor(perspective: PerspectiveProxy, baseExpression?: string, source?: string) {
|
|
21
|
+
this.#baseExpression = baseExpression ? baseExpression : Literal.from(makeRandomPrologAtom(24)).toUrl();
|
|
22
|
+
this.#perspective = perspective;
|
|
23
|
+
this.#source = source || "ad4m://self";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get baseExpression() {
|
|
27
|
+
return this.#baseExpression
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private async getData(id?: string) {
|
|
31
|
+
const tempId = id ?? this.#baseExpression;
|
|
32
|
+
let isInstance = await this.#perspective.isSubjectInstance(tempId, this.#subjectClass)
|
|
33
|
+
if (!isInstance) {
|
|
34
|
+
throw `Not a valid subject instance of ${this.#subjectClass} for ${tempId}`
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let results = await this.#perspective.infer(`subject_class("${this.#subjectClass}", C), property(C, Property)`)
|
|
38
|
+
let properties = results.map(result => result.Property)
|
|
39
|
+
|
|
40
|
+
for (let p of properties) {
|
|
41
|
+
const resolveExpressionURI = await this.#perspective.infer(`subject_class("${this.#subjectClass}", C), property_resolve(C, "${p}")`)
|
|
42
|
+
const getProperty = async () => {
|
|
43
|
+
let results = await this.#perspective.infer(`subject_class("${this.#subjectClass}", C), property_getter(C, "${tempId}", "${p}", Value)`)
|
|
44
|
+
if (results && results.length > 0) {
|
|
45
|
+
let expressionURI = results[0].Value
|
|
46
|
+
if (resolveExpressionURI) {
|
|
47
|
+
try {
|
|
48
|
+
const expression = await this.#perspective.getExpression(expressionURI)
|
|
49
|
+
try {
|
|
50
|
+
return JSON.parse(expression.data)
|
|
51
|
+
} catch (e) {
|
|
52
|
+
return expression.data
|
|
53
|
+
}
|
|
54
|
+
} catch (err) {
|
|
55
|
+
return expressionURI
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
return expressionURI
|
|
59
|
+
}
|
|
60
|
+
} else if (results) {
|
|
61
|
+
return results
|
|
62
|
+
} else {
|
|
63
|
+
return undefined
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
this[p] = await getProperty()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let results2 = await this.#perspective.infer(`subject_class("${this.#subjectClass}", C), collection(C, Collection)`)
|
|
71
|
+
if (!results2) results2 = []
|
|
72
|
+
let collections = results2.map(result => result.Collection)
|
|
73
|
+
|
|
74
|
+
for (let c of collections) {
|
|
75
|
+
const getProperty = async () => {
|
|
76
|
+
let results = await this.#perspective.infer(`subject_class("${this.#subjectClass}", C), collection_getter(C, "${tempId}", "${c}", Value)`)
|
|
77
|
+
if (results && results.length > 0 && results[0].Value) {
|
|
78
|
+
return eval(results[0].Value)
|
|
79
|
+
} else {
|
|
80
|
+
return []
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
this[c] = await getProperty()
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
this.#baseExpression = tempId;
|
|
88
|
+
|
|
89
|
+
return this
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private async setProperty(key: string, value: any) {
|
|
93
|
+
const setters = await this.#perspective.infer(`subject_class("${this.#subjectClass}", C), property_setter(C, "${key}", Setter)`)
|
|
94
|
+
if (setters && setters.length > 0) {
|
|
95
|
+
const actions = eval(setters[0].Setter)
|
|
96
|
+
const resolveLanguageResults = await this.#perspective.infer(`subject_class("${this.#subjectClass}", C), property_resolve_language(C, "${key}", Language)`)
|
|
97
|
+
let resolveLanguage
|
|
98
|
+
if (resolveLanguageResults && resolveLanguageResults.length > 0) {
|
|
99
|
+
resolveLanguage = resolveLanguageResults[0].Language
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (resolveLanguage) {
|
|
103
|
+
value = await this.#perspective.createExpression(value, resolveLanguage)
|
|
104
|
+
}
|
|
105
|
+
await this.#perspective.executeAction(actions, this.#baseExpression, [{ name: "value", value }])
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private async setCollectionSetter(key: string, value: any) {
|
|
110
|
+
let collectionSetters = await this.#perspective.infer(`subject_class("${this.#subjectClass}", C), collection_setter(C, "${singularToPlural(key)}", Setter)`)
|
|
111
|
+
if (!collectionSetters) collectionSetters = []
|
|
112
|
+
|
|
113
|
+
if (collectionSetters.length > 0) {
|
|
114
|
+
const actions = eval(collectionSetters[0].Setter)
|
|
115
|
+
|
|
116
|
+
if (value) {
|
|
117
|
+
if (Array.isArray(value)) {
|
|
118
|
+
await this.#perspective.executeAction(actions, this.#baseExpression, value.map(v => ({ name: "value", value: v })))
|
|
119
|
+
} else {
|
|
120
|
+
await this.#perspective.executeAction(actions, this.#baseExpression, [{ name: "value", value }])
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private async setCollectionAdder(key: string, value: any) {
|
|
127
|
+
let adders = await this.#perspective.infer(`subject_class("${this.#subjectClass}", C), collection_adder(C, "${singularToPlural(key)}", Adder)`)
|
|
128
|
+
if (!adders) adders = []
|
|
129
|
+
|
|
130
|
+
if (adders.length > 0) {
|
|
131
|
+
const actions = eval(adders[0].Adder)
|
|
132
|
+
if (value) {
|
|
133
|
+
if (Array.isArray(value)) {
|
|
134
|
+
await Promise.all(value.map(v => this.#perspective.executeAction(actions, this.#baseExpression, [{ name: "value", value: v }])))
|
|
135
|
+
} else {
|
|
136
|
+
await this.#perspective.executeAction(actions, this.#baseExpression, [{ name: "value", value }])
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private async setCollectionRemover(key: string, value: any) {
|
|
143
|
+
let removers = await this.#perspective.infer(`subject_class("${this.#subjectClass}", C), collection_remover(C, "${singularToPlural(key)}", Remover)`)
|
|
144
|
+
if (!removers) removers = []
|
|
145
|
+
|
|
146
|
+
if (removers.length > 0) {
|
|
147
|
+
const actions = eval(removers[0].Remover)
|
|
148
|
+
if (value) {
|
|
149
|
+
if (Array.isArray(value)) {
|
|
150
|
+
await Promise.all(value.map(v => this.#perspective.executeAction(actions, this.#baseExpression, [{ name: "value", value: v }])))
|
|
151
|
+
} else {
|
|
152
|
+
await this.#perspective.executeAction(actions, this.#baseExpression, [{ name: "value", value }])
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async save() {
|
|
159
|
+
this.#subjectClass = await this.#perspective.stringOrTemplateObjectToSubjectClass(this)
|
|
160
|
+
|
|
161
|
+
await this.#perspective.createSubject(this, this.#baseExpression);
|
|
162
|
+
|
|
163
|
+
await this.#perspective.add(
|
|
164
|
+
new Link({
|
|
165
|
+
source: this.#source,
|
|
166
|
+
predicate: "ad4m://has_child",
|
|
167
|
+
target: this.baseExpression,
|
|
168
|
+
})
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
await this.update()
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async update() {
|
|
175
|
+
this.#subjectClass = await this.#perspective.stringOrTemplateObjectToSubjectClass(this)
|
|
176
|
+
|
|
177
|
+
const entries = Object.entries(this);
|
|
178
|
+
|
|
179
|
+
for (const [key, value] of entries) {
|
|
180
|
+
if (value) {
|
|
181
|
+
if (value?.action) {
|
|
182
|
+
switch (value.action) {
|
|
183
|
+
case 'setter':
|
|
184
|
+
await this.setCollectionSetter(key, value.value)
|
|
185
|
+
break;
|
|
186
|
+
case "adder":
|
|
187
|
+
await this.setCollectionAdder(key, value.value)
|
|
188
|
+
break;
|
|
189
|
+
case 'remover':
|
|
190
|
+
await this.setCollectionRemover(key, value.value)
|
|
191
|
+
default:
|
|
192
|
+
await this.setCollectionSetter(key, value.value)
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
} else if (Array.isArray(value) && value.length > 0) {
|
|
196
|
+
await this.setCollectionSetter(key, value)
|
|
197
|
+
} else {
|
|
198
|
+
await this.setProperty(key, value);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
await this.getData();
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
async get() {
|
|
207
|
+
this.#subjectClass = await this.#perspective.stringOrTemplateObjectToSubjectClass(this)
|
|
208
|
+
|
|
209
|
+
return await this.getData()
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async delete() {
|
|
213
|
+
await this.#perspective.removeSubject(this, this.#baseExpression);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// TODO: implement simple quering like limit, skip etc.
|
|
217
|
+
static async all(perspective: PerspectiveProxy) {
|
|
218
|
+
let subjectClass = await perspective.stringOrTemplateObjectToSubjectClass(this)
|
|
219
|
+
const proxies = await perspective.getAllSubjectProxies(subjectClass)
|
|
220
|
+
|
|
221
|
+
const instances = []
|
|
222
|
+
|
|
223
|
+
if (proxies) {
|
|
224
|
+
for (const proxy of proxies) {
|
|
225
|
+
// @ts-ignore
|
|
226
|
+
const instance = new this(perspective, proxy.X)
|
|
227
|
+
instances.push(await instance.get())
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return instances;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return []
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
static async query(perspective: PerspectiveProxy, query?: SubjectEntityQueryParam) {
|
|
237
|
+
const source = query?.source || "ad4m://self";
|
|
238
|
+
let subjectClass = await perspective.stringOrTemplateObjectToSubjectClass(this)
|
|
239
|
+
|
|
240
|
+
let res = [];
|
|
241
|
+
|
|
242
|
+
if (query) {
|
|
243
|
+
try {
|
|
244
|
+
const queryResponse = (await perspective.infer(`findall([Timestamp, Base], (subject_class("${subjectClass}", C), instance(C, Base), link("${source}", Predicate, Base, Timestamp, Author)), AllData), sort(AllData, SortedData), length(SortedData, DataLength).`))[0]
|
|
245
|
+
|
|
246
|
+
if (queryResponse.DataLength >= query.size) {
|
|
247
|
+
const mainQuery = `findall([Timestamp, Base], (subject_class("${subjectClass}", C), instance(C, Base), link("${source}", Predicate, Base, Timestamp, Author)), AllData), sort(AllData, SortedData), reverse(SortedData, ReverseSortedData), paginate(ReverseSortedData, ${query.page}, ${query.size}, PageData).`
|
|
248
|
+
|
|
249
|
+
res = await perspective.infer(mainQuery);
|
|
250
|
+
|
|
251
|
+
res = res[0].PageData.map(r => ({
|
|
252
|
+
Base: r[1],
|
|
253
|
+
Timestamp: r[0]
|
|
254
|
+
}))
|
|
255
|
+
} else {
|
|
256
|
+
res = await perspective.infer(
|
|
257
|
+
`subject_class("${subjectClass}", C), instance(C, Base), triple("${source}", Predicate, Base).`
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
} catch (e) {
|
|
261
|
+
console.log("Query failed", e);
|
|
262
|
+
}
|
|
263
|
+
} else {
|
|
264
|
+
res = await perspective.infer(
|
|
265
|
+
`subject_class("${subjectClass}", C), instance(C, Base), triple("${source}", Predicate, Base).`
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (!res) return [];
|
|
270
|
+
|
|
271
|
+
const data = await Promise.all(
|
|
272
|
+
res.map(async (result) => {
|
|
273
|
+
const instance = new this(perspective, result.Base)
|
|
274
|
+
|
|
275
|
+
return await instance.get();
|
|
276
|
+
})
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
return data;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export type SubjectArray<T> = T[] | {
|
|
284
|
+
action: 'setter' | 'adder' | 'remover',
|
|
285
|
+
value: T[]
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export type SubjectEntityQueryParam = {
|
|
289
|
+
source?: string;
|
|
290
|
+
size?: number;
|
|
291
|
+
page?: number;
|
|
292
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export function capitalize(str: string) {
|
|
2
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
// e.g. "name" -> "setName"
|
|
6
|
+
export function propertyNameToSetterName(property: string): string {
|
|
7
|
+
return `set${capitalize(property)}`
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// e.g. "setName" -> "name"
|
|
11
|
+
export function setterNameToPropertyName(setter: string): string {
|
|
12
|
+
return setter.replace("set", "").replace(/^[A-Z]/, (m) => m.toLowerCase())
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function singularToPlural(singular: string): string {
|
|
16
|
+
if(singular.endsWith("y")) {
|
|
17
|
+
return singular.slice(0, -1) + "ies"
|
|
18
|
+
} else {
|
|
19
|
+
return singular + "s"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function pluralToSingular(plural: string): string {
|
|
24
|
+
if(plural.endsWith("ies")) {
|
|
25
|
+
return plural.slice(0, -3) + "y"
|
|
26
|
+
} else if(plural.endsWith("s")) {
|
|
27
|
+
return plural.slice(0, -1)
|
|
28
|
+
} else {
|
|
29
|
+
return plural
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// e.g. "comments" -> "addComment"
|
|
34
|
+
export function collectionToAdderName(collection: string): string {
|
|
35
|
+
return `add${capitalize(pluralToSingular(collection))}`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// e.g. "addEntry" -> "entries"
|
|
39
|
+
export function collectionAdderToName(adderName: string): string {
|
|
40
|
+
let singular = adderName.substring(3)
|
|
41
|
+
let plural = singularToPlural(singular)
|
|
42
|
+
return plural.charAt(0).toLowerCase() + plural.slice(1)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// e.g. "comments" -> "removeComment"
|
|
46
|
+
export function collectionToRemoverName(collection: string): string {
|
|
47
|
+
return `remove${capitalize(pluralToSingular(collection))}`
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// e.g. "removeEntry" -> "entries"
|
|
51
|
+
export function collectionRemoverToName(removerName: string): string {
|
|
52
|
+
let singular = removerName.substring(6)
|
|
53
|
+
let plural = singularToPlural(singular)
|
|
54
|
+
return plural.charAt(0).toLowerCase() + plural.slice(1)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function collectionSetterToName(adderName: string): string {
|
|
58
|
+
let singular = adderName.substring(13)
|
|
59
|
+
let plural = singularToPlural(singular)
|
|
60
|
+
return plural.charAt(0).toLowerCase() + plural.slice(1)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// e.g. "comments" -> "addComment"
|
|
64
|
+
export function collectionToSetterName(collection: string): string {
|
|
65
|
+
return `setCollection${capitalize(pluralToSingular(collection))}`
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
export function stringifyObjectLiteral(obj) {
|
|
70
|
+
if(Array.isArray(obj)) {
|
|
71
|
+
//@ts-ignore
|
|
72
|
+
return `[${obj.map(stringifyObjectLiteral).join(", ")}]`
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const keys = Object.keys(obj);
|
|
76
|
+
const stringifiedPairs = [];
|
|
77
|
+
|
|
78
|
+
for (const key of keys) {
|
|
79
|
+
const valueString = JSON.stringify(obj[key]);
|
|
80
|
+
const keyValuePairString = `${key}: ${valueString}`;
|
|
81
|
+
stringifiedPairs.push(keyValuePairString);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return `{${stringifiedPairs.join(', ')}}`;
|
|
85
|
+
}
|
package/src/typeDefs.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// This is just a placeholder for the TS version of the index file.
|
|
2
|
+
// buildSchema over-writes lib/typeDefs.js after tsc has run.
|
|
3
|
+
// This way lib/index.js can stay the compiled version of index.ts,
|
|
4
|
+
// where index.ts imports this file...
|
|
5
|
+
|
|
6
|
+
export const typeDefsString = ""
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ApolloQueryResult, FetchResult } from "@apollo/client/core"
|
|
2
|
+
|
|
3
|
+
export default function unwrapApolloResult(result: ApolloQueryResult<any> | FetchResult<any>) {
|
|
4
|
+
//console.debug('GQL result:', result)
|
|
5
|
+
//@ts-ignore
|
|
6
|
+
if(result.error) {
|
|
7
|
+
//@ts-ignore
|
|
8
|
+
throw result.error
|
|
9
|
+
}
|
|
10
|
+
if(result.errors) {
|
|
11
|
+
throw result.errors
|
|
12
|
+
}
|
|
13
|
+
return result.data
|
|
14
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export function formatList(list) {
|
|
2
|
+
if (!list?.length) {
|
|
3
|
+
return "";
|
|
4
|
+
}
|
|
5
|
+
if (list.length === 1) {
|
|
6
|
+
return list.toString();
|
|
7
|
+
}
|
|
8
|
+
if (list.length === 2) {
|
|
9
|
+
return list.join(' and ');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return list.slice(0, -1).join(', ') + ', and ' + list.slice(-1);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function capSentence(cap) {
|
|
16
|
+
const can = cap.can.includes("*") ? ["READ", "WRITE", "UPDATE"] : cap.can;
|
|
17
|
+
const domain = cap.with.domain === "*" ? "" : cap.with.domain;
|
|
18
|
+
const pointers = cap.with.pointers.includes("*")
|
|
19
|
+
? ["all AD4M data"]
|
|
20
|
+
: cap.with.pointers;
|
|
21
|
+
|
|
22
|
+
return `${formatList(
|
|
23
|
+
can
|
|
24
|
+
)} your ${domain} actions, with access to ${formatList(pointers)}`;
|
|
25
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"include": ["./src/**/*.ts"],
|
|
3
|
+
"exclude": ["./src/buildSchema.ts", "./src/Ad4mClient.test.ts"],
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"baseUrl": ".",
|
|
6
|
+
"paths": {
|
|
7
|
+
"type-graphql": ["./shims/type-graphql.ts"],
|
|
8
|
+
"reflect-metadata": ["./shims/reflect-metadata.ts"]
|
|
9
|
+
},
|
|
10
|
+
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
|
11
|
+
|
|
12
|
+
/* Basic Options */
|
|
13
|
+
// "incremental": true, /* Enable incremental compilation */
|
|
14
|
+
"target": "es2018", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
|
15
|
+
"lib": ["es2018", "esnext.asynciterable"],
|
|
16
|
+
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
|
17
|
+
// "lib": [], /* Specify library files to be included in the compilation. */
|
|
18
|
+
// "allowJs": true, /* Allow javascript files to be compiled. */
|
|
19
|
+
// "checkJs": true, /* Report errors in .js files. */
|
|
20
|
+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
|
|
21
|
+
"declaration": true, /* Generates corresponding '.d.ts' file. */
|
|
22
|
+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
|
23
|
+
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
|
24
|
+
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
25
|
+
"rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
|
26
|
+
"outDir": "./lib",
|
|
27
|
+
// "composite": true, /* Enable project compilation */
|
|
28
|
+
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
|
29
|
+
// "removeComments": true, /* Do not emit comments to output. */
|
|
30
|
+
// "noEmit": true, /* Do not emit outputs. */
|
|
31
|
+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
|
32
|
+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
|
33
|
+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
|
34
|
+
|
|
35
|
+
/* Strict Type-Checking Options */
|
|
36
|
+
// "strict": true, /* Enable all strict type-checking options. */
|
|
37
|
+
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
|
38
|
+
// "strictNullChecks": true, /* Enable strict null checks. */
|
|
39
|
+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
|
40
|
+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
|
41
|
+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
|
42
|
+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
|
43
|
+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
|
44
|
+
|
|
45
|
+
/* Additional Checks */
|
|
46
|
+
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
|
47
|
+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
|
48
|
+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
|
49
|
+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
50
|
+
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
|
51
|
+
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */
|
|
52
|
+
|
|
53
|
+
/* Module Resolution Options */
|
|
54
|
+
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
|
55
|
+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
56
|
+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
57
|
+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
58
|
+
// "typeRoots": [], /* List of folders to include type definitions from. */
|
|
59
|
+
// "types": [], /* Type declaration files to be included in compilation. */
|
|
60
|
+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
61
|
+
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
62
|
+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
63
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
64
|
+
|
|
65
|
+
/* Source Map Options */
|
|
66
|
+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
|
67
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
68
|
+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
|
69
|
+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
70
|
+
|
|
71
|
+
/* Experimental Options */
|
|
72
|
+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
73
|
+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
74
|
+
|
|
75
|
+
/* Advanced Options */
|
|
76
|
+
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
|
77
|
+
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
|
|
78
|
+
"emitDecoratorMetadata": true,
|
|
79
|
+
"experimentalDecorators": true,
|
|
80
|
+
"allowSyntheticDefaultImports": true
|
|
81
|
+
},
|
|
82
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"include": ["./src/**/*.ts", "./src/*.ts", "./shims"],
|
|
3
|
+
"exclude": ["./src/*.test.ts", "./src/*.test.ts"],
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
|
6
|
+
// "paths": {
|
|
7
|
+
// "type-graphql": ["./shims/type-graphql.ts"],
|
|
8
|
+
// "reflect-metadata": ["./shims/reflect-metadata.ts"]
|
|
9
|
+
// },
|
|
10
|
+
/* Basic Options */
|
|
11
|
+
// "incremental": true, /* Enable incremental compilation */
|
|
12
|
+
"target": "es2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'es2015', or 'ESNEXT'. */
|
|
13
|
+
"lib": ["es2020", "esnext.asynciterable"],
|
|
14
|
+
"module": "es2020", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
|
15
|
+
// "lib": [], /* Specify library files to be included in the compilation. */
|
|
16
|
+
// "allowJs": true, /* Allow javascript files to be compiled. */
|
|
17
|
+
// "checkJs": true, /* Report errors in .js files. */
|
|
18
|
+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
|
|
19
|
+
"declaration": true, /* Generates corresponding '.d.ts' file. */
|
|
20
|
+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
|
21
|
+
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
|
22
|
+
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
23
|
+
"rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
|
24
|
+
"outDir": "./lib",
|
|
25
|
+
// "composite": true, /* Enable project compilation */
|
|
26
|
+
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
|
27
|
+
// "removeComments": true, /* Do not emit comments to output. */
|
|
28
|
+
// "noEmit": true, /* Do not emit outputs. */
|
|
29
|
+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
|
30
|
+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
|
31
|
+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
|
32
|
+
|
|
33
|
+
/* Strict Type-Checking Options */
|
|
34
|
+
// "strict": true, /* Enable all strict type-checking options. */
|
|
35
|
+
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
|
36
|
+
// "strictNullChecks": true, /* Enable strict null checks. */
|
|
37
|
+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
|
38
|
+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
|
39
|
+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
|
40
|
+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
|
41
|
+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
|
42
|
+
|
|
43
|
+
/* Additional Checks */
|
|
44
|
+
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
|
45
|
+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
|
46
|
+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
|
47
|
+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
48
|
+
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
|
49
|
+
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */
|
|
50
|
+
|
|
51
|
+
/* Module Resolution Options */
|
|
52
|
+
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
|
53
|
+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
54
|
+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
55
|
+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
56
|
+
// "typeRoots": [], /* List of folders to include type definitions from. */
|
|
57
|
+
// "types": [], /* Type declaration files to be included in compilation. */
|
|
58
|
+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
59
|
+
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
60
|
+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
61
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
62
|
+
|
|
63
|
+
/* Source Map Options */
|
|
64
|
+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
|
65
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
66
|
+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
|
67
|
+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
68
|
+
|
|
69
|
+
/* Experimental Options */
|
|
70
|
+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
71
|
+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
72
|
+
|
|
73
|
+
/* Advanced Options */
|
|
74
|
+
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
|
75
|
+
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
|
|
76
|
+
"emitDecoratorMetadata": true,
|
|
77
|
+
"experimentalDecorators": true,
|
|
78
|
+
"allowSyntheticDefaultImports": true
|
|
79
|
+
},
|
|
80
|
+
}
|