teamplay 0.1.9 → 0.1.11

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/index.js CHANGED
@@ -15,7 +15,7 @@ export const $ = _getRootSignal({ rootId: GLOBAL_ROOT_ID, rootFunction: universa
15
15
  export default $
16
16
  export { default as sub } from './react/universalSub.js'
17
17
  export { default as observer } from './react/observer.js'
18
- export { connection, setConnection, getConnection, fetchOnly, setFetchOnly } from './orm/connection.js'
18
+ export { connection, setConnection, getConnection, fetchOnly, setFetchOnly, publicOnly, setPublicOnly } from './orm/connection.js'
19
19
  export { GUID_PATTERN, hasMany, hasOne, hasManyFlags, belongsTo, pickFormFields } from '@teamplay/schema'
20
20
  export { aggregation, aggregationHeader } from '@teamplay/utils/aggregation'
21
21
 
package/orm/Signal.js CHANGED
@@ -16,6 +16,7 @@ import { get as _get, set as _set, del as _del, setPublicDoc as _setPublicDoc }
16
16
  import getSignal, { rawSignal } from './getSignal.js'
17
17
  import { IS_QUERY, HASH, QUERIES } from './Query.js'
18
18
  import { ROOT_FUNCTION, getRoot } from './Root.js'
19
+ import { publicOnly } from './connection.js'
19
20
 
20
21
  export const SEGMENTS = Symbol('path segments targeting the particular node in the data tree')
21
22
 
@@ -82,10 +83,40 @@ export default class Signal extends Function {
82
83
  if (isPublicCollection(this[SEGMENTS][0])) {
83
84
  await _setPublicDoc(this[SEGMENTS], value)
84
85
  } else {
86
+ if (publicOnly) throw Error(ERRORS.publicOnly)
85
87
  _set(this[SEGMENTS], value)
86
88
  }
87
89
  }
88
90
 
91
+ // TODO: implement a json0 operation for push
92
+ async push (value) {
93
+ if (arguments.length > 1) throw Error('Signal.push() expects a single argument')
94
+ if (this[SEGMENTS].length < 2) throw Error('Can\'t push to a collection or root signal')
95
+ if (this[IS_QUERY]) throw Error('Signal.push() can\'t be used on a query signal')
96
+ const array = this.get()
97
+ await this[array?.length || 0].set(value)
98
+ }
99
+
100
+ // TODO: implement a json0 operation for pop
101
+ async pop () {
102
+ if (arguments.length > 0) throw Error('Signal.pop() does not accept any arguments')
103
+ if (this[SEGMENTS].length < 2) throw Error('Can\'t pop from a collection or root signal')
104
+ if (this[IS_QUERY]) throw Error('Signal.pop() can\'t be used on a query signal')
105
+ const array = this.get()
106
+ if (!Array.isArray(array) || array.length === 0) return
107
+ await this[array.length - 1].del()
108
+ }
109
+
110
+ // TODO: implement a json0 operation for unshift
111
+ async unshift (value) {
112
+ throw Error('Signal.unshift() is not implemented yet')
113
+ }
114
+
115
+ // TODO: implement a json0 operation for shift
116
+ async shift () {
117
+ throw Error('Signal.shift() is not implemented yet')
118
+ }
119
+
89
120
  // TODO: make it use an actual increment json0 operation on public collections
90
121
  async increment (value) {
91
122
  if (arguments.length > 1) throw Error('Signal.increment() expects a single argument')
@@ -116,6 +147,7 @@ export default class Signal extends Function {
116
147
  if (this[SEGMENTS].length === 1) throw Error('Can\'t delete the whole collection')
117
148
  await _setPublicDoc(this[SEGMENTS], undefined, true)
118
149
  } else {
150
+ if (publicOnly) throw Error(ERRORS.publicOnly)
119
151
  _del(this[SEGMENTS])
120
152
  }
121
153
  }
@@ -213,5 +245,9 @@ const ERRORS = {
213
245
  noRootFunction: `
214
246
  Root signal does not have a root function set.
215
247
  You must use getRootSignal({ rootId, rootFunction }) to create a root signal.
248
+ `,
249
+ publicOnly: `
250
+ Can't modify private collections data when 'publicOnly' is enabled.
251
+ On the server you can only work with public collections.
216
252
  `
217
253
  }
package/orm/connection.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export let connection
2
2
  export let fetchOnly
3
+ export let publicOnly
3
4
 
4
5
  export function setConnection (_connection) {
5
6
  connection = _connection
@@ -14,6 +15,10 @@ export function setFetchOnly (_fetchOnly) {
14
15
  fetchOnly = _fetchOnly
15
16
  }
16
17
 
18
+ export function setPublicOnly (_publicOnly) {
19
+ publicOnly = _publicOnly
20
+ }
21
+
17
22
  const ERRORS = {
18
23
  notSet: `
19
24
  Connection is not set.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teamplay",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "Full-stack signals ORM with multiplayer",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -23,12 +23,12 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@nx-js/observer-util": "^4.1.3",
26
- "@teamplay/backend": "^0.1.9",
27
- "@teamplay/cache": "^0.1.9",
28
- "@teamplay/channel": "^0.1.9",
29
- "@teamplay/debug": "^0.1.9",
30
- "@teamplay/schema": "^0.1.9",
31
- "@teamplay/utils": "^0.1.9",
26
+ "@teamplay/backend": "^0.1.11",
27
+ "@teamplay/cache": "^0.1.11",
28
+ "@teamplay/channel": "^0.1.11",
29
+ "@teamplay/debug": "^0.1.11",
30
+ "@teamplay/schema": "^0.1.11",
31
+ "@teamplay/utils": "^0.1.11",
32
32
  "diff-match-patch": "^1.0.5",
33
33
  "events": "^3.3.0",
34
34
  "json0-ot-diff": "^1.1.2",
@@ -63,5 +63,5 @@
63
63
  ]
64
64
  },
65
65
  "license": "MIT",
66
- "gitHead": "e6a092cd5d261ac516d96b7fbd6c7087e40c4398"
66
+ "gitHead": "1fbdde069e50c6cee18d8bb71c43ed5b06367cac"
67
67
  }
package/server.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import createChannel from '@teamplay/channel/server'
2
- import { connection, setConnection, setFetchOnly } from './orm/connection.js'
2
+ import { connection, setConnection, setFetchOnly, setPublicOnly } from './orm/connection.js'
3
3
 
4
4
  export { default as ShareDB } from 'sharedb'
5
5
  export {
@@ -9,11 +9,13 @@ export {
9
9
 
10
10
  export function initConnection (backend, {
11
11
  fetchOnly = true,
12
+ publicOnly = true,
12
13
  ...options
13
14
  } = {}) {
14
15
  if (!backend) throw Error('backend is required')
15
16
  if (connection) throw Error('Connection already exists')
16
17
  setConnection(backend.connect())
17
18
  setFetchOnly(fetchOnly)
19
+ setPublicOnly(publicOnly)
18
20
  return createChannel(backend, options)
19
21
  }