@live-change/relations-plugin 0.7.39 → 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.
package/boundTo.js CHANGED
@@ -1,13 +1,13 @@
1
- const {
1
+ import {
2
2
  defineProperties, defineIndex,
3
3
  processModelsAnnotation, generateId
4
- } = require('./utils.js')
4
+ } from './utils.js'
5
5
 
6
- const { defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineResetEvent } = require('./propertyEvents.js')
6
+ import { defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineResetEvent } from './propertyEvents.js'
7
7
 
8
- const { defineView, defineSetAction, defineUpdateAction, defineResetAction } = require('./singularRelationUtils.js')
8
+ import { defineView, defineSetAction, defineUpdateAction, defineResetAction } from './singularRelationUtils.js'
9
9
 
10
- module.exports = function(service, app) {
10
+ export default function(service, app) {
11
11
  processModelsAnnotation(service, app, 'boundTo', false, (config, context) => {
12
12
 
13
13
  context.relationWord = 'Friend'
package/boundToAny.js CHANGED
@@ -1,13 +1,13 @@
1
- const {
1
+ import {
2
2
  defineAnyProperties, defineAnyIndex,
3
3
  processModelsAnyAnnotation, generateAnyId
4
- } = require('./utilsAny.js')
4
+ } from './utilsAny.js'
5
5
 
6
- const { defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineResetEvent } = require('./propertyEvents.js')
6
+ import { defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineResetEvent } from './propertyEvents.js'
7
7
 
8
- const { defineView, defineSetAction, defineUpdateAction, defineResetAction } = require('./singularRelationUtils.js')
8
+ import { defineView, defineSetAction, defineUpdateAction, defineResetAction } from './singularRelationUtils.js'
9
9
 
10
- module.exports = function(service, app) {
10
+ export default function(service, app) {
11
11
  processModelsAnyAnnotation(service, app, 'boundToAny', false, (config, context) => {
12
12
 
13
13
  context.relationWord = 'Friend'
package/changeTriggers.js CHANGED
@@ -1,8 +1,7 @@
1
- const { extractObjectData, extractIdentifiers } = require("./dataUtils.js")
2
- const App = require("@live-change/framework")
3
- const {
1
+ import { extractObjectData, extractIdentifiers } from "./dataUtils.js"
2
+ import {
4
3
  TriggerDefinition
5
- } = App
4
+ } from "@live-change/framework"
6
5
 
7
6
  async function fireChangeTriggers(context, objectType, identifiers, object, oldData, data) {
8
7
  const { service, modelName, app } = context
@@ -255,7 +254,7 @@ function registerParentCopyTriggers(context, config) {
255
254
  }
256
255
  }
257
256
 
258
- module.exports = {
257
+ export {
259
258
  fireChangeTriggers,
260
259
  registerParentDeleteTriggers,
261
260
  registerParentCopyTriggers,
package/combinations.js CHANGED
@@ -14,4 +14,4 @@ function allCombinations(x) {
14
14
  return acc
15
15
  }
16
16
 
17
- module.exports = { combinations, allCombinations }
17
+ export { combinations, allCombinations }
package/dataUtils.js CHANGED
@@ -1,4 +1,4 @@
1
- const App = require("@live-change/framework");
1
+ import App from "@live-change/framework"
2
2
 
3
3
  function extractIdentifiers(otherPropertyNames, properties) {
4
4
  const identifiers = {}
@@ -18,7 +18,7 @@ function extractObjectData(writeableProperties, properties, defaults) {
18
18
  return App.utils.mergeDeep({}, defaults, JSON.parse(JSON.stringify(objectData)))
19
19
  }
20
20
 
21
- module.exports = {
21
+ export {
22
22
  extractIdentifiers,
23
23
  extractObjectData
24
24
  }
package/entity.js CHANGED
@@ -1,10 +1,12 @@
1
- const {
1
+ import {
2
2
  defineProperties, defineIndex,
3
3
  processModelsAnnotation, extractIdParts, extractIdentifiers, extractObjectData
4
- } = require('./utils.js')
5
- const App = require("@live-change/framework")
6
- const {fireChangeTriggers} = require("./changeTriggers.js");
7
- const { PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, EventDefinition } = App
4
+ } from './utils.js'
5
+ import { fireChangeTriggers } from "./changeTriggers.js"
6
+ import App from '@live-change/framework'
7
+ import {
8
+ PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, EventDefinition
9
+ } from "@live-change/framework"
8
10
 
9
11
  const annotation = 'entity'
10
12
 
@@ -195,7 +197,7 @@ function defineDeleteAction(config, context) {
195
197
  })
196
198
  }
197
199
 
198
- module.exports = function(service, app) {
200
+ export default function(service, app) {
199
201
  if (!service) throw new Error("no service")
200
202
  if (!app) throw new Error("no app")
201
203
 
package/index.js CHANGED
@@ -1,16 +1,17 @@
1
- const entity = require('./entity.js')
1
+ import entity from './entity.js'
2
2
 
3
- const propertyOf = require('./propertyOf.js')
4
- const itemOf = require('./itemOf.js')
3
+ import propertyOf from './propertyOf.js'
4
+ import itemOf from './itemOf.js'
5
5
 
6
- const propertyOfAny = require('./propertyOfAny.js')
7
- const itemOfAny = require('./itemOfAny.js')
6
+ import propertyOfAny from './propertyOfAny.js'
7
+ import itemOfAny from './itemOfAny.js'
8
8
 
9
- const relatedTo = require('./relatedTo.js')
10
- const relatedToAny = require('./relatedToAny.js')
9
+ import relatedTo from './relatedTo.js'
10
+ import relatedToAny from './relatedToAny.js'
11
+
12
+ import boundTo from './boundTo.js'
13
+ import boundToAny from './boundToAny.js'
11
14
 
12
- const boundTo = require('./boundTo.js')
13
- const boundToAny = require('./boundToAny.js')
14
15
 
15
16
  const processors = [
16
17
  entity,
@@ -20,10 +21,11 @@ const processors = [
20
21
  boundTo, boundToAny
21
22
  ]
22
23
 
23
- module.exports = function(app, services) {
24
+ const plugin = function(app, services) {
24
25
  app.defaultProcessors.push(...processors)
25
26
  }
27
+ plugin.processors = processors
26
28
 
27
- module.exports.processors = [
28
- ...processors
29
- ]
29
+ export default plugin
30
+
31
+ export { processors }
package/itemEvents.js CHANGED
@@ -1,5 +1,6 @@
1
- const App = require("@live-change/framework")
2
- const { PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, EventDefinition } = App
1
+ import {
2
+ PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, EventDefinition
3
+ } from "@live-change/framework"
3
4
 
4
5
  function defineCreatedEvent(config, context) {
5
6
  const {
@@ -72,7 +73,7 @@ function defineCopyEvent(config, context) {
72
73
  })
73
74
  }
74
75
 
75
- module.exports = {
76
+ export {
76
77
  defineCreatedEvent, defineUpdatedEvent, defineTransferredEvent, defineDeletedEvent,
77
78
  defineCopyEvent,
78
79
  }
package/itemOf.js CHANGED
@@ -1,20 +1,20 @@
1
- const {
1
+ import {
2
2
  defineProperties, defineIndexes,
3
3
  processModelsAnnotation, addAccessControlParents,
4
4
  defineDeleteByOwnerEvents, defineParentDeleteTriggers, defineParentCopyTriggers
5
- } = require('./utils.js')
5
+ } from './utils.js'
6
6
 
7
- const {
7
+ import {
8
8
  defineCreatedEvent, defineUpdatedEvent, defineDeletedEvent, defineTransferredEvent,
9
9
  defineCopyEvent
10
- } = require('./itemEvents.js')
10
+ } from './itemEvents.js'
11
11
 
12
- const {
12
+ import {
13
13
  defineView, defineCreateAction, defineUpdateAction, defineDeleteAction, defineSortIndex,
14
14
  defineCopyAction, defineCopyOnParentCopyTrigger
15
- } = require('./pluralRelationUtils.js')
15
+ } from './pluralRelationUtils.js'
16
16
 
17
- module.exports = function(service, app) {
17
+ export default function(service, app) {
18
18
  processModelsAnnotation(service, app, 'itemOf', false, (config, context) => {
19
19
 
20
20
  context.relationWord = 'Item'
package/itemOfAny.js CHANGED
@@ -1,18 +1,18 @@
1
- const {
1
+ import {
2
2
  defineAnyProperties, defineAnyIndexes,
3
3
  processModelsAnyAnnotation, addAccessControlAnyParents, generateAnyId, defineDeleteByOwnerEvents,
4
4
  defineParentDeleteTrigger
5
- } = require('./utilsAny.js')
5
+ } from './utilsAny.js'
6
6
 
7
- const {
7
+ import {
8
8
  defineCreatedEvent, defineUpdatedEvent, defineDeletedEvent, defineTransferredEvent,
9
- } = require('./itemEvents.js')
9
+ } from './itemEvents.js'
10
10
 
11
- const {
11
+ import {
12
12
  defineView, defineCreateAction, defineUpdateAction, defineDeleteAction, defineSortIndex
13
- } = require('./pluralRelationAnyUtils.js')
13
+ } from './pluralRelationAnyUtils.js'
14
14
 
15
- module.exports = function(service, app) {
15
+ export default function(service, app) {
16
16
  processModelsAnyAnnotation(service, app, 'itemOfAny',false, (config, context) => {
17
17
 
18
18
  context.relationWord = 'Item'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/relations-plugin",
3
- "version": "0.7.39",
3
+ "version": "0.8.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -20,9 +20,10 @@
20
20
  "name": "Michał Łaszczewski",
21
21
  "url": "https://www.viamage.com/"
22
22
  },
23
+ "type": "module",
23
24
  "dependencies": {
24
- "@live-change/framework": "^0.7.39",
25
+ "@live-change/framework": "^0.8.1",
25
26
  "pluralize": "^8.0.0"
26
27
  },
27
- "gitHead": "9e9cd47f2fb1c3c82b20fdddbc5505c99e1e1c68"
28
+ "gitHead": "d26056b63edb7fecb98c6b9ee14eba859360f900"
28
29
  }
@@ -1,12 +1,13 @@
1
- const App = require("@live-change/framework")
2
- const { PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, EventDefinition } = App
3
- const { extractTypeAndIdParts, extractIdentifiersWithTypes, prepareAccessControl } = require("./utilsAny.js")
4
- const { extractObjectData, extractIdentifiers} = require("./utils.js")
1
+ import App from "@live-change/framework"
5
2
  const { extractRange } = App
3
+ import {
4
+ PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, EventDefinition
5
+ } from "@live-change/framework"
6
+ import { extractTypeAndIdParts, extractIdentifiersWithTypes, prepareAccessControl } from "./utilsAny.js"
7
+ import { extractObjectData, extractIdentifiers} from "./utils.js"
8
+ import { fireChangeTriggers } from "./changeTriggers.js"
6
9
 
7
- const { fireChangeTriggers } = require("./changeTriggers.js")
8
-
9
- const pluralize = require('pluralize')
10
+ import pluralize from 'pluralize'
10
11
 
11
12
  function defineView(config, context) {
12
13
  const { service, modelRuntime, otherPropertyNames, joinedOthersPropertyName, joinedOthersClassName,
@@ -194,4 +195,4 @@ function defineSortIndex(context, sortFields) {
194
195
  })
195
196
  }
196
197
 
197
- module.exports = { defineView, defineCreateAction, defineUpdateAction, defineDeleteAction, defineSortIndex }
198
+ export { defineView, defineCreateAction, defineUpdateAction, defineDeleteAction, defineSortIndex }
@@ -1,9 +1,10 @@
1
- const App = require("@live-change/framework")
2
- const { PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, TriggerDefinition } = App
3
- const { extractIdParts, extractIdentifiers, extractObjectData, prepareAccessControl } = require("./utils.js")
4
-
5
- const pluralize = require('pluralize')
6
- const { fireChangeTriggers } = require("./changeTriggers.js")
1
+ import App from '@live-change/framework'
2
+ import {
3
+ PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, TriggerDefinition
4
+ } from "@live-change/framework"
5
+ import { extractIdParts, extractIdentifiers, extractObjectData, prepareAccessControl } from "./utils.js"
6
+ import { fireChangeTriggers } from "./changeTriggers.js"
7
+ import pluralize from 'pluralize'
7
8
 
8
9
  function defineView(config, context) {
9
10
  const { service, modelRuntime, otherPropertyNames, joinedOthersPropertyName, joinedOthersClassName,
@@ -338,7 +339,7 @@ function defineSortIndex(context, sortFields) {
338
339
  })
339
340
  }
340
341
 
341
- module.exports = {
342
+ export {
342
343
  defineView,
343
344
  defineCreateAction, defineUpdateAction, defineDeleteAction, defineCopyAction,
344
345
  defineCopyOnParentCopyTrigger,
package/propertyEvents.js CHANGED
@@ -1,5 +1,6 @@
1
- const App = require("@live-change/framework")
2
- const { PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, EventDefinition } = App
1
+ import {
2
+ PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, EventDefinition
3
+ } from '@live-change/framework'
3
4
 
4
5
  function defineSetEvent(config, context, generateId) {
5
6
  const {
@@ -65,6 +66,6 @@ function defineResetEvent(config, context, generateId) {
65
66
  })
66
67
  }
67
68
 
68
- module.exports = {
69
+ export {
69
70
  defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineResetEvent
70
71
  }
package/propertyOf.js CHANGED
@@ -1,16 +1,16 @@
1
- const {
1
+ import {
2
2
  defineProperties, defineIndexes,
3
3
  processModelsAnnotation, generateId, addAccessControlParents,
4
4
  defineDeleteByOwnerEvents, defineParentDeleteTriggers
5
- } = require('./utils.js')
5
+ } from './utils.js'
6
6
 
7
- const { defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineResetEvent } = require('./propertyEvents.js')
7
+ import { defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineResetEvent } from './propertyEvents.js'
8
8
 
9
- const {
9
+ import {
10
10
  defineView, defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction
11
- } = require('./singularRelationUtils.js')
11
+ } from './singularRelationUtils.js'
12
12
 
13
- module.exports = function(service, app) {
13
+ export default function(service, app) {
14
14
  processModelsAnnotation(service, app, 'propertyOf', false, (config, context) => {
15
15
 
16
16
  context.relationWord = 'Property'
package/propertyOfAny.js CHANGED
@@ -1,19 +1,18 @@
1
- const {
1
+ import {
2
2
  defineAnyProperties, defineAnyIndexes,
3
3
  processModelsAnyAnnotation, generateAnyId, addAccessControlAnyParents,
4
4
  defineDeleteByOwnerEvents, defineParentDeleteTrigger
5
- } = require('./utilsAny.js')
5
+ } from './utilsAny.js'
6
6
 
7
- const {
7
+ import {
8
8
  defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineResetEvent
9
- } = require('./propertyEvents.js')
9
+ } from './propertyEvents.js'
10
10
 
11
- const {
11
+ import {
12
12
  defineObjectView, defineRangeViews, defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction
13
- } = require('./singularRelationAnyUtils.js')
14
- const {defineResetByOwner} = require("./propertyEvents");
13
+ } from './singularRelationAnyUtils.js'
15
14
 
16
- module.exports = function(service, app) {
15
+ export default function(service, app) {
17
16
  processModelsAnyAnnotation(service, app, 'propertyOfAny', false, (config, context) => {
18
17
 
19
18
  context.relationWord = 'Property'
package/relatedTo.js CHANGED
@@ -1,17 +1,16 @@
1
- const {
2
- defineProperties, defineIndex,
3
- processModelsAnnotation
4
- } = require('./utils.js')
1
+ import {
2
+ defineProperties, defineIndex, processModelsAnnotation
3
+ } from './utils.js'
5
4
 
6
- const {
5
+ import {
7
6
  defineCreatedEvent, defineUpdatedEvent, defineDeletedEvent, defineTransferredEvent,
8
- } = require('./itemEvents.js')
7
+ } from './itemEvents.js'
9
8
 
10
- const {
9
+ import {
11
10
  defineView, defineCreateAction, defineUpdateAction, defineDeleteAction, defineSortIndex
12
- } = require('./pluralRelationUtils.js')
11
+ } from './pluralRelationUtils.js'
13
12
 
14
- module.exports = function(service, app) {
13
+ export default function(service, app) {
15
14
  processModelsAnnotation(service, app, 'relatedTo', true, (config, context) => {
16
15
 
17
16
  context.relationWord = 'Friend'
package/relatedToAny.js CHANGED
@@ -1,17 +1,16 @@
1
- const {
2
- defineAnyProperties, defineAnyIndex,
3
- processModelsAnyAnnotation
4
- } = require('./utilsAny.js')
1
+ import {
2
+ defineAnyProperties, defineAnyIndex, processModelsAnyAnnotation
3
+ } from './utilsAny.js'
5
4
 
6
- const {
5
+ import {
7
6
  defineCreatedEvent, defineUpdatedEvent, defineDeletedEvent, defineTransferredEvent,
8
- } = require('./itemEvents.js')
7
+ } from './itemEvents.js'
9
8
 
10
- const {
9
+ import {
11
10
  defineView, defineCreateAction, defineUpdateAction, defineDeleteAction, defineSortIndex
12
- } = require('./pluralRelationAnyUtils.js')
11
+ } from './pluralRelationAnyUtils.js'
13
12
 
14
- module.exports = function(service, app) {
13
+ export default function(service, app) {
15
14
  processModelsAnyAnnotation(service, app, 'relatedToAny',true, (config, context) => {
16
15
 
17
16
  context.relationWord = 'Friend'
@@ -1,11 +1,13 @@
1
- const App = require("@live-change/framework")
2
- const { PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition } = App
3
- const { extractTypeAndIdParts, extractIdentifiersWithTypes, generateAnyId, prepareAccessControl } = require("./utilsAny.js")
4
- const { extractObjectData } = require("./utils.js")
5
- const { allCombinations } = require("./combinations.js")
1
+ import App from '@live-change/framework'
2
+ import { PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition } from '@live-change/framework'
3
+ import {
4
+ extractTypeAndIdParts, extractIdentifiersWithTypes, generateAnyId, prepareAccessControl
5
+ } from './utilsAny.js'
6
+ import { extractObjectData } from "./utils.js"
7
+ import { allCombinations } from "./combinations.js"
8
+ import { fireChangeTriggers } from "./changeTriggers.js"
6
9
 
7
- const pluralize = require('pluralize')
8
- const {fireChangeTriggers} = require("./changeTriggers.js");
10
+ import pluralize from 'pluralize'
9
11
 
10
12
  function createIdentifiersProperties(keys) {
11
13
  const identifiers = {}
@@ -241,7 +243,7 @@ function defineResetAction(config, context) {
241
243
  })
242
244
  }
243
245
 
244
- module.exports = {
246
+ export {
245
247
  defineObjectView, defineRangeViews,
246
248
  defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction
247
249
  }
@@ -1,9 +1,8 @@
1
- const App = require("@live-change/framework")
2
- const { PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition } = App
3
- const {
1
+ import { PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition } from "@live-change/framework"
2
+ import {
4
3
  extractIdentifiers, extractObjectData, generateId, extractIdParts, prepareAccessControl
5
- } = require("./utils.js")
6
- const {fireChangeTriggers} = require("./changeTriggers.js");
4
+ } from "./utils.js"
5
+ import { fireChangeTriggers } from "./changeTriggers.js"
7
6
 
8
7
  function defineView(config, context) {
9
8
  const { service, modelRuntime, otherPropertyNames, joinedOthersPropertyName, joinedOthersClassName,
@@ -189,4 +188,4 @@ function defineResetAction(config, context) {
189
188
  })
190
189
  }
191
190
 
192
- module.exports = { defineView, defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction }
191
+ export { defineView, defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction }
package/utils.js CHANGED
@@ -1,16 +1,16 @@
1
- const App = require("@live-change/framework")
1
+ import App from "@live-change/framework"
2
2
  const app = App.app()
3
- const { allCombinations } = require("./combinations.js")
4
- const {
3
+ import { allCombinations } from "./combinations.js"
4
+ import {
5
5
  fireChangeTriggers, registerParentDeleteTriggers, registerParentCopyTriggers
6
- } = require("./changeTriggers.js")
7
- const {
6
+ } from "./changeTriggers.js"
7
+ import {
8
8
  PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, EventDefinition, TriggerDefinition
9
- } = App
9
+ } from "@live-change/framework"
10
10
 
11
- const {
11
+ import {
12
12
  extractObjectData, extractIdentifiers
13
- } = require('./dataUtils.js')
13
+ } from './dataUtils.js'
14
14
 
15
15
  function extractIdParts(otherPropertyNames, properties) {
16
16
  const idParts = []
@@ -188,7 +188,7 @@ function defineParentCopyTriggers(config, context) {
188
188
  }
189
189
 
190
190
 
191
- module.exports = {
191
+ export {
192
192
  extractIdParts, extractIdentifiers, extractObjectData, defineProperties, defineIndex, defineIndexes,
193
193
  processModelsAnnotation, generateId, addAccessControlParents, prepareAccessControl,
194
194
  defineDeleteByOwnerEvents, defineParentDeleteTriggers, defineParentCopyTriggers,
package/utilsAny.js CHANGED
@@ -1,11 +1,11 @@
1
- const App = require("@live-change/framework")
1
+ import App from "@live-change/framework"
2
2
  const app = App.app()
3
- const {
3
+ import {
4
4
  PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, EventDefinition, TriggerDefinition
5
- } = App
6
- const { allCombinations } = require("./combinations.js")
7
- const { fireChangeTriggers, registerParentDeleteTriggers } = require("./changeTriggers")
8
- const { extractObjectData } = require("./dataUtils.js")
5
+ } from "@live-change/framework"
6
+ import { allCombinations } from "./combinations.js"
7
+ import { fireChangeTriggers, registerParentDeleteTriggers } from "./changeTriggers.js"
8
+ import { extractObjectData } from "./dataUtils.js"
9
9
 
10
10
  function extractTypeAndIdParts(otherPropertyNames, properties) {
11
11
  const typeAndIdParts = []
@@ -192,7 +192,7 @@ function defineParentDeleteTrigger(config, context) {
192
192
  registerParentDeleteTriggers(context, config)
193
193
  }
194
194
 
195
- module.exports = {
195
+ export {
196
196
  extractTypeAndIdParts, extractIdentifiersWithTypes, defineAnyProperties,
197
197
  defineAnyIndex, defineAnyIndexes,
198
198
  processModelsAnyAnnotation, generateAnyId,
package/tests/tests.js DELETED
@@ -1,220 +0,0 @@
1
- const test = require('blue-tape')
2
- const r = require('rethinkdb')
3
- const testUtils = require('rethink-event-sourcing/tape-test-utils.js')
4
- const crypto = require('crypto')
5
-
6
- test('Session service login, logout', t => {
7
- t.plan(9)
8
-
9
- let conn
10
-
11
- testUtils.connectToDatabase(t, r, (connection) => conn = connection)
12
-
13
- let sessionId = crypto.randomBytes(24).toString('hex')
14
- let userId = crypto.randomBytes(24).toString('hex')
15
-
16
- t.test('create user', t => {
17
- t.plan(2)
18
-
19
- testUtils.runCommand(t, r, 'user', {
20
- type: 'create',
21
- userId: userId
22
- }, (cId) => { }).then(
23
- result => {
24
- }
25
- )
26
-
27
- t.test('check if user exists', t=> {
28
- t.plan(2)
29
- setTimeout(()=>{
30
- r.table('user').get(userId).run(conn).then(
31
- userRow => {
32
- if(userRow) t.pass('user exists')
33
- t.equals(userRow.display, 'unknown', 'user display name unknown')
34
- }
35
- ).catch(t.fail)
36
- }, 150)
37
- })
38
-
39
- })
40
-
41
- t.test('create session', t => {
42
- t.plan(2)
43
-
44
- testUtils.runCommand(t, r, 'session', {
45
- type: 'createSessionIfNotExists',
46
- sessionId: sessionId
47
- }, (cId) => {})
48
-
49
- t.test('check if session exists', t=> {
50
- t.plan(1)
51
- setTimeout(()=>{
52
- r.table('session').get(sessionId).run(conn).then(
53
- session => {
54
- if(session) t.pass('session exists')
55
- else t.fail('session not found')
56
- }
57
- ).catch(t.fail)
58
- }, 250)
59
- })
60
-
61
- })
62
-
63
- t.test('login', t => {
64
- t.plan(2)
65
-
66
- testUtils.pushEvents(t, r, 'session', [
67
- {
68
- type: "loggedIn",
69
- sessionId: sessionId,
70
- userId: userId,
71
- roles: [],
72
- expire: null
73
- }
74
- ])
75
-
76
- t.test('check if logged in', t=> {
77
- t.plan(2)
78
- setTimeout(()=>{
79
- r.table('session').get(sessionId).run(conn).then(
80
- session => {
81
- t.equal(session.userId, userId, 'user id match')
82
- t.pass('logged in')
83
- }
84
- ).catch(t.fail)
85
- }, 150)
86
- })
87
-
88
- })
89
-
90
- let commandId
91
-
92
- t.test('logout', t => {
93
- t.plan(3)
94
-
95
- testUtils.runCommand(t, r, 'session', {
96
- type: 'logout',
97
- sessionId: sessionId
98
- }, (cId) => commandId = cId)
99
-
100
- t.test('Check if there are events generated', t => {
101
- t.plan(2)
102
-
103
- setTimeout(()=>{
104
- testUtils.getGeneratedEvents(r, 'session', commandId,
105
- (events) => {
106
- t.equal(events.length, 1, "generated one event")
107
- t.equal(events[0].type, "loggedOut", "loggedOut event found")
108
- })
109
- }, 150)
110
-
111
- })
112
-
113
- t.test('check if logged off', t=> {
114
- t.plan(2)
115
- setTimeout(()=>{
116
- r.table('session').get(sessionId).run(conn).then(
117
- session => {
118
- console.log("session", session)
119
- t.equal(session.userId, undefined, 'userId not exists')
120
- t.pass('logged out')
121
- }
122
- ).catch(t.fail)
123
- }, 150)
124
- })
125
-
126
- })
127
-
128
- t.test('second login', t => {
129
- t.plan(2)
130
-
131
- testUtils.pushEvents(t, r, 'session', [
132
- {
133
- type: "loggedIn",
134
- sessionId: sessionId,
135
- userId: userId,
136
- roles: [],
137
- expire: null
138
- }
139
- ])
140
-
141
- t.test('check if logged in', t=> {
142
- t.plan(2)
143
- setTimeout(()=>{
144
- r.table('session').get(sessionId).run(conn).then(
145
- session => {
146
- t.equal(session.userId, userId, 'user id match')
147
- t.pass('logged in')
148
- }
149
- ).catch(t.fail)
150
- }, 150)
151
- })
152
- })
153
-
154
- t.test('change user roles, check session roles', t=> {
155
- t.plan(3)
156
-
157
- testUtils.runCommand(t, r, 'user', {
158
- type: 'updateRoles',
159
- userId: userId,
160
- roles: ['test_object']
161
- }, (cId) => { }).then(
162
- result => {
163
- }
164
- )
165
-
166
- t.test('check if user roles is changed', t => {
167
- t.plan(1)
168
- setTimeout( () => {
169
- r.table('user').get(userId).run(conn).then(
170
- user => {
171
- t.deepEqual(user.roles, [ 'test_object' ], 'roles are updated correctly')
172
- }
173
- ).catch( t.fail )
174
- }, 150)
175
- })
176
-
177
- t.test('check if session roles is changed', t => {
178
- t.plan(1)
179
- setTimeout( () => {
180
- r.table('session').get(sessionId).run(conn).then(
181
- session => {
182
- t.deepEqual(session.roles, [ 'test_object' ], 'roles are updated correctly')
183
- }
184
- ).catch( t.fail )
185
- }, 300)
186
- })
187
-
188
- })
189
-
190
- t.test('delete user and check if session is logged out', t => {
191
- t.plan(2)
192
-
193
- testUtils.runCommand(t, r, 'user', {
194
- type: 'remove',
195
- userId: userId
196
- }, (cId) => { }).then(result => {})
197
-
198
- t.test('check if logged out', t=> {
199
- t.plan(2)
200
- setTimeout(()=>{
201
- r.table('session').get(sessionId).run(conn).then(
202
- session => {
203
- console.log("session", session)
204
- t.equal(session.userId, undefined, 'userId not exists')
205
- t.pass('logged out')
206
- }
207
- ).catch(t.fail)
208
- }, 150)
209
- })
210
-
211
- })
212
-
213
- t.test('close connection', t => {
214
- conn.close(() => {
215
- t.pass('closed')
216
- t.end()
217
- })
218
- })
219
-
220
- })