@coasys/ad4m 0.8.0-fix → 0.8.1

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 (161) hide show
  1. package/README.md +229 -229
  2. package/jest.config.js +5 -5
  3. package/jsdoc.json +27 -27
  4. package/lib/index.cjs +4522 -4571
  5. package/lib/index.js +4522 -4571
  6. package/lib/shims/type-graphql.d.ts +32 -32
  7. package/lib/shims/type-graphql.js +70 -70
  8. package/lib/src/Ad4mClient.d.ts +26 -26
  9. package/lib/src/Ad4mClient.js +66 -66
  10. package/lib/src/Address.d.ts +1 -1
  11. package/lib/src/Address.js +1 -1
  12. package/lib/src/DID.d.ts +1 -1
  13. package/lib/src/DID.js +1 -1
  14. package/lib/src/Exception.d.ts +6 -6
  15. package/lib/src/Exception.js +7 -7
  16. package/lib/src/Literal.d.ts +7 -7
  17. package/lib/src/Literal.js +76 -76
  18. package/lib/src/PubSub.d.ts +14 -14
  19. package/lib/src/PubSub.js +14 -14
  20. package/lib/src/SmartLiteral.d.ts +12 -12
  21. package/lib/src/SmartLiteral.js +74 -74
  22. package/lib/src/agent/Agent.d.ts +104 -104
  23. package/lib/src/agent/Agent.js +337 -337
  24. package/lib/src/agent/AgentClient.d.ts +57 -57
  25. package/lib/src/agent/AgentClient.js +431 -431
  26. package/lib/src/agent/AgentResolver.d.ts +30 -30
  27. package/lib/src/agent/AgentResolver.js +325 -325
  28. package/lib/src/agent/AgentStatus.d.ts +8 -8
  29. package/lib/src/agent/AgentStatus.js +61 -61
  30. package/lib/src/buildSchema.d.ts +1 -1
  31. package/lib/src/buildSchema.js +36 -36
  32. package/lib/src/expression/Expression.d.ts +28 -28
  33. package/lib/src/expression/Expression.js +143 -143
  34. package/lib/src/expression/ExpressionClient.d.ts +13 -13
  35. package/lib/src/expression/ExpressionClient.js +102 -102
  36. package/lib/src/expression/ExpressionRef.d.ts +9 -9
  37. package/lib/src/expression/ExpressionRef.js +67 -67
  38. package/lib/src/expression/ExpressionResolver.d.ts +10 -10
  39. package/lib/src/expression/ExpressionResolver.js +106 -106
  40. package/lib/src/index.d.ts +30 -30
  41. package/lib/src/index.js +30 -30
  42. package/lib/src/jestSetup.d.ts +1 -1
  43. package/lib/src/jestSetup.js +1 -1
  44. package/lib/src/language/Icon.d.ts +4 -4
  45. package/lib/src/language/Icon.js +24 -24
  46. package/lib/src/language/Language.d.ts +195 -195
  47. package/lib/src/language/Language.js +79 -79
  48. package/lib/src/language/LanguageClient.d.ts +17 -17
  49. package/lib/src/language/LanguageClient.js +137 -137
  50. package/lib/src/language/LanguageContext.d.ts +37 -37
  51. package/lib/src/language/LanguageContext.js +2 -2
  52. package/lib/src/language/LanguageHandle.d.ts +9 -9
  53. package/lib/src/language/LanguageHandle.js +41 -41
  54. package/lib/src/language/LanguageMeta.d.ts +35 -35
  55. package/lib/src/language/LanguageMeta.js +89 -89
  56. package/lib/src/language/LanguageRef.d.ts +6 -6
  57. package/lib/src/language/LanguageRef.js +30 -30
  58. package/lib/src/language/LanguageResolver.d.ts +19 -19
  59. package/lib/src/language/LanguageResolver.js +143 -143
  60. package/lib/src/links/Links.d.ts +39 -39
  61. package/lib/src/links/Links.js +148 -148
  62. package/lib/src/links/Links.test.d.ts +1 -1
  63. package/lib/src/links/Links.test.js +33 -33
  64. package/lib/src/neighbourhood/Neighbourhood.d.ts +10 -10
  65. package/lib/src/neighbourhood/Neighbourhood.js +38 -38
  66. package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +25 -25
  67. package/lib/src/neighbourhood/NeighbourhoodClient.js +256 -256
  68. package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +19 -19
  69. package/lib/src/neighbourhood/NeighbourhoodProxy.js +54 -54
  70. package/lib/src/neighbourhood/NeighbourhoodResolver.d.ts +24 -24
  71. package/lib/src/neighbourhood/NeighbourhoodResolver.js +180 -180
  72. package/lib/src/perspectives/LinkQuery.d.ts +11 -11
  73. package/lib/src/perspectives/LinkQuery.js +80 -80
  74. package/lib/src/perspectives/Perspective.d.ts +38 -38
  75. package/lib/src/perspectives/Perspective.js +144 -144
  76. package/lib/src/perspectives/Perspective.test.d.ts +1 -1
  77. package/lib/src/perspectives/Perspective.test.js +20 -20
  78. package/lib/src/perspectives/PerspectiveClient.d.ts +55 -54
  79. package/lib/src/perspectives/PerspectiveClient.js +418 -410
  80. package/lib/src/perspectives/PerspectiveDiff.d.ts +9 -9
  81. package/lib/src/perspectives/PerspectiveDiff.js +33 -33
  82. package/lib/src/perspectives/PerspectiveHandle.d.ts +16 -16
  83. package/lib/src/perspectives/PerspectiveHandle.js +59 -59
  84. package/lib/src/perspectives/PerspectiveProxy.d.ts +178 -178
  85. package/lib/src/perspectives/PerspectiveProxy.js +501 -540
  86. package/lib/src/perspectives/PerspectiveResolver.d.ts +38 -37
  87. package/lib/src/perspectives/PerspectiveResolver.js +376 -362
  88. package/lib/src/runtime/RuntimeClient.d.ts +33 -33
  89. package/lib/src/runtime/RuntimeClient.js +263 -263
  90. package/lib/src/runtime/RuntimeResolver.d.ts +47 -47
  91. package/lib/src/runtime/RuntimeResolver.js +328 -328
  92. package/lib/src/schema.gql +1 -0
  93. package/lib/src/subject/SDNADecorators.d.ts +45 -45
  94. package/lib/src/subject/SDNADecorators.js +250 -250
  95. package/lib/src/subject/Subject.d.ts +7 -7
  96. package/lib/src/subject/Subject.js +160 -160
  97. package/lib/src/subject/SubjectEntity.d.ts +31 -31
  98. package/lib/src/subject/SubjectEntity.js +250 -250
  99. package/lib/src/subject/util.d.ts +12 -12
  100. package/lib/src/subject/util.js +73 -73
  101. package/lib/src/typeDefs.d.ts +1 -1
  102. package/lib/src/typeDefs.js +1 -0
  103. package/lib/src/unwrapApolloResult.d.ts +2 -2
  104. package/lib/src/unwrapApolloResult.js +14 -12
  105. package/lib/src/utils.d.ts +2 -2
  106. package/lib/src/utils.js +21 -21
  107. package/package.json +61 -61
  108. package/rollup.config.js +26 -26
  109. package/shims/type-graphql.ts +75 -75
  110. package/src/Ad4mClient.test.ts +1089 -1084
  111. package/src/Ad4mClient.ts +62 -62
  112. package/src/Address.ts +1 -1
  113. package/src/Exception.ts +6 -6
  114. package/src/Literal.test.ts +30 -30
  115. package/src/Literal.ts +80 -80
  116. package/src/PubSub.ts +13 -13
  117. package/src/SmartLiteral.ts +74 -74
  118. package/src/agent/Agent.ts +293 -293
  119. package/src/agent/AgentClient.ts +531 -531
  120. package/src/agent/AgentResolver.ts +263 -263
  121. package/src/agent/AgentStatus.ts +43 -43
  122. package/src/buildSchema.ts +41 -41
  123. package/src/expression/Expression.ts +99 -99
  124. package/src/expression/ExpressionClient.ts +98 -98
  125. package/src/expression/ExpressionRef.ts +62 -62
  126. package/src/expression/ExpressionResolver.ts +63 -63
  127. package/src/index.ts +30 -30
  128. package/src/language/Icon.ts +10 -10
  129. package/src/language/Language.ts +266 -266
  130. package/src/language/LanguageClient.ts +159 -159
  131. package/src/language/LanguageContext.ts +37 -37
  132. package/src/language/LanguageHandle.ts +23 -23
  133. package/src/language/LanguageMeta.ts +69 -69
  134. package/src/language/LanguageRef.ts +18 -18
  135. package/src/language/LanguageResolver.ts +98 -98
  136. package/src/links/Links.test.ts +39 -39
  137. package/src/links/Links.ts +107 -107
  138. package/src/neighbourhood/Neighbourhood.ts +22 -22
  139. package/src/neighbourhood/NeighbourhoodClient.ts +275 -275
  140. package/src/neighbourhood/NeighbourhoodProxy.ts +58 -58
  141. package/src/neighbourhood/NeighbourhoodResolver.ts +99 -99
  142. package/src/perspectives/LinkQuery.ts +65 -65
  143. package/src/perspectives/Perspective.test.ts +22 -22
  144. package/src/perspectives/Perspective.ts +118 -118
  145. package/src/perspectives/PerspectiveClient.ts +452 -443
  146. package/src/perspectives/PerspectiveDiff.ts +15 -15
  147. package/src/perspectives/PerspectiveHandle.ts +39 -39
  148. package/src/perspectives/PerspectiveProxy.ts +576 -610
  149. package/src/perspectives/PerspectiveResolver.ts +224 -219
  150. package/src/runtime/RuntimeClient.ts +282 -282
  151. package/src/runtime/RuntimeResolver.ts +192 -192
  152. package/src/subject/SDNADecorators.ts +333 -333
  153. package/src/subject/Subject.ts +152 -152
  154. package/src/subject/SubjectEntity.ts +291 -291
  155. package/src/subject/util.ts +84 -84
  156. package/src/typeDefs.ts +5 -5
  157. package/src/unwrapApolloResult.ts +15 -13
  158. package/src/utils.ts +25 -25
  159. package/tsconfig-browser.json +82 -82
  160. package/tsconfig.json +80 -80
  161. package/yarn-error.log +0 -22814
