solid-logic 3.0.9-ea192f01 → 3.0.9-ed64096

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 (81) hide show
  1. package/package.json +9 -3
  2. package/babel.config.js +0 -6
  3. package/eslint.config.js +0 -28
  4. package/jest.config.js +0 -17
  5. package/rollup.config.js +0 -29
  6. package/src/acl/aclLogic.ts +0 -156
  7. package/src/authSession/authSession.ts +0 -13
  8. package/src/authn/SolidAuthnLogic.ts +0 -126
  9. package/src/authn/authUtil.ts +0 -70
  10. package/src/chat/chatLogic.ts +0 -226
  11. package/src/inbox/inboxLogic.ts +0 -59
  12. package/src/index.ts +0 -21
  13. package/src/issuer/issuerLogic.ts +0 -40
  14. package/src/logic/CustomError.ts +0 -29
  15. package/src/logic/solidLogic.ts +0 -76
  16. package/src/logic/solidLogicSingleton.ts +0 -20
  17. package/src/profile/profileLogic.ts +0 -125
  18. package/src/typeIndex/typeIndexLogic.ts +0 -198
  19. package/src/types.ts +0 -122
  20. package/src/util/containerLogic.ts +0 -53
  21. package/src/util/debug.ts +0 -16
  22. package/src/util/ns.ts +0 -5
  23. package/src/util/utilityLogic.ts +0 -156
  24. package/src/util/utils.ts +0 -52
  25. package/src/versionInfo.ts +0 -32
  26. package/test/aclLogic.test.ts +0 -24
  27. package/test/authUtil.test.ts +0 -23
  28. package/test/chatLogic.test.ts +0 -322
  29. package/test/container.test.ts +0 -58
  30. package/test/helpers/dataSetup.ts +0 -135
  31. package/test/helpers/setup.ts +0 -22
  32. package/test/inboxLogic.test.ts +0 -209
  33. package/test/logic.test.ts +0 -29
  34. package/test/profileLogic.test.ts +0 -248
  35. package/test/solidAuthLogic.test.ts +0 -49
  36. package/test/typeIndexLogic.test.ts +0 -255
  37. package/test/utilityLogic.test.ts +0 -180
  38. package/test/utils.test.ts +0 -32
  39. package/timestamp.sh +0 -13
  40. package/tsconfig.json +0 -77
  41. package/tsconfig.test.json +0 -8
  42. /package/{lib → dist}/acl/aclLogic.d.ts +0 -0
  43. /package/{lib → dist}/acl/aclLogic.d.ts.map +0 -0
  44. /package/{lib → dist}/authSession/authSession.d.ts +0 -0
  45. /package/{lib → dist}/authSession/authSession.d.ts.map +0 -0
  46. /package/{lib → dist}/authn/SolidAuthnLogic.d.ts +0 -0
  47. /package/{lib → dist}/authn/SolidAuthnLogic.d.ts.map +0 -0
  48. /package/{lib → dist}/authn/authUtil.d.ts +0 -0
  49. /package/{lib → dist}/authn/authUtil.d.ts.map +0 -0
  50. /package/{lib → dist}/chat/chatLogic.d.ts +0 -0
  51. /package/{lib → dist}/chat/chatLogic.d.ts.map +0 -0
  52. /package/{lib → dist}/inbox/inboxLogic.d.ts +0 -0
  53. /package/{lib → dist}/inbox/inboxLogic.d.ts.map +0 -0
  54. /package/{lib → dist}/index.d.ts +0 -0
  55. /package/{lib → dist}/index.d.ts.map +0 -0
  56. /package/{lib → dist}/issuer/issuerLogic.d.ts +0 -0
  57. /package/{lib → dist}/issuer/issuerLogic.d.ts.map +0 -0
  58. /package/{lib → dist}/logic/CustomError.d.ts +0 -0
  59. /package/{lib → dist}/logic/CustomError.d.ts.map +0 -0
  60. /package/{lib → dist}/logic/solidLogic.d.ts +0 -0
  61. /package/{lib → dist}/logic/solidLogic.d.ts.map +0 -0
  62. /package/{lib → dist}/logic/solidLogicSingleton.d.ts +0 -0
  63. /package/{lib → dist}/logic/solidLogicSingleton.d.ts.map +0 -0
  64. /package/{lib → dist}/profile/profileLogic.d.ts +0 -0
  65. /package/{lib → dist}/profile/profileLogic.d.ts.map +0 -0
  66. /package/{lib → dist}/solid-logic.js +0 -0
  67. /package/{lib → dist}/solid-logic.js.map +0 -0
  68. /package/{lib → dist}/typeIndex/typeIndexLogic.d.ts +0 -0
  69. /package/{lib → dist}/typeIndex/typeIndexLogic.d.ts.map +0 -0
  70. /package/{lib → dist}/types.d.ts +0 -0
  71. /package/{lib → dist}/types.d.ts.map +0 -0
  72. /package/{lib → dist}/util/containerLogic.d.ts +0 -0
  73. /package/{lib → dist}/util/containerLogic.d.ts.map +0 -0
  74. /package/{lib → dist}/util/debug.d.ts +0 -0
  75. /package/{lib → dist}/util/debug.d.ts.map +0 -0
  76. /package/{lib → dist}/util/ns.d.ts +0 -0
  77. /package/{lib → dist}/util/ns.d.ts.map +0 -0
  78. /package/{lib → dist}/util/utilityLogic.d.ts +0 -0
  79. /package/{lib → dist}/util/utilityLogic.d.ts.map +0 -0
  80. /package/{lib → dist}/util/utils.d.ts +0 -0
  81. /package/{lib → dist}/util/utils.d.ts.map +0 -0
