Importer

Importer

Source:
Author:
  • Tom De Caluw√©

Exposes the Importer object implementing methods for bulk imports.

Methods

(static) buffer(collection) → {Object}

Get an import buffer for a given collection.

Source:
Parameters:
Name Type Description
collection Object

The target collection

Returns:

return buffer If no buffer is presented, a new one will be constructed.

Type
Object

(static) commit(collection) → {undefined}

Commit the buffer for a given collection to the database.

Source:
Parameters:
Name Type Description
collection Mongo.Collection

The target collection to be flushed to disk

Returns:
Type
undefined

(static) context(collection, selectoropt) → {SimpleSchema.ValidationContext}

Get a validation context for a given collection.

Source:
Parameters:
Name Type Attributes Description
collection Mongo.Collection

The target collection

selector Object <optional>

A selector object to retrieve the correct schema.

Returns:

A validation context.

The validation context is requested from the schema associated with the collection.

Type
SimpleSchema.ValidationContext

(static) flush(collection) → {undefined}

Process the buffer for a given collection and commit the database.

Source:
Parameters:
Name Type Description
collection Mongo.Collection

optional - supply a Mongo collection, or leave empty to commit all buffer entries

Returns:
Type
undefined

(static) identify(document) → {Mongo.Collection}

Tries to identify the schema associated with a document.

Source:

Importer.identify

Parameters:
Name Type Description
document Object

A document with unknown schema

Throws:

Throws an error if the schema couldn't be determined.

The algorithm initially assumes the document can be anything. It associates with each field in the document a probability that it isn't following some schema other than the one the field is associated with.

Afterwards the schema with the maximal probability is selected. An error is thrown if the schema cannot be determined.

Type
Error
Returns:

Returns a MongoDB collection in which the document can be inserted.

Type
Mongo.Collection

(static) layout(layout, shopId) → {Object}

store a shop layout in the import buffer

Source:
Parameters:
Name Type Description
layout Array

an array of layouts to be added to shop

shopId String

shopId

Returns:

this shop

Type
Object

(static) object(collection, key, object) → {undefined}

Push a new upsert document to the import buffer.

Source:
Parameters:
Name Type Description
collection Mongo.Collection

The target collection

key Object

A key to look up the object

object Object

The object data to be updated

Returns:
Type
undefined

(static) package(pkg, shopId) → {undefined}

Store a package in the import buffer.

Source:
Parameters:
Name Type Description
pkg Object

The package data to be updated

shopId String

The package data to be updated

Returns:
Type
undefined

(static) process(json, keys, callback, cbArgs) → {undefined}

Process a json array of import documents using a callback.

Source:
Parameters:
Name Type Description
json Array.<Object>

An array containing the import documents

keys Array.<string>

Fields that should be used as the import key.

callback function

A callback accepting two parameters.

cbArgs Array

An array of extra callback arguments, mainly used to pass shopId to callbacks The callback should accept a key document to consult the database as a first parameter and an update document as the second parameter.

Returns:
Type
undefined

(static) product(key, product) → {Object}

Store a product in the import buffer.

Source:
Parameters:
Name Type Description
key Object

A key to look up the product

product Object

The product data to be updated

Returns:

Importing a variant currently consists of the following steps:

  • Pull the variant from non-matching parent products.
  • Push the variant if it doesn't exist.
  • Update the variant.
Type
Object

(static) shipping(key, shipping) → {Object}

Store shipping in the import buffer.

Source:
Parameters:
Name Type Description
key Object

A shipping service key used in combination with provider

shipping Object

The shipping data to be updated

Returns:

this shipping

Type
Object

(static) shop(key, shop) → {Object}

Store a shop in the import buffer.

Source:
Parameters:
Name Type Description
key Object

A key to look up the shop

shop Object

The shop data to be updated

Returns:

this shop

Type
Object

(static) tag(key, tag) → {Object}

Store a tag in the import buffer.

Source:
Parameters:
Name Type Description
key Object

A key to look up the tag

tag Object

The tag data to be updated

Returns:

this tag

Type
Object

(static) template(templateInfo, shopId) → {undefined}

Store a template in the import buffer.

Source:
Parameters:
Name Type Description
templateInfo Object

The template data to be updated

shopId String

The package data to be updated

Returns:
Type
undefined

(static) translation(key, translation, shopId) → {Object}

Store a translation in the import buffer.

Source:
Parameters:
Name Type Description
key Object

A key to look up the translation

translation Object

The translation data to be updated

shopId String

The package data to be updated

Returns:

updated translation buffer

Type
Object