@@ -1,98 +1,98 @@
1
-
2
- import { Arg, Mutation, Query, Resolver } from "type-graphql";
3
- import { Icon } from "./Icon";
4
- import { LanguageHandle } from "./LanguageHandle";
5
- import { LanguageMeta, LanguageMetaInput } from "./LanguageMeta"
6
- import { LanguageRef } from "./LanguageRef";
7
-
8
- /**
9
- * Resolver classes are used here to define the GraphQL schema
10
- * (through the type-graphql annotations)
11
- * and are spawned in the client tests in Ad4mClient.test.ts.
12
- * For the latter, they return test fixtures.
13
- */
14
- @Resolver()
15
- export default class LanguageResolver {
16
- @Query(returns => LanguageHandle, {nullable: true})
17
- language(@Arg('address') address: string): LanguageHandle {
18
- let language = new LanguageHandle()
19
- language.address = address
20
- language.name = 'test-language'
21
- language.settings = JSON.stringify({testSetting: 'test'})
22
- language.icon = new Icon('test-code')
23
- language.settingsIcon = new Icon('test-code')
24
- language.constructorIcon = new Icon('test-code')
25
- return language
26
- }
27
-
28
-
29
- @Query(returns => [LanguageHandle])
30
- languages(@Arg('filter', {nullable: true}) filter: string): LanguageHandle[] {
31
- let language = new LanguageHandle()
32
- language.address = 'test-address'
33
- language.name = 'test-links-language'
34
-
35
- if(!filter || filter === 'linksAdapter')
36
- return [language]
37
- else
38
- return []
39
- }
40
-
41
- @Mutation(returns => Boolean)
42
- languageWriteSettings(
43
- @Arg('languageAddress') languageAddress: string,
44
- @Arg('settings') settings: string
45
- ): Boolean {
46
- return true
47
- }
48
-
49
- @Mutation()
50
- languageApplyTemplateAndPublish(
51
- @Arg('sourceLanguageHash') sourceLanguageHash: string,
52
- @Arg('templateData') templateData: string,
53
- ): LanguageRef {
54
- return new LanguageRef('test-address', `${sourceLanguageHash}-clone`)
55
- }
56
-
57
- @Mutation()
58
- languagePublish(
59
- @Arg('languagePath') languagePath: string,
60
- @Arg('languageMeta') languageMeta: LanguageMetaInput,
61
- ): LanguageMeta {
62
- let meta = new LanguageMeta()
63
- meta.name = languageMeta.name
64
- meta.address = "Qm12345"
65
- meta.description = languageMeta.description
66
- meta.author = "did:test:me"
67
- meta.templated = true
68
- meta.templateSourceLanguageAddress = "Qm12345"
69
- meta.templateAppliedParams = JSON.stringify({uuid: 'asdfsdaf', name: 'test template'})
70
- meta.possibleTemplateParams = languageMeta.possibleTemplateParams
71
- meta.sourceCodeLink = languageMeta.sourceCodeLink
72
- return meta
73
- }
74
-
75
- @Query()
76
- languageMeta(@Arg('address') address: string): LanguageMeta {
77
- let meta = new LanguageMeta()
78
- meta.name = "test-language"
79
- meta.address = address
80
- meta.description = "Language meta for testing"
81
- meta.author = "did:test:me"
82
- meta.templated = true
83
- meta.templateSourceLanguageAddress = "Qm12345"
84
- meta.templateAppliedParams = JSON.stringify({uuid: 'asdfsdaf', name: 'test template'})
85
- meta.possibleTemplateParams = ['uuid', 'name']
86
- meta.sourceCodeLink = "https://github.com/perspect3vism/ad4m"
87
- return meta
88
- }
89
-
90
- @Query()
91
- languageSource(@Arg('address') address: string): string {
92
- return "var test = 'language source code'"
93
- }
94
-
95
- @Mutation()
96
- languageRemove(@Arg('address') address: string): Boolean { return true }
97
- }
98
-
1
+
2
+ import { Arg, Mutation, Query, Resolver } from "type-graphql";
3
+ import { Icon } from "./Icon";
4
+ import { LanguageHandle } from "./LanguageHandle";
5
+ import { LanguageMeta, LanguageMetaInput } from "./LanguageMeta"
6
+ import { LanguageRef } from "./LanguageRef";
7
+
8
+ /**
9
+ * Resolver classes are used here to define the GraphQL schema
10
+ * (through the type-graphql annotations)
11
+ * and are spawned in the client tests in Ad4mClient.test.ts.
12
+ * For the latter, they return test fixtures.
13
+ */
14
+ @Resolver()
15
+ export default class LanguageResolver {
16
+ @Query(returns => LanguageHandle, {nullable: true})
17
+ language(@Arg('address') address: string): LanguageHandle {
18
+ let language = new LanguageHandle()
19
+ language.address = address
20
+ language.name = 'test-language'
21
+ language.settings = JSON.stringify({testSetting: 'test'})
22
+ language.icon = new Icon('test-code')
23
+ language.settingsIcon = new Icon('test-code')
24
+ language.constructorIcon = new Icon('test-code')
25
+ return language
26
+ }
27
+
28
+
29
+ @Query(returns => [LanguageHandle])
30
+ languages(@Arg('filter', {nullable: true}) filter: string): LanguageHandle[] {
31
+ let language = new LanguageHandle()
32
+ language.address = 'test-address'
33
+ language.name = 'test-links-language'
34
+
35
+ if(!filter || filter === 'linksAdapter')
36
+ return [language]
37
+ else
38
+ return []
39
+ }
40
+
41
+ @Mutation(returns => Boolean)
42
+ languageWriteSettings(
43
+ @Arg('languageAddress') languageAddress: string,
44
+ @Arg('settings') settings: string
45
+ ): Boolean {
46
+ return true
47
+ }
48
+
49
+ @Mutation()
50
+ languageApplyTemplateAndPublish(
51
+ @Arg('sourceLanguageHash') sourceLanguageHash: string,
52
+ @Arg('templateData') templateData: string,
53
+ ): LanguageRef {
54
+ return new LanguageRef('test-address', `${sourceLanguageHash}-clone`)
55
+ }
56
+
57
+ @Mutation()
58
+ languagePublish(
59
+ @Arg('languagePath') languagePath: string,
60
+ @Arg('languageMeta') languageMeta: LanguageMetaInput,
61
+ ): LanguageMeta {
62
+ let meta = new LanguageMeta()
63
+ meta.name = languageMeta.name
64
+ meta.address = "Qm12345"
65
+ meta.description = languageMeta.description
66
+ meta.author = "did:test:me"
67
+ meta.templated = true
68
+ meta.templateSourceLanguageAddress = "Qm12345"
69
+ meta.templateAppliedParams = JSON.stringify({uuid: 'asdfsdaf', name: 'test template'})
70
+ meta.possibleTemplateParams = languageMeta.possibleTemplateParams
71
+ meta.sourceCodeLink = languageMeta.sourceCodeLink
72
+ return meta
73
+ }
74
+
75
+ @Query()
76
+ languageMeta(@Arg('address') address: string): LanguageMeta {
77
+ let meta = new LanguageMeta()
78
+ meta.name = "test-language"
79
+ meta.address = address
80
+ meta.description = "Language meta for testing"
81
+ meta.author = "did:test:me"
82
+ meta.templated = true
83
+ meta.templateSourceLanguageAddress = "Qm12345"
84
+ meta.templateAppliedParams = JSON.stringify({uuid: 'asdfsdaf', name: 'test template'})
85
+ meta.possibleTemplateParams = ['uuid', 'name']
86
+ meta.sourceCodeLink = "https://github.com/perspect3vism/ad4m"
87
+ return meta
88
+ }
89
+
90
+ @Query()
91
+ languageSource(@Arg('address') address: string): string {
92
+ return "var test = 'language source code'"
93
+ }
94
+
95
+ @Mutation()
96
+ languageRemove(@Arg('address') address: string): Boolean { return true }
97
+ }
98
+
@@ -1,40 +1,40 @@
1
- import { LinkQuery } from '../perspectives/LinkQuery'
2
-
3
- const query = new LinkQuery({
4
- source: 'a'
5
- })
6
-
7
- describe('LinkQuery', () => {
8
- it('can match positively', () => {
9
- expect(query.isMatch({
10
- source: 'a',
11
- predicate: 'b',
12
- target: 'c'
13
- })).toBe(true)
14
-
15
- expect(query.isMatch({
16
- source: 'a',
17
- target: 'c'
18
- })).toBe(true)
19
-
20
- expect(query.isMatch({
21
- source: 'a',
22
- predicate: 'b',
23
- target: 'c'
24
- })).toBe(true)
25
- })
26
-
27
- it('can match negatively', () => {
28
- expect(query.isMatch({
29
- source: 'c',
30
- predicate: 'b',
31
- target: 'c'
32
- })).toBe(false)
33
-
34
- expect(query.isMatch({
35
- source: 'c',
36
- target: 'b'
37
- })).toBe(false)
38
-
39
- })
1
+ import { LinkQuery } from '../perspectives/LinkQuery'
2
+
3
+ const query = new LinkQuery({
4
+ source: 'a'
5
+ })
6
+
7
+ describe('LinkQuery', () => {
8
+ it('can match positively', () => {
9
+ expect(query.isMatch({
10
+ source: 'a',
11
+ predicate: 'b',
12
+ target: 'c'
13
+ })).toBe(true)
14
+
15
+ expect(query.isMatch({
16
+ source: 'a',
17
+ target: 'c'
18
+ })).toBe(true)
19
+
20
+ expect(query.isMatch({
21
+ source: 'a',
22
+ predicate: 'b',
23
+ target: 'c'
24
+ })).toBe(true)
25
+ })
26
+
27
+ it('can match negatively', () => {
28
+ expect(query.isMatch({
29
+ source: 'c',
30
+ predicate: 'b',
31
+ target: 'c'
32
+ })).toBe(false)
33
+
34
+ expect(query.isMatch({
35
+ source: 'c',
36
+ target: 'b'
37
+ })).toBe(false)
38
+
39
+ })
40
40
  })
@@ -1,107 +1,107 @@
1
- import { Field, InputType, ObjectType } from "type-graphql";
2
- import { ExpressionGeneric, ExpressionGenericInput } from '../expression/Expression';
3
- import { LinkStatus } from "../perspectives/PerspectiveProxy";
4
-
5
- @ObjectType()
6
- export class Link {
7
- @Field()
8
- source: string;
9
-
10
- @Field()
11
- target: string;
12
-
13
- @Field({nullable: true})
14
- predicate?: string;
15
-
16
- constructor(obj) {
17
- this.source = obj.source ? obj.source : ''
18
- this.target = obj.target ? obj.target : ''
19
- this.predicate = obj.predicate ? obj.predicate : ''
20
- }
21
- }
22
-
23
- @InputType()
24
- export class LinkMutations {
25
- @Field(type => [LinkInput])
26
- additions: LinkInput[];
27
-
28
- @Field(type => [LinkExpressionInput])
29
- removals: LinkExpressionInput[];
30
- }
31
- @ObjectType()
32
- export class LinkExpressionMutations {
33
- @Field(type => [LinkExpression])
34
- additions: LinkExpression[];
35
-
36
- @Field(type => [LinkExpression])
37
- removals: LinkExpression[];
38
-
39
- constructor(additions: LinkExpression[], removals: LinkExpression[]) {
40
- this.additions = additions
41
- this.removals = removals
42
- }
43
- }
44
-
45
- @InputType()
46
- export class LinkInput {
47
- @Field()
48
- source: string;
49
-
50
- @Field()
51
- target: string;
52
-
53
- @Field({nullable: true})
54
- predicate?: string;
55
- }
56
-
57
- @ObjectType()
58
- export class LinkExpression extends ExpressionGeneric(Link) {
59
- hash(): number {
60
- const mash = JSON.stringify(this.data, Object.keys(this.data).sort()) +
61
- JSON.stringify(this.author) + this.timestamp
62
- let hash = 0, i, chr;
63
- for (i = 0; i < mash.length; i++) {
64
- chr = mash.charCodeAt(i);
65
- hash = ((hash << 5) - hash) + chr;
66
- hash |= 0; // Convert to 32bit integer
67
- }
68
- return hash;
69
- }
70
-
71
- @Field({ nullable: true, defaultValue: 'shared' })
72
- status?: LinkStatus;
73
- };
74
-
75
- @InputType()
76
- export class LinkExpressionInput extends ExpressionGenericInput(LinkInput) {
77
- hash: () => number;
78
-
79
- @Field({ nullable: true, defaultValue: 'shared' })
80
- status?: LinkStatus;
81
- };
82
-
83
- export function linkEqual(l1: LinkExpression, l2: LinkExpression): boolean {
84
- return l1.author == l2.author &&
85
- l1.timestamp == l2.timestamp &&
86
- l1.data.source == l2.data.source &&
87
- l1.data.predicate == l2.data.predicate &&
88
- l1.data.target == l2.data.target
89
- }
90
-
91
- export function isLink(l: any): boolean {
92
- return l && l.source && l.target
93
- }
94
-
95
- @ObjectType()
96
- export class LinkExpressionUpdated {
97
- @Field(type => LinkExpression)
98
- oldLink: LinkExpression;
99
-
100
- @Field(type => LinkExpression)
101
- newLink: LinkExpression;
102
-
103
- constructor(oldLink: LinkExpression, newLink: LinkExpression) {
104
- this.oldLink = oldLink
105
- this.newLink = newLink
106
- }
107
- }
1
+ import { Field, InputType, ObjectType } from "type-graphql";
2
+ import { ExpressionGeneric, ExpressionGenericInput } from '../expression/Expression';
3
+ import { LinkStatus } from "../perspectives/PerspectiveProxy";
4
+
5
+ @ObjectType()
6
+ export class Link {
7
+ @Field()
8
+ source: string;
9
+
10
+ @Field()
11
+ target: string;
12
+
13
+ @Field({nullable: true})
14
+ predicate?: string;
15
+
16
+ constructor(obj) {
17
+ this.source = obj.source ? obj.source : ''
18
+ this.target = obj.target ? obj.target : ''
19
+ this.predicate = obj.predicate ? obj.predicate : ''
20
+ }
21
+ }
22
+
23
+ @InputType()
24
+ export class LinkMutations {
25
+ @Field(type => [LinkInput])
26
+ additions: LinkInput[];
27
+
28
+ @Field(type => [LinkExpressionInput])
29
+ removals: LinkExpressionInput[];
30
+ }
31
+ @ObjectType()
32
+ export class LinkExpressionMutations {
33
+ @Field(type => [LinkExpression])
34
+ additions: LinkExpression[];
35
+
36
+ @Field(type => [LinkExpression])
37
+ removals: LinkExpression[];
38
+
39
+ constructor(additions: LinkExpression[], removals: LinkExpression[]) {
40
+ this.additions = additions
41
+ this.removals = removals
42
+ }
43
+ }
44
+
45
+ @InputType()
46
+ export class LinkInput {
47
+ @Field()
48
+ source: string;
49
+
50
+ @Field()
51
+ target: string;
52
+
53
+ @Field({nullable: true})
54
+ predicate?: string;
55
+ }
56
+
57
+ @ObjectType()
58
+ export class LinkExpression extends ExpressionGeneric(Link) {
59
+ hash(): number {
60
+ const mash = JSON.stringify(this.data, Object.keys(this.data).sort()) +
61
+ JSON.stringify(this.author) + this.timestamp
62
+ let hash = 0, i, chr;
63
+ for (i = 0; i < mash.length; i++) {
64
+ chr = mash.charCodeAt(i);
65
+ hash = ((hash << 5) - hash) + chr;
66
+ hash |= 0; // Convert to 32bit integer
67
+ }
68
+ return hash;
69
+ }
70
+
71
+ @Field({ nullable: true, defaultValue: 'shared' })
72
+ status?: LinkStatus;
73
+ };
74
+
75
+ @InputType()
76
+ export class LinkExpressionInput extends ExpressionGenericInput(LinkInput) {
77
+ hash: () => number;
78
+
79
+ @Field({ nullable: true, defaultValue: 'shared' })
80
+ status?: LinkStatus;
81
+ };
82
+
83
+ export function linkEqual(l1: LinkExpression, l2: LinkExpression): boolean {
84
+ return l1.author == l2.author &&
85
+ l1.timestamp == l2.timestamp &&
86
+ l1.data.source == l2.data.source &&
87
+ l1.data.predicate == l2.data.predicate &&
88
+ l1.data.target == l2.data.target
89
+ }
90
+
91
+ export function isLink(l: any): boolean {
92
+ return l && l.source && l.target
93
+ }
94
+
95
+ @ObjectType()
96
+ export class LinkExpressionUpdated {
97
+ @Field(type => LinkExpression)
98
+ oldLink: LinkExpression;
99
+
100
+ @Field(type => LinkExpression)
101
+ newLink: LinkExpression;
102
+
103
+ constructor(oldLink: LinkExpression, newLink: LinkExpression) {
104
+ this.oldLink = oldLink
105
+ this.newLink = newLink
106
+ }
107
+ }
@@ -1,22 +1,22 @@
1
- import { Field, ObjectType } from "type-graphql";
2
- import { ExpressionGeneric } from "../expression/Expression";
3
- import { LanguageRef } from "../language/LanguageRef";
4
- import { Perspective } from "../perspectives/Perspective";
5
-
6
-
7
- @ObjectType()
8
- export class Neighbourhood {
9
- @Field()
10
- linkLanguage: string
11
-
12
- @Field()
13
- meta: Perspective
14
-
15
- constructor(linkLanguage: string, meta: Perspective) {
16
- this.linkLanguage = linkLanguage;
17
- this.meta = meta;
18
- }
19
- }
20
-
21
- @ObjectType()
22
- export class NeighbourhoodExpression extends ExpressionGeneric(Neighbourhood) {};
1
+ import { Field, ObjectType } from "type-graphql";
2
+ import { ExpressionGeneric } from "../expression/Expression";
3
+ import { LanguageRef } from "../language/LanguageRef";
4
+ import { Perspective } from "../perspectives/Perspective";
5
+
6
+
7
+ @ObjectType()
8
+ export class Neighbourhood {
9
+ @Field()
10
+ linkLanguage: string
11
+
12
+ @Field()
13
+ meta: Perspective
14
+
15
+ constructor(linkLanguage: string, meta: Perspective) {
16
+ this.linkLanguage = linkLanguage;
17
+ this.meta = meta;
18
+ }
19
+ }
20
+
21
+ @ObjectType()
22
+ export class NeighbourhoodExpression extends ExpressionGeneric(Neighbourhood) {};