[#667] sanity checks for Yjs caveats. In dev_mode, objects inserted into Yjs can't be manipulated.
This commit is contained in:
		
							parent
							
								
									3bf44b9850
								
							
						
					
					
						commit
						8152cf81cb
					
				
							
								
								
									
										9
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										9
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							@ -9,7 +9,7 @@
 | 
				
			|||||||
      "version": "13.6.19",
 | 
					      "version": "13.6.19",
 | 
				
			||||||
      "license": "MIT",
 | 
					      "license": "MIT",
 | 
				
			||||||
      "dependencies": {
 | 
					      "dependencies": {
 | 
				
			||||||
        "lib0": "^0.2.86"
 | 
					        "lib0": "^0.2.98"
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      "devDependencies": {
 | 
					      "devDependencies": {
 | 
				
			||||||
        "@rollup/plugin-commonjs": "^24.0.1",
 | 
					        "@rollup/plugin-commonjs": "^24.0.1",
 | 
				
			||||||
@ -2785,13 +2785,14 @@
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "node_modules/lib0": {
 | 
					    "node_modules/lib0": {
 | 
				
			||||||
      "version": "0.2.88",
 | 
					      "version": "0.2.98",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/lib0/-/lib0-0.2.88.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/lib0/-/lib0-0.2.98.tgz",
 | 
				
			||||||
      "integrity": "sha512-KyroiEvCeZcZEMx5Ys+b4u4eEBbA1ch7XUaBhYpwa/nPMrzTjUhI4RfcytmQfYoTBPcdyx+FX6WFNIoNuJzJfQ==",
 | 
					      "integrity": "sha512-XteTiNO0qEXqqweWx+b21p/fBnNHUA1NwAtJNJek1oPrewEZs2uiT4gWivHKr9GqCjDPAhchz0UQO8NwU3bBNA==",
 | 
				
			||||||
      "dependencies": {
 | 
					      "dependencies": {
 | 
				
			||||||
        "isomorphic.js": "^0.2.4"
 | 
					        "isomorphic.js": "^0.2.4"
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      "bin": {
 | 
					      "bin": {
 | 
				
			||||||
 | 
					        "0ecdsa-generate-keypair": "bin/0ecdsa-generate-keypair.js",
 | 
				
			||||||
        "0gentesthtml": "bin/gentesthtml.js",
 | 
					        "0gentesthtml": "bin/gentesthtml.js",
 | 
				
			||||||
        "0serve": "bin/0serve.js"
 | 
					        "0serve": "bin/0serve.js"
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
 | 
				
			|||||||
@ -13,7 +13,7 @@
 | 
				
			|||||||
  },
 | 
					  },
 | 
				
			||||||
  "scripts": {
 | 
					  "scripts": {
 | 
				
			||||||
    "clean": "rm -rf dist docs",
 | 
					    "clean": "rm -rf dist docs",
 | 
				
			||||||
    "test": "npm run dist && node ./dist/tests.cjs --repetition-time 50",
 | 
					    "test": "npm run dist && NODE_ENV=development node ./dist/tests.cjs --repetition-time 50",
 | 
				
			||||||
    "test-extensive": "npm run lint && npm run dist && node ./dist/tests.cjs --production --repetition-time 10000",
 | 
					    "test-extensive": "npm run lint && npm run dist && node ./dist/tests.cjs --production --repetition-time 10000",
 | 
				
			||||||
    "dist": "npm run clean && rollup -c && tsc",
 | 
					    "dist": "npm run clean && rollup -c && tsc",
 | 
				
			||||||
    "watch": "rollup -wc",
 | 
					    "watch": "rollup -wc",
 | 
				
			||||||
@ -76,7 +76,7 @@
 | 
				
			|||||||
  },
 | 
					  },
 | 
				
			||||||
  "homepage": "https://docs.yjs.dev",
 | 
					  "homepage": "https://docs.yjs.dev",
 | 
				
			||||||
  "dependencies": {
 | 
					  "dependencies": {
 | 
				
			||||||
    "lib0": "^0.2.86"
 | 
					    "lib0": "^0.2.98"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "devDependencies": {
 | 
					  "devDependencies": {
 | 
				
			||||||
    "@rollup/plugin-commonjs": "^24.0.1",
 | 
					    "@rollup/plugin-commonjs": "^24.0.1",
 | 
				
			||||||
 | 
				
			|||||||
@ -2,6 +2,11 @@ import {
 | 
				
			|||||||
  UpdateEncoderV1, UpdateEncoderV2, UpdateDecoderV1, UpdateDecoderV2, Transaction, Item, StructStore // eslint-disable-line
 | 
					  UpdateEncoderV1, UpdateEncoderV2, UpdateDecoderV1, UpdateDecoderV2, Transaction, Item, StructStore // eslint-disable-line
 | 
				
			||||||
} from '../internals.js'
 | 
					} from '../internals.js'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import * as env from 'lib0/environment'
 | 
				
			||||||
 | 
					import * as object from 'lib0/object'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const isDevMode = env.getVariable('node_env') === 'development'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export class ContentAny {
 | 
					export class ContentAny {
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * @param {Array<any>} arr
 | 
					   * @param {Array<any>} arr
 | 
				
			||||||
@ -11,6 +16,7 @@ export class ContentAny {
 | 
				
			|||||||
     * @type {Array<any>}
 | 
					     * @type {Array<any>}
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    this.arr = arr
 | 
					    this.arr = arr
 | 
				
			||||||
 | 
					    isDevMode && object.deepFreeze(arr)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
 | 
				
			|||||||
@ -4,6 +4,9 @@ import * as Y from '../src/index.js'
 | 
				
			|||||||
import * as t from 'lib0/testing'
 | 
					import * as t from 'lib0/testing'
 | 
				
			||||||
import * as prng from 'lib0/prng'
 | 
					import * as prng from 'lib0/prng'
 | 
				
			||||||
import * as math from 'lib0/math'
 | 
					import * as math from 'lib0/math'
 | 
				
			||||||
 | 
					import * as env from 'lib0/environment'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const isDevMode = env.getVariable('node_env') === 'development'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @param {t.TestCase} tc
 | 
					 * @param {t.TestCase} tc
 | 
				
			||||||
@ -17,6 +20,28 @@ export const testBasicUpdate = tc => {
 | 
				
			|||||||
  t.compare(doc2.getArray('array').toArray(), ['hi'])
 | 
					  t.compare(doc2.getArray('array').toArray(), ['hi'])
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * @param {t.TestCase} tc
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					export const testFailsObjectManipulationInDevMode = tc => {
 | 
				
			||||||
 | 
					  if (isDevMode) {
 | 
				
			||||||
 | 
					    t.info('running in dev mode')
 | 
				
			||||||
 | 
					    const doc = new Y.Doc()
 | 
				
			||||||
 | 
					    const a = [1, 2, 3]
 | 
				
			||||||
 | 
					    const b = { o: 1 }
 | 
				
			||||||
 | 
					    doc.getArray('test').insert(0, [a])
 | 
				
			||||||
 | 
					    doc.getMap('map').set('k', b)
 | 
				
			||||||
 | 
					    t.fails(() => {
 | 
				
			||||||
 | 
					      a[0] = 42
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					    t.fails(() => {
 | 
				
			||||||
 | 
					      b.o = 42
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    t.info('not in dev mode')
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @param {t.TestCase} tc
 | 
					 * @param {t.TestCase} tc
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user