Use single quotes for identifiers
This commit is contained in:
		
					parent
					
						
							
								819671a23a
							
						
					
				
			
			
				commit
				
					
						24f4ad53bc
					
				
			
		
					 15 changed files with 73 additions and 73 deletions
				
			
		| 
						 | 
					@ -11,7 +11,7 @@ const PATH = 'attachments.noindex';
 | 
				
			||||||
//      getPath :: AbsolutePath -> AbsolutePath
 | 
					//      getPath :: AbsolutePath -> AbsolutePath
 | 
				
			||||||
exports.getPath = (userDataPath) => {
 | 
					exports.getPath = (userDataPath) => {
 | 
				
			||||||
  if (!isString(userDataPath)) {
 | 
					  if (!isString(userDataPath)) {
 | 
				
			||||||
    throw new TypeError('"userDataPath" must be a string');
 | 
					    throw new TypeError("'userDataPath' must be a string");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  return path.join(userDataPath, PATH);
 | 
					  return path.join(userDataPath, PATH);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -19,7 +19,7 @@ exports.getPath = (userDataPath) => {
 | 
				
			||||||
//      ensureDirectory :: AbsolutePath -> IO Unit
 | 
					//      ensureDirectory :: AbsolutePath -> IO Unit
 | 
				
			||||||
exports.ensureDirectory = async (userDataPath) => {
 | 
					exports.ensureDirectory = async (userDataPath) => {
 | 
				
			||||||
  if (!isString(userDataPath)) {
 | 
					  if (!isString(userDataPath)) {
 | 
				
			||||||
    throw new TypeError('"userDataPath" must be a string');
 | 
					    throw new TypeError("'userDataPath' must be a string");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  await fse.ensureDir(exports.getPath(userDataPath));
 | 
					  await fse.ensureDir(exports.getPath(userDataPath));
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -29,12 +29,12 @@ exports.ensureDirectory = async (userDataPath) => {
 | 
				
			||||||
//                      IO (Promise ArrayBuffer)
 | 
					//                      IO (Promise ArrayBuffer)
 | 
				
			||||||
exports.createReader = (root) => {
 | 
					exports.createReader = (root) => {
 | 
				
			||||||
  if (!isString(root)) {
 | 
					  if (!isString(root)) {
 | 
				
			||||||
    throw new TypeError('"root" must be a path');
 | 
					    throw new TypeError("'root' must be a path");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return async (relativePath) => {
 | 
					  return async (relativePath) => {
 | 
				
			||||||
    if (!isString(relativePath)) {
 | 
					    if (!isString(relativePath)) {
 | 
				
			||||||
      throw new TypeError('"relativePath" must be a string');
 | 
					      throw new TypeError("'relativePath' must be a string");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const absolutePath = path.join(root, relativePath);
 | 
					    const absolutePath = path.join(root, relativePath);
 | 
				
			||||||
| 
						 | 
					@ -48,12 +48,12 @@ exports.createReader = (root) => {
 | 
				
			||||||
//                            IO (Promise RelativePath)
 | 
					//                            IO (Promise RelativePath)
 | 
				
			||||||
exports.createWriterForNew = (root) => {
 | 
					exports.createWriterForNew = (root) => {
 | 
				
			||||||
  if (!isString(root)) {
 | 
					  if (!isString(root)) {
 | 
				
			||||||
    throw new TypeError('"root" must be a path');
 | 
					    throw new TypeError("'root' must be a path");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return async (arrayBuffer) => {
 | 
					  return async (arrayBuffer) => {
 | 
				
			||||||
    if (!isArrayBuffer(arrayBuffer)) {
 | 
					    if (!isArrayBuffer(arrayBuffer)) {
 | 
				
			||||||
      throw new TypeError('"arrayBuffer" must be an array buffer');
 | 
					      throw new TypeError("'arrayBuffer' must be an array buffer");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const name = exports.createName();
 | 
					    const name = exports.createName();
 | 
				
			||||||
| 
						 | 
					@ -70,16 +70,16 @@ exports.createWriterForNew = (root) => {
 | 
				
			||||||
//                      IO (Promise RelativePath)
 | 
					//                      IO (Promise RelativePath)
 | 
				
			||||||
exports.createWriterForExisting = (root) => {
 | 
					exports.createWriterForExisting = (root) => {
 | 
				
			||||||
  if (!isString(root)) {
 | 
					  if (!isString(root)) {
 | 
				
			||||||
    throw new TypeError('"root" must be a path');
 | 
					    throw new TypeError("'root' must be a path");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return async ({ data: arrayBuffer, path: relativePath } = {}) => {
 | 
					  return async ({ data: arrayBuffer, path: relativePath } = {}) => {
 | 
				
			||||||
    if (!isString(relativePath)) {
 | 
					    if (!isString(relativePath)) {
 | 
				
			||||||
      throw new TypeError('"relativePath" must be a path');
 | 
					      throw new TypeError("'relativePath' must be a path");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!isArrayBuffer(arrayBuffer)) {
 | 
					    if (!isArrayBuffer(arrayBuffer)) {
 | 
				
			||||||
      throw new TypeError('"arrayBuffer" must be an array buffer');
 | 
					      throw new TypeError("'arrayBuffer' must be an array buffer");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const buffer = Buffer.from(arrayBuffer);
 | 
					    const buffer = Buffer.from(arrayBuffer);
 | 
				
			||||||
| 
						 | 
					@ -95,12 +95,12 @@ exports.createWriterForExisting = (root) => {
 | 
				
			||||||
//                       IO Unit
 | 
					//                       IO Unit
 | 
				
			||||||
exports.createDeleter = (root) => {
 | 
					exports.createDeleter = (root) => {
 | 
				
			||||||
  if (!isString(root)) {
 | 
					  if (!isString(root)) {
 | 
				
			||||||
    throw new TypeError('"root" must be a path');
 | 
					    throw new TypeError("'root' must be a path");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return async (relativePath) => {
 | 
					  return async (relativePath) => {
 | 
				
			||||||
    if (!isString(relativePath)) {
 | 
					    if (!isString(relativePath)) {
 | 
				
			||||||
      throw new TypeError('"relativePath" must be a string');
 | 
					      throw new TypeError("'relativePath' must be a string");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const absolutePath = path.join(root, relativePath);
 | 
					    const absolutePath = path.join(root, relativePath);
 | 
				
			||||||
| 
						 | 
					@ -117,7 +117,7 @@ exports.createName = () => {
 | 
				
			||||||
//      getRelativePath :: String -> IO Path
 | 
					//      getRelativePath :: String -> IO Path
 | 
				
			||||||
exports.getRelativePath = (name) => {
 | 
					exports.getRelativePath = (name) => {
 | 
				
			||||||
  if (!isString(name)) {
 | 
					  if (!isString(name)) {
 | 
				
			||||||
    throw new TypeError('"name" must be a string');
 | 
					    throw new TypeError("'name' must be a string");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const prefix = name.slice(0, 2);
 | 
					  const prefix = name.slice(0, 2);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -100,11 +100,11 @@
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        getOrCreate: function(id, type) {
 | 
					        getOrCreate: function(id, type) {
 | 
				
			||||||
            if (typeof id !== 'string') {
 | 
					            if (typeof id !== 'string') {
 | 
				
			||||||
                throw new TypeError('"id" must be a string');
 | 
					                throw new TypeError("'id' must be a string");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (type !== 'private' && type !== 'group') {
 | 
					            if (type !== 'private' && type !== 'group') {
 | 
				
			||||||
                throw new TypeError('"type" must be "private" or "group"; got: ' + type);
 | 
					                throw new TypeError(`'type' must be 'private' or 'group'; got: '${type}'`);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!this._initialFetchComplete) {
 | 
					            if (!this._initialFetchComplete) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -496,7 +496,7 @@ async function writeAttachment(attachment, options) {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!Attachment.hasData(attachment)) {
 | 
					  if (!Attachment.hasData(attachment)) {
 | 
				
			||||||
    throw new TypeError('"attachment.data" is required');
 | 
					    throw new TypeError("'attachment.data' is required");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const ciphertext = await crypto.encryptSymmetric(key, attachment.data);
 | 
					  const ciphertext = await crypto.encryptSymmetric(key, attachment.data);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -56,7 +56,7 @@ exports.getVersion = async (name) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.getCount = async ({ store } = {}) => {
 | 
					exports.getCount = async ({ store } = {}) => {
 | 
				
			||||||
  if (!isObject(store)) {
 | 
					  if (!isObject(store)) {
 | 
				
			||||||
    throw new TypeError('"store" is required');
 | 
					    throw new TypeError("'store' is required");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const request = store.count();
 | 
					  const request = store.count();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,15 +29,15 @@ exports.createConversation = async ({
 | 
				
			||||||
} = {}) => {
 | 
					} = {}) => {
 | 
				
			||||||
  if (!isObject(ConversationController) ||
 | 
					  if (!isObject(ConversationController) ||
 | 
				
			||||||
      !isFunction(ConversationController.getOrCreateAndWait)) {
 | 
					      !isFunction(ConversationController.getOrCreateAndWait)) {
 | 
				
			||||||
    throw new TypeError('"ConversationController" is required');
 | 
					    throw new TypeError("'ConversationController' is required");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!isNumber(numMessages) || numMessages <= 0) {
 | 
					  if (!isNumber(numMessages) || numMessages <= 0) {
 | 
				
			||||||
    throw new TypeError('"numMessages" must be a positive number');
 | 
					    throw new TypeError("'numMessages' must be a positive number");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!isFunction(WhisperMessage)) {
 | 
					  if (!isFunction(WhisperMessage)) {
 | 
				
			||||||
    throw new TypeError('"WhisperMessage" is required');
 | 
					    throw new TypeError("'WhisperMessage' is required");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const conversation =
 | 
					  const conversation =
 | 
				
			||||||
| 
						 | 
					@ -80,7 +80,7 @@ const SAMPLE_MESSAGES = [
 | 
				
			||||||
const ATTACHMENT_SAMPLE_RATE = 0.33;
 | 
					const ATTACHMENT_SAMPLE_RATE = 0.33;
 | 
				
			||||||
const createRandomMessage = async ({ conversationId } = {}) => {
 | 
					const createRandomMessage = async ({ conversationId } = {}) => {
 | 
				
			||||||
  if (!isString(conversationId)) {
 | 
					  if (!isString(conversationId)) {
 | 
				
			||||||
    throw new TypeError('"conversationId" must be a string');
 | 
					    throw new TypeError("'conversationId' must be a string");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const sentAt = Date.now() - random(100 * 24 * 60 * 60 * 1000);
 | 
					  const sentAt = Date.now() - random(100 * 24 * 60 * 60 * 1000);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,20 +29,20 @@ exports.processNext = async ({
 | 
				
			||||||
  upgradeMessageSchema,
 | 
					  upgradeMessageSchema,
 | 
				
			||||||
} = {}) => {
 | 
					} = {}) => {
 | 
				
			||||||
  if (!isFunction(BackboneMessage)) {
 | 
					  if (!isFunction(BackboneMessage)) {
 | 
				
			||||||
    throw new TypeError('"BackboneMessage" (Whisper.Message) constructor is required');
 | 
					    throw new TypeError("'BackboneMessage' (Whisper.Message) constructor is required");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!isFunction(BackboneMessageCollection)) {
 | 
					  if (!isFunction(BackboneMessageCollection)) {
 | 
				
			||||||
    throw new TypeError('"BackboneMessageCollection" (Whisper.MessageCollection)' +
 | 
					    throw new TypeError("'BackboneMessageCollection' (Whisper.MessageCollection)" +
 | 
				
			||||||
      ' constructor is required');
 | 
					      ' constructor is required');
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!isNumber(numMessagesPerBatch)) {
 | 
					  if (!isNumber(numMessagesPerBatch)) {
 | 
				
			||||||
    throw new TypeError('"numMessagesPerBatch" is required');
 | 
					    throw new TypeError("'numMessagesPerBatch' is required");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!isFunction(upgradeMessageSchema)) {
 | 
					  if (!isFunction(upgradeMessageSchema)) {
 | 
				
			||||||
    throw new TypeError('"upgradeMessageSchema" is required');
 | 
					    throw new TypeError("'upgradeMessageSchema' is required");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const startTime = Date.now();
 | 
					  const startTime = Date.now();
 | 
				
			||||||
| 
						 | 
					@ -85,19 +85,19 @@ exports.dangerouslyProcessAllWithoutIndex = async ({
 | 
				
			||||||
  upgradeMessageSchema,
 | 
					  upgradeMessageSchema,
 | 
				
			||||||
} = {}) => {
 | 
					} = {}) => {
 | 
				
			||||||
  if (!isString(databaseName)) {
 | 
					  if (!isString(databaseName)) {
 | 
				
			||||||
    throw new TypeError('"databaseName" must be a string');
 | 
					    throw new TypeError("'databaseName' must be a string");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!isNumber(minDatabaseVersion)) {
 | 
					  if (!isNumber(minDatabaseVersion)) {
 | 
				
			||||||
    throw new TypeError('"minDatabaseVersion" must be a number');
 | 
					    throw new TypeError("'minDatabaseVersion' must be a number");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!isNumber(numMessagesPerBatch)) {
 | 
					  if (!isNumber(numMessagesPerBatch)) {
 | 
				
			||||||
    throw new TypeError('"numMessagesPerBatch" must be a number');
 | 
					    throw new TypeError("'numMessagesPerBatch' must be a number");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!isFunction(upgradeMessageSchema)) {
 | 
					  if (!isFunction(upgradeMessageSchema)) {
 | 
				
			||||||
    throw new TypeError('"upgradeMessageSchema" is required');
 | 
					    throw new TypeError("'upgradeMessageSchema' is required");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const connection = await database.open(databaseName);
 | 
					  const connection = await database.open(databaseName);
 | 
				
			||||||
| 
						 | 
					@ -155,7 +155,7 @@ exports.processNextBatchWithoutIndex = async ({
 | 
				
			||||||
  upgradeMessageSchema,
 | 
					  upgradeMessageSchema,
 | 
				
			||||||
} = {}) => {
 | 
					} = {}) => {
 | 
				
			||||||
  if (!isFunction(upgradeMessageSchema)) {
 | 
					  if (!isFunction(upgradeMessageSchema)) {
 | 
				
			||||||
    throw new TypeError('"upgradeMessageSchema" is required');
 | 
					    throw new TypeError("'upgradeMessageSchema' is required");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const connection = await _getConnection({ databaseName, minDatabaseVersion });
 | 
					  const connection = await _getConnection({ databaseName, minDatabaseVersion });
 | 
				
			||||||
| 
						 | 
					@ -170,11 +170,11 @@ exports.processNextBatchWithoutIndex = async ({
 | 
				
			||||||
// Private API
 | 
					// Private API
 | 
				
			||||||
const _getConnection = async ({ databaseName, minDatabaseVersion }) => {
 | 
					const _getConnection = async ({ databaseName, minDatabaseVersion }) => {
 | 
				
			||||||
  if (!isString(databaseName)) {
 | 
					  if (!isString(databaseName)) {
 | 
				
			||||||
    throw new TypeError('"databaseName" must be a string');
 | 
					    throw new TypeError("'databaseName' must be a string");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!isNumber(minDatabaseVersion)) {
 | 
					  if (!isNumber(minDatabaseVersion)) {
 | 
				
			||||||
    throw new TypeError('"minDatabaseVersion" must be a number');
 | 
					    throw new TypeError("'minDatabaseVersion' must be a number");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const connection = await database.open(databaseName);
 | 
					  const connection = await database.open(databaseName);
 | 
				
			||||||
| 
						 | 
					@ -194,15 +194,15 @@ const _processBatch = async ({
 | 
				
			||||||
  upgradeMessageSchema,
 | 
					  upgradeMessageSchema,
 | 
				
			||||||
} = {}) => {
 | 
					} = {}) => {
 | 
				
			||||||
  if (!isObject(connection)) {
 | 
					  if (!isObject(connection)) {
 | 
				
			||||||
    throw new TypeError('"connection" must be a string');
 | 
					    throw new TypeError("'connection' must be a string");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!isFunction(upgradeMessageSchema)) {
 | 
					  if (!isFunction(upgradeMessageSchema)) {
 | 
				
			||||||
    throw new TypeError('"upgradeMessageSchema" is required');
 | 
					    throw new TypeError("'upgradeMessageSchema' is required");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!isNumber(numMessagesPerBatch)) {
 | 
					  if (!isNumber(numMessagesPerBatch)) {
 | 
				
			||||||
    throw new TypeError('"numMessagesPerBatch" is required');
 | 
					    throw new TypeError("'numMessagesPerBatch' is required");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const isAttachmentMigrationComplete =
 | 
					  const isAttachmentMigrationComplete =
 | 
				
			||||||
| 
						 | 
					@ -273,7 +273,7 @@ const _saveMessageBackbone = ({ BackboneMessage } = {}) => (message) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const _saveMessage = ({ transaction } = {}) => (message) => {
 | 
					const _saveMessage = ({ transaction } = {}) => (message) => {
 | 
				
			||||||
  if (!isObject(transaction)) {
 | 
					  if (!isObject(transaction)) {
 | 
				
			||||||
    throw new TypeError('"transaction" is required');
 | 
					    throw new TypeError("'transaction' is required");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const messagesStore = transaction.objectStore(MESSAGES_STORE_NAME);
 | 
					  const messagesStore = transaction.objectStore(MESSAGES_STORE_NAME);
 | 
				
			||||||
| 
						 | 
					@ -289,12 +289,12 @@ const _saveMessage = ({ transaction } = {}) => (message) => {
 | 
				
			||||||
const _fetchMessagesRequiringSchemaUpgrade =
 | 
					const _fetchMessagesRequiringSchemaUpgrade =
 | 
				
			||||||
  async ({ BackboneMessageCollection, count } = {}) => {
 | 
					  async ({ BackboneMessageCollection, count } = {}) => {
 | 
				
			||||||
    if (!isFunction(BackboneMessageCollection)) {
 | 
					    if (!isFunction(BackboneMessageCollection)) {
 | 
				
			||||||
      throw new TypeError('"BackboneMessageCollection" (Whisper.MessageCollection)' +
 | 
					      throw new TypeError("'BackboneMessageCollection' (Whisper.MessageCollection)" +
 | 
				
			||||||
        ' constructor is required');
 | 
					        ' constructor is required');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!isNumber(count)) {
 | 
					    if (!isNumber(count)) {
 | 
				
			||||||
      throw new TypeError('"count" is required');
 | 
					      throw new TypeError("'count' is required");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const collection = new BackboneMessageCollection();
 | 
					    const collection = new BackboneMessageCollection();
 | 
				
			||||||
| 
						 | 
					@ -318,15 +318,15 @@ const _fetchMessagesRequiringSchemaUpgrade =
 | 
				
			||||||
const _dangerouslyFetchMessagesRequiringSchemaUpgradeWithoutIndex =
 | 
					const _dangerouslyFetchMessagesRequiringSchemaUpgradeWithoutIndex =
 | 
				
			||||||
  ({ connection, count, lastIndex } = {}) => {
 | 
					  ({ connection, count, lastIndex } = {}) => {
 | 
				
			||||||
    if (!isObject(connection)) {
 | 
					    if (!isObject(connection)) {
 | 
				
			||||||
      throw new TypeError('"connection" is required');
 | 
					      throw new TypeError("'connection' is required");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!isNumber(count)) {
 | 
					    if (!isNumber(count)) {
 | 
				
			||||||
      throw new TypeError('"count" is required');
 | 
					      throw new TypeError("'count' is required");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (lastIndex && !isString(lastIndex)) {
 | 
					    if (lastIndex && !isString(lastIndex)) {
 | 
				
			||||||
      throw new TypeError('"lastIndex" must be a string');
 | 
					      throw new TypeError("'lastIndex' must be a string");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const hasLastIndex = Boolean(lastIndex);
 | 
					    const hasLastIndex = Boolean(lastIndex);
 | 
				
			||||||
| 
						 | 
					@ -359,7 +359,7 @@ const _dangerouslyFetchMessagesRequiringSchemaUpgradeWithoutIndex =
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const _getNumMessages = async ({ connection } = {}) => {
 | 
					const _getNumMessages = async ({ connection } = {}) => {
 | 
				
			||||||
  if (!isObject(connection)) {
 | 
					  if (!isObject(connection)) {
 | 
				
			||||||
    throw new TypeError('"connection" is required');
 | 
					    throw new TypeError("'connection' is required");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const transaction = connection.transaction(MESSAGES_STORE_NAME, 'readonly');
 | 
					  const transaction = connection.transaction(MESSAGES_STORE_NAME, 'readonly');
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,12 +19,12 @@ const closeDatabaseConnection = ({ Backbone } = {}) =>
 | 
				
			||||||
exports.runMigrations = async ({ Backbone, database } = {}) => {
 | 
					exports.runMigrations = async ({ Backbone, database } = {}) => {
 | 
				
			||||||
  if (!isObject(Backbone) || !isObject(Backbone.Collection) ||
 | 
					  if (!isObject(Backbone) || !isObject(Backbone.Collection) ||
 | 
				
			||||||
      !isFunction(Backbone.Collection.extend)) {
 | 
					      !isFunction(Backbone.Collection.extend)) {
 | 
				
			||||||
    throw new TypeError('"Backbone" is required');
 | 
					    throw new TypeError("'Backbone' is required");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!isObject(database) || !isString(database.id) ||
 | 
					  if (!isObject(database) || !isString(database.id) ||
 | 
				
			||||||
      !Array.isArray(database.migrations)) {
 | 
					      !Array.isArray(database.migrations)) {
 | 
				
			||||||
    throw new TypeError('"database" is required');
 | 
					    throw new TypeError("'database' is required");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const {
 | 
					  const {
 | 
				
			||||||
| 
						 | 
					@ -58,7 +58,7 @@ exports.runMigrations = async ({ Backbone, database } = {}) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const getMigrationVersions = (database) => {
 | 
					const getMigrationVersions = (database) => {
 | 
				
			||||||
  if (!isObject(database) || !Array.isArray(database.migrations)) {
 | 
					  if (!isObject(database) || !Array.isArray(database.migrations)) {
 | 
				
			||||||
    throw new TypeError('"database" is required');
 | 
					    throw new TypeError("'database' is required");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const firstMigration = head(database.migrations);
 | 
					  const firstMigration = head(database.migrations);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,14 +16,14 @@ const REDACTION_PLACEHOLDER = '[REDACTED]';
 | 
				
			||||||
//      _redactPath :: Path -> String -> String
 | 
					//      _redactPath :: Path -> String -> String
 | 
				
			||||||
exports._redactPath = (filePath) => {
 | 
					exports._redactPath = (filePath) => {
 | 
				
			||||||
  if (!is.string(filePath)) {
 | 
					  if (!is.string(filePath)) {
 | 
				
			||||||
    throw new TypeError('"filePath" must be a string');
 | 
					    throw new TypeError("'filePath' must be a string");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const filePathPattern = exports._pathToRegExp(filePath);
 | 
					  const filePathPattern = exports._pathToRegExp(filePath);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (text) => {
 | 
					  return (text) => {
 | 
				
			||||||
    if (!is.string(text)) {
 | 
					    if (!is.string(text)) {
 | 
				
			||||||
      throw new TypeError('"text" must be a string');
 | 
					      throw new TypeError("'text' must be a string");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!is.regExp(filePathPattern)) {
 | 
					    if (!is.regExp(filePathPattern)) {
 | 
				
			||||||
| 
						 | 
					@ -58,7 +58,7 @@ exports._pathToRegExp = (filePath) => {
 | 
				
			||||||
//      redactPhoneNumbers :: String -> String
 | 
					//      redactPhoneNumbers :: String -> String
 | 
				
			||||||
exports.redactPhoneNumbers = (text) => {
 | 
					exports.redactPhoneNumbers = (text) => {
 | 
				
			||||||
  if (!is.string(text)) {
 | 
					  if (!is.string(text)) {
 | 
				
			||||||
    throw new TypeError('"text" must be a string');
 | 
					    throw new TypeError("'text' must be a string");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return text.replace(PHONE_NUMBER_PATTERN, `+${REDACTION_PLACEHOLDER}$1`);
 | 
					  return text.replace(PHONE_NUMBER_PATTERN, `+${REDACTION_PLACEHOLDER}$1`);
 | 
				
			||||||
| 
						 | 
					@ -67,7 +67,7 @@ exports.redactPhoneNumbers = (text) => {
 | 
				
			||||||
//      redactGroupIds :: String -> String
 | 
					//      redactGroupIds :: String -> String
 | 
				
			||||||
exports.redactGroupIds = (text) => {
 | 
					exports.redactGroupIds = (text) => {
 | 
				
			||||||
  if (!is.string(text)) {
 | 
					  if (!is.string(text)) {
 | 
				
			||||||
    throw new TypeError('"text" must be a string');
 | 
					    throw new TypeError("'text' must be a string");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return text.replace(
 | 
					  return text.replace(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,11 +26,11 @@ exports.markAttachmentMigrationComplete = connection =>
 | 
				
			||||||
// Private API
 | 
					// Private API
 | 
				
			||||||
exports._getItem = (connection, key) => {
 | 
					exports._getItem = (connection, key) => {
 | 
				
			||||||
  if (!isObject(connection)) {
 | 
					  if (!isObject(connection)) {
 | 
				
			||||||
    throw new TypeError('"connection" is required');
 | 
					    throw new TypeError("'connection' is required");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!isString(key)) {
 | 
					  if (!isString(key)) {
 | 
				
			||||||
    throw new TypeError('"key" must be a string');
 | 
					    throw new TypeError("'key' must be a string");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const transaction = connection.transaction(ITEMS_STORE_NAME, 'readonly');
 | 
					  const transaction = connection.transaction(ITEMS_STORE_NAME, 'readonly');
 | 
				
			||||||
| 
						 | 
					@ -47,11 +47,11 @@ exports._getItem = (connection, key) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports._setItem = (connection, key, value) => {
 | 
					exports._setItem = (connection, key, value) => {
 | 
				
			||||||
  if (!isObject(connection)) {
 | 
					  if (!isObject(connection)) {
 | 
				
			||||||
    throw new TypeError('"connection" is required');
 | 
					    throw new TypeError("'connection' is required");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!isString(key)) {
 | 
					  if (!isString(key)) {
 | 
				
			||||||
    throw new TypeError('"key" must be a string');
 | 
					    throw new TypeError("'key' must be a string");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const transaction = connection.transaction(ITEMS_STORE_NAME, 'readwrite');
 | 
					  const transaction = connection.transaction(ITEMS_STORE_NAME, 'readwrite');
 | 
				
			||||||
| 
						 | 
					@ -68,11 +68,11 @@ exports._setItem = (connection, key, value) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports._deleteItem = (connection, key) => {
 | 
					exports._deleteItem = (connection, key) => {
 | 
				
			||||||
  if (!isObject(connection)) {
 | 
					  if (!isObject(connection)) {
 | 
				
			||||||
    throw new TypeError('"connection" is required');
 | 
					    throw new TypeError("'connection' is required");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!isString(key)) {
 | 
					  if (!isString(key)) {
 | 
				
			||||||
    throw new TypeError('"key" must be a string');
 | 
					    throw new TypeError("'key' must be a string");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const transaction = connection.transaction(ITEMS_STORE_NAME, 'readwrite');
 | 
					  const transaction = connection.transaction(ITEMS_STORE_NAME, 'readwrite');
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,15 +10,15 @@ exports.syncReadReceiptConfiguration = async ({
 | 
				
			||||||
  storage,
 | 
					  storage,
 | 
				
			||||||
}) => {
 | 
					}) => {
 | 
				
			||||||
  if (!is.string(deviceId)) {
 | 
					  if (!is.string(deviceId)) {
 | 
				
			||||||
    throw new TypeError('"deviceId" is required');
 | 
					    throw new TypeError("'deviceId' is required");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!is.function(sendRequestConfigurationSyncMessage)) {
 | 
					  if (!is.function(sendRequestConfigurationSyncMessage)) {
 | 
				
			||||||
    throw new TypeError('"sendRequestConfigurationSyncMessage" is required');
 | 
					    throw new TypeError("'sendRequestConfigurationSyncMessage' is required");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!is.object(storage)) {
 | 
					  if (!is.object(storage)) {
 | 
				
			||||||
    throw new TypeError('"storage" is required');
 | 
					    throw new TypeError("'storage' is required");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const isPrimaryDevice = deviceId === '1';
 | 
					  const isPrimaryDevice = deviceId === '1';
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
exports.stringToArrayBuffer = (string) => {
 | 
					exports.stringToArrayBuffer = (string) => {
 | 
				
			||||||
  if (typeof string !== 'string') {
 | 
					  if (typeof string !== 'string') {
 | 
				
			||||||
    throw new TypeError('"string" must be a string');
 | 
					    throw new TypeError("'string' must be a string");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const array = new Uint8Array(string.length);
 | 
					  const array = new Uint8Array(string.length);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -116,12 +116,12 @@ exports.hasData = attachment =>
 | 
				
			||||||
//                  IO (Promise Attachment)
 | 
					//                  IO (Promise Attachment)
 | 
				
			||||||
exports.loadData = (readAttachmentData) => {
 | 
					exports.loadData = (readAttachmentData) => {
 | 
				
			||||||
  if (!isFunction(readAttachmentData)) {
 | 
					  if (!isFunction(readAttachmentData)) {
 | 
				
			||||||
    throw new TypeError('"readAttachmentData" must be a function');
 | 
					    throw new TypeError("'readAttachmentData' must be a function");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return async (attachment) => {
 | 
					  return async (attachment) => {
 | 
				
			||||||
    if (!exports.isValid(attachment)) {
 | 
					    if (!exports.isValid(attachment)) {
 | 
				
			||||||
      throw new TypeError('"attachment" is not valid');
 | 
					      throw new TypeError("'attachment' is not valid");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const isAlreadyLoaded = exports.hasData(attachment);
 | 
					    const isAlreadyLoaded = exports.hasData(attachment);
 | 
				
			||||||
| 
						 | 
					@ -130,7 +130,7 @@ exports.loadData = (readAttachmentData) => {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!isString(attachment.path)) {
 | 
					    if (!isString(attachment.path)) {
 | 
				
			||||||
      throw new TypeError('"attachment.path" is required');
 | 
					      throw new TypeError("'attachment.path' is required");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const data = await readAttachmentData(attachment.path);
 | 
					    const data = await readAttachmentData(attachment.path);
 | 
				
			||||||
| 
						 | 
					@ -143,12 +143,12 @@ exports.loadData = (readAttachmentData) => {
 | 
				
			||||||
//                    IO Unit
 | 
					//                    IO Unit
 | 
				
			||||||
exports.deleteData = (deleteAttachmentData) => {
 | 
					exports.deleteData = (deleteAttachmentData) => {
 | 
				
			||||||
  if (!isFunction(deleteAttachmentData)) {
 | 
					  if (!isFunction(deleteAttachmentData)) {
 | 
				
			||||||
    throw new TypeError('"deleteAttachmentData" must be a function');
 | 
					    throw new TypeError("'deleteAttachmentData' must be a function");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return async (attachment) => {
 | 
					  return async (attachment) => {
 | 
				
			||||||
    if (!exports.isValid(attachment)) {
 | 
					    if (!exports.isValid(attachment)) {
 | 
				
			||||||
      throw new TypeError('"attachment" is not valid');
 | 
					      throw new TypeError("'attachment' is not valid");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const hasDataInMemory = exports.hasData(attachment);
 | 
					    const hasDataInMemory = exports.hasData(attachment);
 | 
				
			||||||
| 
						 | 
					@ -157,7 +157,7 @@ exports.deleteData = (deleteAttachmentData) => {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!isString(attachment.path)) {
 | 
					    if (!isString(attachment.path)) {
 | 
				
			||||||
      throw new TypeError('"attachment.path" is required');
 | 
					      throw new TypeError("'attachment.path' is required");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    await deleteAttachmentData(attachment.path);
 | 
					    await deleteAttachmentData(attachment.path);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,7 +15,7 @@ const {
 | 
				
			||||||
//                                 Promise Attachment
 | 
					//                                 Promise Attachment
 | 
				
			||||||
exports.migrateDataToFileSystem = async (attachment, { writeNewAttachmentData } = {}) => {
 | 
					exports.migrateDataToFileSystem = async (attachment, { writeNewAttachmentData } = {}) => {
 | 
				
			||||||
  if (!isFunction(writeNewAttachmentData)) {
 | 
					  if (!isFunction(writeNewAttachmentData)) {
 | 
				
			||||||
    throw new TypeError('"writeNewAttachmentData" must be a function');
 | 
					    throw new TypeError("'writeNewAttachmentData' must be a function");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const { data } = attachment;
 | 
					  const { data } = attachment;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -81,10 +81,10 @@ exports.initializeSchemaVersion = (message) => {
 | 
				
			||||||
// SchemaVersion -> UpgradeStep -> UpgradeStep
 | 
					// SchemaVersion -> UpgradeStep -> UpgradeStep
 | 
				
			||||||
exports._withSchemaVersion = (schemaVersion, upgrade) => {
 | 
					exports._withSchemaVersion = (schemaVersion, upgrade) => {
 | 
				
			||||||
  if (!SchemaVersion.isValid(schemaVersion)) {
 | 
					  if (!SchemaVersion.isValid(schemaVersion)) {
 | 
				
			||||||
    throw new TypeError('"schemaVersion" is invalid');
 | 
					    throw new TypeError("'schemaVersion' is invalid");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if (!isFunction(upgrade)) {
 | 
					  if (!isFunction(upgrade)) {
 | 
				
			||||||
    throw new TypeError('"upgrade" must be a function');
 | 
					    throw new TypeError("'upgrade' must be a function");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return async (message, context) => {
 | 
					  return async (message, context) => {
 | 
				
			||||||
| 
						 | 
					@ -192,12 +192,12 @@ exports.createAttachmentLoader = (loadAttachmentData) => {
 | 
				
			||||||
//                                    IO (Promise Message)
 | 
					//                                    IO (Promise Message)
 | 
				
			||||||
exports.createAttachmentDataWriter = (writeExistingAttachmentData) => {
 | 
					exports.createAttachmentDataWriter = (writeExistingAttachmentData) => {
 | 
				
			||||||
  if (!isFunction(writeExistingAttachmentData)) {
 | 
					  if (!isFunction(writeExistingAttachmentData)) {
 | 
				
			||||||
    throw new TypeError('"writeExistingAttachmentData" must be a function');
 | 
					    throw new TypeError("'writeExistingAttachmentData' must be a function");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return async (rawMessage) => {
 | 
					  return async (rawMessage) => {
 | 
				
			||||||
    if (!exports.isValid(rawMessage)) {
 | 
					    if (!exports.isValid(rawMessage)) {
 | 
				
			||||||
      throw new TypeError('"rawMessage" is not valid');
 | 
					      throw new TypeError("'rawMessage' is not valid");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const message = exports.initializeSchemaVersion(rawMessage);
 | 
					    const message = exports.initializeSchemaVersion(rawMessage);
 | 
				
			||||||
| 
						 | 
					@ -217,11 +217,11 @@ exports.createAttachmentDataWriter = (writeExistingAttachmentData) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    attachments.forEach((attachment) => {
 | 
					    attachments.forEach((attachment) => {
 | 
				
			||||||
      if (!Attachment.hasData(attachment)) {
 | 
					      if (!Attachment.hasData(attachment)) {
 | 
				
			||||||
        throw new TypeError('"attachment.data" is required during message import');
 | 
					        throw new TypeError("'attachment.data' is required during message import");
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (!isString(attachment.path)) {
 | 
					      if (!isString(attachment.path)) {
 | 
				
			||||||
        throw new TypeError('"attachment.path" is required during message import');
 | 
					        throw new TypeError("'attachment.path' is required during message import");
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -246,14 +246,14 @@ describe('Message', () => {
 | 
				
			||||||
      const toVersionX = () => {};
 | 
					      const toVersionX = () => {};
 | 
				
			||||||
      assert.throws(
 | 
					      assert.throws(
 | 
				
			||||||
        () => Message._withSchemaVersion(toVersionX, 2),
 | 
					        () => Message._withSchemaVersion(toVersionX, 2),
 | 
				
			||||||
        '"schemaVersion" is invalid'
 | 
					        "'schemaVersion' is invalid"
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    it('should require an upgrade function', () => {
 | 
					    it('should require an upgrade function', () => {
 | 
				
			||||||
      assert.throws(
 | 
					      assert.throws(
 | 
				
			||||||
        () => Message._withSchemaVersion(2, 3),
 | 
					        () => Message._withSchemaVersion(2, 3),
 | 
				
			||||||
        '"upgrade" must be a function'
 | 
					        "'upgrade' must be a function"
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue