<commit_before>var path = require('path');
var url = require('url');
var fs = require('fs');
var mapnik = require('mapnik');
var Step = require('step');
var millstone = require('millstone');

models.Datasource.prototype.sync = function(method, model, success, error) {
    if (method !== 'read') return error('Method not supported.');

    var options = model.options;
    var config = Bones.plugin.config;

    if (!options) return error(new Error('options are required.'));
    if (!options.id) return error(new Error('id is required.'));
    if (!options.project) return error(new Error('project is required.'));

    millstone.resolve({
        mml: {
            Stylesheet: [{ id: 'layer', data: '' }],
            Layer: [{
                name: options.id,
                srs: options.srs || '',
                Datasource: {
                    file: options.file,
                    type: options.type
                }
            }]
        },
        base: path.join(config.files, 'project', options.project),
        cache: path.join(config.files, 'cache')
    }, function(err, mml) {
        if (err) return error(err);

        try {
            var source = new mapnik.Datasource(_({
                file: mml.Layer[0].Datasource.file,
                type: mml.Layer[0].Datasource.type
            }).defaults(options));

            var features = [];
            if (options.features) {
                var featureset = source.featureset();
                for (var i = 0, feat; i < 1000 && (feat = featureset.next(true)); i++) {
                    features.push(feat.attributes());
                }
            }

            var desc = source.describe();
            var datasource = {
                id: options.id,
                project: options.project,
                url: options.file,
                fields: desc.fields,
                features: features,
                type: desc.type,
                geometry_type: desc.type === 'raster' ? 'raster' : desc.geometry_type
            };

            // Process fields and calculate min/max values.<commit_msg>Properly pass resolved values when loading datasource.<commit_after>var path = require('path');
var url = require('url');
var fs = require('fs');
var mapnik = require('mapnik');
var Step = require('step');
var millstone = require('millstone');

models.Datasource.prototype.sync = function(method, model, success, error) {
    if (method !== 'read') return error('Method not supported.');

    var options = model.options;
    var config = Bones.plugin.config;

    if (!options) return error(new Error('options are required.'));
    if (!options.id) return error(new Error('id is required.'));
    if (!options.project) return error(new Error('project is required.'));

    millstone.resolve({
        mml: {
            Stylesheet: [{ id: 'layer', data: '' }],
            Layer: [{
                name: options.id,
                srs: options.srs || '',
                Datasource: {
                    file: options.file,
                    type: options.type
                }
            }]
        },
        base: path.join(config.files, 'project', options.project),
        cache: path.join(config.files, 'cache')
    }, function(err, mml) {
        if (err) return error(err);

        try {
            mml.Layer[0].Datasource = _(mml.Layer[0].Datasource).defaults(options);
            var source = new mapnik.Datasource(mml.Layer[0].Datasource);

            var features = [];
            if (options.features) {
                var featureset = source.featureset();
                for (var i = 0, feat; i < 1000 && (feat = featureset.next(true)); i++) {
                    features.push(feat.attributes());
                }
            }

            var desc = source.describe();
            var datasource = {
                id: options.id,
                project: options.project,
                url: options.file,
                fields: desc.fields,
                features: features,
                type: desc.type,
                geometry_type: desc.type === 'raster' ? 'raster' : desc.geometry_type
            };

            // Process fields and calculate min/max values.
{'fraction_non_alphanumeric': 0.13542409123307197, 'fraction_numerical': 0.003563791874554526, 'mean_word_length': 1.7408854166666667, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4203311', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1099, 'n_words': 286}