@@ -1,255 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- *
4
- */
5
- import { Fetcher, Store, sym, UpdateManager } from 'rdflib'
6
- import { createAclLogic } from '../src/acl/aclLogic'
7
- import { createProfileLogic } from '../src/profile/profileLogic'
8
- import { createTypeIndexLogic} from '../src/typeIndex/typeIndexLogic'
9
- import { createContainerLogic } from '../src/util/containerLogic'
10
- import { ns } from '../src/util/ns'
11
- import { createUtilityLogic } from '../src/util/utilityLogic'
12
- import { uniqueNodes } from '../src/util/utils'
13
- import { alice, AlicePhotoFolder, AlicePhotos, AlicePreferences, AlicePreferencesFile, AlicePrivateTypeIndex, AlicePrivateTypes, AliceProfile, AlicePublicTypeIndex, AlicePublicTypes, bob, BobProfile, club, ClubPreferences, ClubPreferencesFile, ClubPrivateTypeIndex, ClubPrivateTypes, ClubProfile, ClubPublicTypeIndex, ClubPublicTypes } from './helpers/dataSetup'
14
-
15
- const prefixes = Object.keys(ns).map(prefix => `@prefix ${prefix}: ${ns[prefix]('')}.\n`).join('') // In turtle
16
- window.$SolidTestEnvironment = { username: alice.uri }
17
-
18
- const Tracker = ns.wf('Tracker')
19
- const Image = ns.schema('Image')
20
-
21
- //let web = {}
22
- //web = loadWebObject()
23
- const user = alice
24
- const profile = user.doc()
25
- const web = {}
26
- web[profile.uri] = AliceProfile
27
- web[AlicePreferencesFile.uri] = AlicePreferences
28
- web[AlicePrivateTypeIndex.uri] = AlicePrivateTypes
29
- web[AlicePublicTypeIndex.uri] = AlicePublicTypes
30
- web[AlicePhotoFolder.uri] = AlicePhotos
31
- web[bob.doc().uri] = BobProfile
32
-
33
- web[club.doc().uri] = ClubProfile
34
- web[ClubPreferencesFile.uri] = ClubPreferences
35
- web[ClubPrivateTypeIndex.uri] = ClubPrivateTypes
36
- web[ClubPublicTypeIndex.uri] = ClubPublicTypes
37
- let requests: Request[] = []
38
- let statustoBeReturned = 200
39
- let typeIndexLogic
40
-
41
- describe('TypeIndex logic NEW', () => {
42
- let store
43
- const authn = {
44
- currentUser: () => {
45
- return alice
46
- },
47
- }
48
-
49
- beforeEach(() => {
50
- fetchMock.resetMocks()
51
- requests = []
52
- statustoBeReturned = 200
53
-
54
- fetchMock.mockIf(/^https?.*$/, async req => {
55
-
56
- if (req.method !== 'GET') {
57
- requests.push(req)
58
- if (req.method === 'PUT') {
59
- const contents = await req.text()
60
- web[req.url] = contents // Update our dummy web
61
- console.log(`Tetst: Updated ${req.url} on PUT to <<<${web[req.url]}>>>`)
62
- }
63
- return { status: statustoBeReturned }
64
- }
65
- const contents = web[req.url]
66
- if (contents !== undefined) { //
67
- return {
68
- body: prefixes + contents, // Add namespaces to anything
69
- status: 200,
70
- headers: {
71
- 'Content-Type': 'text/turtle',
72
- 'WAC-Allow': 'user="write", public="read"',
73
- 'Accept-Patch': 'application/sparql-update'
74
- }
75
- }
76
- } // if contents
77
- return {
78
- status: 404,
79
- body: 'Not Found'
80
- }
81
- })
82
-
83
- store = new Store()
84
- store.fetcher = new Fetcher(store, { fetch: fetch })
85
- store.updater = new UpdateManager(store)
86
- const util = createUtilityLogic(store, createAclLogic(store), createContainerLogic(store))
87
- typeIndexLogic = createTypeIndexLogic(store, authn, createProfileLogic(store, authn, util), util)
88
- })
89
-
90
- describe('loadAllTypeIndexes', () => {
91
- it('exists', () => {
92
- expect(typeIndexLogic.loadAllTypeIndexes).toBeInstanceOf(Function)
93
- })
94
- })
95
-
96
- const AliceScopes = [{
97
- 'agent': {
98
- 'classOrder': 5,
99
- 'termType': 'NamedNode',
100
- 'value': 'https://alice.example.com/profile/card.ttl#me',
101
- },
102
- 'index': {
103
- 'classOrder': 5,
104
- 'termType': 'NamedNode',
105
- 'value': 'https://alice.example.com/profile/public-type-index.ttl',
106
- },
107
- 'label': 'public',
108
- },
109
- {
110
- 'agent': {
111
- 'classOrder': 5,
112
- 'termType': 'NamedNode',
113
- 'value': 'https://alice.example.com/profile/card.ttl#me',
114
- },
115
- 'index': {
116
- 'classOrder': 5,
117
- 'termType': 'NamedNode',
118
- 'value': 'https://alice.example.com/settings/private-type-index.ttl',
119
- },
120
- 'label': 'private',
121
- }
122
- ]
123
-
124
- describe('loadTypeIndexesFor', () => {
125
- it('exists', () => {
126
- expect(typeIndexLogic.loadTypeIndexesFor).toBeInstanceOf(Function)
127
- })
128
- it('loads data', async () => {
129
- const result = await typeIndexLogic.loadTypeIndexesFor(alice)
130
- expect(result).toEqual(AliceScopes)
131
- expect(store.statementsMatching(null, null, null, AlicePrivateTypeIndex).length).toEqual(8)
132
- expect(store.statementsMatching(null, null, null, AlicePublicTypeIndex).length).toEqual(8)
133
- })
134
- })
135
-
136
- const ClubScopes =
137
- [
138
- {
139
- 'agent': {
140
- 'classOrder': 5,
141
- 'termType': 'NamedNode',
142
- 'value': 'https://club.example.com/profile/card.ttl#it',
143
- },
144
- 'index': {
145
- 'classOrder': 5,
146
- 'termType': 'NamedNode',
147
- 'value': 'https://club.example.com/profile/public-type-index.ttl',
148
- },
149
- 'label': 'public',
150
- },
151
- {
152
- 'agent': {
153
- 'classOrder': 5,
154
- 'termType': 'NamedNode',
155
- 'value': 'https://club.example.com/profile/card.ttl#it',
156
- },
157
- 'index': {
158
- 'classOrder': 5,
159
- 'termType': 'NamedNode',
160
- 'value': 'https://club.example.com/settings/private-type-index.ttl',
161
- },
162
- 'label': 'private',
163
- }
164
- ]
165
- describe('loadCommunityTypeIndexes', () => {
166
- it('exists', () => {
167
- expect(typeIndexLogic.loadCommunityTypeIndexes).toBeInstanceOf(Function)
168
- })
169
- it('loads data', async () => {
170
- const result = await typeIndexLogic.loadCommunityTypeIndexes(alice)
171
- expect(result).toEqual(ClubScopes)
172
- })
173
- })
174
-
175
- const AliceAndClubScopes = [{'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/publicStuff/actionItems.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/profile/card.ttl#me'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/profile/public-type-index.ttl'}, 'label': 'public'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/project4/issues.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/profile/card.ttl#me'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/profile/public-type-index.ttl'}, 'label': 'public'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/privateStuff/ToDo.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/profile/card.ttl#me'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/settings/private-type-index.ttl'}, 'label': 'private'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/privateStuff/Goals.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/profile/card.ttl#me'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/settings/private-type-index.ttl'}, 'label': 'private'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/privateStuff/workingOn.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/profile/card.ttl#me'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/settings/private-type-index.ttl'}, 'label': 'private'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/publicStuff/actionItems.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/profile/card.ttl#it'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/profile/public-type-index.ttl'}, 'label': 'public'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/project4/clubIssues.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/profile/card.ttl#it'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/profile/public-type-index.ttl'}, 'label': 'public'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/privateStuff/ToDo.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/profile/card.ttl#it'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/settings/private-type-index.ttl'}, 'label': 'private'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/privateStuff/Goals.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/profile/card.ttl#it'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/settings/private-type-index.ttl'}, 'label': 'private'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/privateStuff/tasks.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/profile/card.ttl#it'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/settings/private-type-index.ttl'}, 'label': 'private'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}]
176
-
177
- describe('getScopedAppInstances', () => {
178
- it('exists', () => {
179
- expect(typeIndexLogic.getScopedAppInstances).toBeInstanceOf(Function)
180
- })
181
- it('pulls in users scopes and also community ones', async () => {
182
- const result = await typeIndexLogic.getScopedAppInstances(Tracker, alice)
183
- expect(result).toEqual(AliceAndClubScopes) // @@ AliceAndClubScopes
184
- })
185
- it('creates new preferenceFile and typeIndex files where they dont exist', async () => {
186
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
187
- const result = await typeIndexLogic.getScopedAppInstances(Tracker, bob)
188
-
189
- expect(requests[0].method).toEqual('PATCH') // Add preferrencesFile link to profile
190
- expect(requests[0].url).toEqual('https://bob.example.com/profile/card.ttl')
191
-
192
- expect(requests[1].method).toEqual('PUT') // create publiTypeIndex
193
- expect(requests[1].url).toEqual('https://bob.example.com/profile/publicTypeIndex.ttl')
194
-
195
- expect(requests[2].method).toEqual('PATCH') // Add link of publiTypeIndex to profile
196
- expect(requests[2].url).toEqual('https://bob.example.com/profile/card.ttl')
197
-
198
- expect(requests[3].method).toEqual('PUT') // create preferenceFile
199
- expect(requests[3].url).toEqual('https://bob.example.com/Settings/Preferences.ttl')
200
-
201
- expect(requests[4].method).toEqual('PATCH') // Add privateTypeIndex link preference file
202
- expect(requests[4].url).toEqual('https://bob.example.com/Settings/Preferences.ttl')
203
-
204
- expect(requests[5].method).toEqual('PUT') //create privatTypeIndex
205
- expect(requests[5].url).toEqual('https://bob.example.com/Settings/privateTypeIndex.ttl')
206
-
207
- expect(requests.length).toEqual(6)
208
-
209
- })
210
- })
211
-
212
- const TRACKERS =
213
- [{'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/publicStuff/actionItems.ttl#this'},
214
- {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/project4/issues.ttl#this'},
215
- {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/privateStuff/ToDo.ttl#this'},
216
- {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/privateStuff/Goals.ttl#this'},
217
- {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/privateStuff/workingOn.ttl#this'},
218
- {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/publicStuff/actionItems.ttl#this'},
219
- {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/project4/clubIssues.ttl#this'},
220
- {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/privateStuff/ToDo.ttl#this'},
221
- {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/privateStuff/Goals.ttl#this'},
222
- {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/privateStuff/tasks.ttl#this'} ]
223
-
224
- describe('getAppInstances', () => {
225
- it('exists', () => {
226
- expect(typeIndexLogic.getAppInstances).toBeInstanceOf(Function)
227
- })
228
- it('finds trackers', async () => {
229
- const result = await typeIndexLogic.getAppInstances(Tracker)
230
- expect(result).toEqual(TRACKERS) // TRACKERS @@
231
- expect(result).toEqual(uniqueNodes(result)) // shoud have no dups
232
- })
233
- it('finds containers', async () => {
234
- const result = await typeIndexLogic.getAppInstances(Image)
235
- expect(result.length).toEqual(1)
236
- expect(result).toEqual(uniqueNodes(result)) // shoud have no dups
237
- expect(result.map(x => x.uri).join()).toEqual('https://alice.example.com/profile/Photos/')
238
- })
239
- })
240
-
241
- describe('registerInTypeIndex', () => {
242
- it('exists', () => {
243
- expect(typeIndexLogic.registerInTypeIndex).toBeInstanceOf(Function)
244
- })
245
- it('throws error', async () => {
246
- const result = await typeIndexLogic.registerInTypeIndex(
247
- sym('https://test.test#'),
248
- sym('https://test.test#'),
249
- sym('https://test.test/TheClass')
250
- )
251
- console.log(result)
252
- expect(result).toEqual(null)
253
- })
254
- })
255
- })
@@ -1,180 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- *
4
- */
5
- import fetchMock from 'jest-fetch-mock'
6
- import { UpdateManager, sym, Fetcher, Store } from 'rdflib'
7
- import { createAclLogic } from '../src/acl/aclLogic'
8
- import { WebOperationError } from '../src/logic/CustomError'
9
- import { createContainerLogic } from '../src/util/containerLogic'
10
- import { ns } from '../src/util/ns'
11
- import { createUtilityLogic } from '../src/util/utilityLogic'
12
- import { alice, AlicePhotoFolder, AlicePhotos, AlicePreferences, AlicePreferencesFile, AlicePrivateTypeIndex, AlicePrivateTypes, AliceProfile, AlicePublicTypeIndex, AlicePublicTypes, bob, BobProfile, club, ClubPreferences, ClubPreferencesFile, ClubPrivateTypeIndex, ClubPrivateTypes, ClubProfile, ClubPublicTypeIndex, ClubPublicTypes } from './helpers/dataSetup'
13
-
14
- window.$SolidTestEnvironment = { username: alice.uri }
15
- const prefixes = Object.keys(ns).map(prefix => `@prefix ${prefix}: ${ns[prefix]('')}.\n`).join('') // In turtle
16
-
17
- describe('utilityLogic', () => {
18
- let store
19
- let options
20
- let web = {}
21
- let requests: Request[] = []
22
- let statustoBeReturned = 200
23
- let utilityLogic
24
- beforeEach(() => {
25
- fetchMock.resetMocks()
26
- fetchMock.mockResponse('Not Found', {
27
- status: 404,
28
- })
29
- requests = []
30
- statustoBeReturned = 200
31
-
32
- fetchMock.mockIf(/^https?.*$/, async req => {
33
-
34
- if (req.method !== 'GET') {
35
- requests.push(req)
36
- if (req.method === 'PUT') {
37
- const contents = await req.text()
38
- web[req.url] = contents // Update our dummy web
39
- console.log(`Tetst: Updated ${req.url} on PUT to <<<${web[req.url]}>>>`)
40
- }
41
- return { status: statustoBeReturned }
42
- }
43
- const contents = web[req.url]
44
- if (contents !== undefined) { //
45
- return {
46
- body: prefixes + contents, // Add namespaces to anything
47
- status: 200,
48
- headers: {
49
- 'Content-Type': 'text/turtle',
50
- 'WAC-Allow': 'user="write", public="read"',
51
- 'Accept-Patch': 'application/sparql-update'
52
- }
53
- }
54
- } // if contents
55
- return {
56
- status: 404,
57
- body: 'Not Found'
58
- }
59
- })
60
- web = {}
61
- web[alice.doc().uri] = AliceProfile
62
- web[AlicePreferencesFile.uri] = AlicePreferences
63
- web[AlicePrivateTypeIndex.uri] = AlicePrivateTypes
64
- web[AlicePublicTypeIndex.uri] = AlicePublicTypes
65
- web[AlicePhotoFolder.uri] = AlicePhotos
66
- web[bob.doc().uri] = BobProfile
67
-
68
- web[club.doc().uri] = ClubProfile
69
- web[ClubPreferencesFile.uri] = ClubPreferences
70
- web[ClubPrivateTypeIndex.uri] = ClubPrivateTypes
71
- web[ClubPublicTypeIndex.uri] = ClubPublicTypes
72
-
73
- options = { fetch: fetch }
74
- store = new Store()
75
- store.fetcher = new Fetcher(store, options)
76
- store.updater = new UpdateManager(store)
77
- requests = []
78
- utilityLogic = createUtilityLogic(store, createAclLogic(store), createContainerLogic(store))
79
- })
80
-
81
- describe('loadOrCreateIfNotExists', () => {
82
- it('exists', () => {
83
- expect(utilityLogic.loadOrCreateIfNotExists).toBeInstanceOf(Function)
84
- })
85
- it('does nothing if existing file', async () => {
86
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
87
- const result = await utilityLogic.loadOrCreateIfNotExists(alice.doc())
88
- expect(requests).toEqual([])
89
-
90
- })
91
- it('creates empty file if did not exist', async () => {
92
- const suggestion = 'https://bob.example.com/settings/prefsSuggestion.ttl'
93
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
94
- const result = await utilityLogic.loadOrCreateIfNotExists(sym(suggestion))
95
- expect(requests[0].method).toEqual('PUT')
96
- expect(requests[0].url).toEqual(suggestion)
97
- })
98
- })
99
-
100
- describe('followOrCreateLink', () => {
101
- it('exists', () => {
102
- expect(utilityLogic.followOrCreateLink).toBeInstanceOf(Function)
103
- })
104
- it('follows existing link', async () => {
105
- const suggestion = 'https://alice.example.com/settings/prefsSuggestion.ttl'
106
- const result = await utilityLogic.followOrCreateLink(alice, ns.space('preferencesFile'), sym(suggestion), alice.doc())
107
- expect(result).toEqual(AlicePreferencesFile)
108
-
109
- })
110
- it('creates empty file if did not exist and new link', async () => {
111
- const suggestion = 'https://bob.example.com/settings/prefsSuggestion.ttl'
112
- const result = await utilityLogic.followOrCreateLink(bob, ns.space('preferencesFile'), sym(suggestion), bob.doc())
113
- expect(result).toEqual(sym(suggestion))
114
- expect(requests[0].method).toEqual('PATCH')
115
- expect(requests[0].url).toEqual(bob.doc().uri)
116
- expect(requests[1].method).toEqual('PUT')
117
- expect(requests[1].url).toEqual(suggestion)
118
- expect(store.holds(bob, ns.space('preferencesFile'), sym(suggestion), bob.doc())).toEqual(true)
119
- })
120
- //
121
- it('returns null if it cannot create the new file', async () => {
122
- const suggestion = 'https://bob.example.com/settings/prefsSuggestion.ttl'
123
- statustoBeReturned = 403 // Unauthorized
124
- expect(async () => {
125
- await utilityLogic.followOrCreateLink(bob, ns.space('preferencesFile'), sym(suggestion), bob.doc())
126
- }).rejects.toThrow(WebOperationError)
127
- })
128
-
129
- })
130
- describe('setSinglePeerAccess', () => {
131
- beforeEach(() => {
132
- fetchMock.mockOnceIf(
133
- 'https://owner.com/some/resource',
134
- 'hello', {
135
- headers: {
136
- Link: '<https://owner.com/some/acl>; rel="acl"'
137
- }
138
- })
139
- fetchMock.mockOnceIf(
140
- 'https://owner.com/some/acl',
141
- 'Created', {
142
- status: 201
143
- })
144
- })
145
- it('Creates the right ACL doc', async () => {
146
- await utilityLogic.setSinglePeerAccess({
147
- ownerWebId: 'https://owner.com/#me',
148
- peerWebId: 'https://peer.com/#me',
149
- accessToModes: 'acl:Read, acl:Control',
150
- defaultModes: 'acl:Write',
151
- target: 'https://owner.com/some/resource'
152
- })
153
- expect(fetchMock.mock.calls).toEqual([
154
- [ 'https://owner.com/some/resource', fetchMock.mock.calls[0][1] ],
155
- [ 'https://owner.com/some/acl', {
156
- body: '@prefix acl: <http://www.w3.org/ns/auth/acl#>.\n' +
157
- '\n' +
158
- '<#alice> a acl:Authorization;\n' +
159
- ' acl:agent <https://owner.com/#me>;\n' +
160
- ' acl:accessTo <https://owner.com/some/resource>;\n' +
161
- ' acl:default <https://owner.com/some/resource>;\n' +
162
- ' acl:mode acl:Read, acl:Write, acl:Control.\n' +
163
- '<#bobAccessTo> a acl:Authorization;\n' +
164
- ' acl:agent <https://peer.com/#me>;\n' +
165
- ' acl:accessTo <https://owner.com/some/resource>;\n' +
166
- ' acl:mode acl:Read, acl:Control.\n' +
167
- '<#bobDefault> a acl:Authorization;\n' +
168
- ' acl:agent <https://peer.com/#me>;\n' +
169
- ' acl:default <https://owner.com/some/resource>;\n' +
170
- ' acl:mode acl:Write.\n',
171
- headers: [
172
- ['Content-Type', 'text/turtle']
173
- ],
174
- method: 'PUT'
175
- }]
176
- ])
177
- })
178
- })
179
-
180
- })
@@ -1,32 +0,0 @@
1
- import * as rdf from 'rdflib'
2
- import { getArchiveUrl, uniqueNodes } from '../src/util/utils'
3
-
4
- describe('utils', () => {
5
- describe('uniqueNodes', () => {
6
- it('exists', () => {
7
- expect(uniqueNodes).toBeInstanceOf(Function)
8
- })
9
- it('removed duplicates', async () => {
10
- const input = [ rdf.sym('https://a.com/'), rdf.sym('https://b.com/'), rdf.sym('https://a.com/'), rdf.sym('https://a.com/'), rdf.sym('https://c.com/'), ]
11
- const expected = [ rdf.sym('https://a.com/'), rdf.sym('https://b.com/'), rdf.sym('https://c.com/'), ]
12
- const result = uniqueNodes(input)
13
- expect(result).toEqual(expected)
14
-
15
- })
16
- it('handles an empty array', async () => {
17
- const result = await uniqueNodes([])
18
- expect(result).toEqual([])
19
- })
20
- })
21
-
22
- describe('getArchiveUrl', () => {
23
- it('produces the right URL in February', () => {
24
- const url = getArchiveUrl('https://example.com/inbox/asdf-qwer-asdf-qwer', new Date('7 Feb 2062 UTC'))
25
- expect(url).toEqual('https://example.com/inbox/archive/2062/02/07/asdf-qwer-asdf-qwer')
26
- })
27
- it('produces the right URL in November', () => {
28
- const url = getArchiveUrl('https://example.com/inbox/asdf-qwer-asdf-qwer', new Date('12 Nov 2012 UTC'))
29
- expect(url).toEqual('https://example.com/inbox/archive/2012/11/12/asdf-qwer-asdf-qwer')
30
- })
31
- })
32
- })
package/timestamp.sh DELETED
@@ -1,13 +0,0 @@
1
- #!/bin/bash
2
-
3
- echo "export default {"
4
- date -u '+buildTime: "%Y-%m-%dT%H:%M:%SZ",'
5
- git log | grep commit | head -1 | sed -e 's/ /: "/' | sed -e 's/$/",/'
6
- echo " npmInfo: {"
7
- npm version | sed 's/\x1b\[[0-9;:]*[mG]//g' | grep -v '^{' | while read line; do
8
- key=$(echo "$line" | cut -d ':' -f 1 | tr -d ' ')
9
- value=$(echo "$line" | cut -d ':' -f 2- | tr -d ' ')
10
- echo " \"${key}\": \"${value}\","
11
- done
12
- echo " }"
13
- echo "};"
package/tsconfig.json DELETED
@@ -1,77 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- /* Basic Options */
4
- "target": "ES2020", /* Allow top-level await and modern JS features. */
5
- "module": "ESNext", /* Use ESNext modules for Webpack/Babel compatibility. */
6
- "moduleResolution": "node", /* Use Node.js-style module resolution for Webpack compatibility. */
7
- "lib": [
8
- "dom",
9
- "es2015",
10
- "es2019"
11
- ] /* Specify library files to be included in the compilation. */,
12
- // "allowJs": true, /* Allow javascript files to be compiled. */
13
- // "checkJs": true, /* Report errors in .js files. */
14
- // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
15
- "declaration": true /* Generates corresponding '.d.ts' file. */,
16
- "declarationMap": true /* Generates a sourcemap for each corresponding '.d.ts' file. */,
17
- "sourceMap": true /* Generates corresponding '.map' file. */,
18
- // "outFile": "./", /* Concatenate and emit output to single file. */
19
-
20
- "outDir": "lib" /* Redirect output structure to the directory. */,
21
- "rootDir": "src/",
22
-
23
- // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
24
- // "composite": true, /* Enable project compilation */
25
- // "incremental": true, /* Enable incremental 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": false /* Enable all strict type-checking options. */,
35
- "noImplicitAny": false /* 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
-
49
- /* Module Resolution Options */
50
- // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
51
- // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
52
- // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
53
- // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
54
- // "typeRoots": [], /* List of folders to include type definitions from. */
55
- "typeRoots": [
56
- "node_modules/@types",
57
- "typings"
58
- ] /* List of folders to include type definitions from. */,
59
- // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
60
- "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
61
- // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
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
- "include": [
74
- "src/**/*"
75
- ],
76
- "exclude": ["node_modules"]
77
- }
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "include": ["test/**/*"],
4
- "compilerOptions": {
5
- "rootDir": ".",
6
- "noEmit": true
7
- }
8
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes