<commit_before>"use strict";

/**
 * @module opcua.client
 */

const util = require("util");
const EventEmitter = require("events").EventEmitter;

const _ = require("underscore");
const assert = require("node-opcua-assert").assert;

const resolveNodeId = require("node-opcua-nodeid").resolveNodeId;

const DataValue = require("node-opcua-data-value").DataValue;

const NodeId = require("node-opcua-nodeid").NodeId;
const coerceNodeId = require("node-opcua-nodeid").coerceNodeId;

const Variant = require("node-opcua-variant").Variant;
const DataType = require("node-opcua-variant").DataType;

const StatusCodes = require("node-opcua-status-code").StatusCodes;
const makeResultMask = require("node-opcua-data-model").makeResultMask;
const BrowseDirection = require("node-opcua-data-model").BrowseDirection;
const makeNodeClassMask = require("node-opcua-data-model").makeNodeClassMask;

const subscription_service = require("node-opcua-service-subscription");
const read_service = require("node-opcua-service-read");
const historizing_service = require("node-opcua-service-history");
const browse_service = require("node-opcua-service-browse");
const write_service = require("node-opcua-service-write");
const utils = require("node-opcua-utils");
const call_service = require("node-opcua-service-call");
const translate_service = require("node-opcua-service-translate-browse-path");

const BrowseResult = require("node-opcua-service-browse").BrowseResult;

const debugLog = require("node-opcua-debug").make_debugLog(__filename);
const doDebug = require("node-opcua-debug").checkDebugFlag(__filename);
const helpAPIChange = process.env.DEBUG && process.env.DEBUG.match(/API/);

const getFunctionParameterNames = require("node-opcua-utils").getFunctionParameterNames;

/**
 * @class ClientSession
 * @param client {OPCUAClient}
 * @constructor
 */
function ClientSession(client) {
    this._closeEventHasBeenEmmitted = false;
    this._client = client;
    this._publishEngine = null;
    this._closed = false;
}
util.inherits(ClientSession, EventEmitter);

/**
 * @method getPublishEngine
 * @return {ClientSidePublishEngine}
 */
ClientSession.prototype.getPublishEngine = function () {

    if (!this._publishEngine) {

        const ClientSidePublishEngine = require("../src/client_publish_engine").ClientSidePublishEngine;
        this._publishEngine = new ClientSidePublishEngine(this);
    }

    return this._publishEngine;
};

function coerceBrowseDescription(data) {
    if (typeof data === "string" || data instanceof NodeId) {
      var tmp = coerceBrowseDescription({
            nodeId: data,
                //includeSubtypes: false,
            includeSubtypes: true,
                //browseDirection: BrowseDirection.Both,
                browseDirection: BrowseDirection.Forward,
            nodeClassMask: 0,
                //resultMask: 255
            resultMask: 63
        });

            tmp.referenceTypeId.value = 33;
            return tmp;
    } else {
        data.nodeId = resolveNodeId(data.nodeId);
        data.referenceTypeId = data.referenceTypeId ? resolveNodeId(data.referenceTypeId) : null;
        return new browse_service.BrowseDescription(data);
    }
}

/**
 * @method browse
 * @async
 * @param nodeToBrowse           {String|BrowseDescription}
 * @param callback               {Function}
 * @param callback.err           {Error|null}
 * @param callback.browseResult  {BrowseResult}
 *
 * @example<commit_msg>Update client_session.js<commit_after>"use strict";

/**
 * @module opcua.client
 */

const util = require("util");
const EventEmitter = require("events").EventEmitter;

const _ = require("underscore");
const assert = require("node-opcua-assert").assert;

const resolveNodeId = require("node-opcua-nodeid").resolveNodeId;

const DataValue = require("node-opcua-data-value").DataValue;

const NodeId = require("node-opcua-nodeid").NodeId;
const coerceNodeId = require("node-opcua-nodeid").coerceNodeId;

const Variant = require("node-opcua-variant").Variant;
const DataType = require("node-opcua-variant").DataType;

const StatusCodes = require("node-opcua-status-code").StatusCodes;
const makeResultMask = require("node-opcua-data-model").makeResultMask;
const BrowseDirection = require("node-opcua-data-model").BrowseDirection;
const makeNodeClassMask = require("node-opcua-data-model").makeNodeClassMask;

const subscription_service = require("node-opcua-service-subscription");
const read_service = require("node-opcua-service-read");
const historizing_service = require("node-opcua-service-history");
const browse_service = require("node-opcua-service-browse");
const write_service = require("node-opcua-service-write");
const utils = require("node-opcua-utils");
const call_service = require("node-opcua-service-call");
const translate_service = require("node-opcua-service-translate-browse-path");

const BrowseResult = require("node-opcua-service-browse").BrowseResult;

const debugLog = require("node-opcua-debug").make_debugLog(__filename);
const doDebug = require("node-opcua-debug").checkDebugFlag(__filename);
const helpAPIChange = process.env.DEBUG && process.env.DEBUG.match(/API/);

const getFunctionParameterNames = require("node-opcua-utils").getFunctionParameterNames;

/**
 * @class ClientSession
 * @param client {OPCUAClient}
 * @constructor
 */
function ClientSession(client) {
    this._closeEventHasBeenEmmitted = false;
    this._client = client;
    this._publishEngine = null;
    this._closed = false;
}
util.inherits(ClientSession, EventEmitter);

/**
 * @method getPublishEngine
 * @return {ClientSidePublishEngine}
 */
ClientSession.prototype.getPublishEngine = function () {

    if (!this._publishEngine) {

        const ClientSidePublishEngine = require("../src/client_publish_engine").ClientSidePublishEngine;
        this._publishEngine = new ClientSidePublishEngine(this);
    }

    return this._publishEngine;
};

function coerceBrowseDescription(data) {
    if (typeof data === "string" || data instanceof NodeId) {
        return coerceBrowseDescription({
            nodeId: data,
            includeSubtypes: true,
            browseDirection: BrowseDirection.Forward,
            nodeClassMask: 0,
            resultMask: 63,
            referenceTypeId: "HierarchicalReferences"
        });
    } else {
        data.nodeId = resolveNodeId(data.nodeId);
        data.referenceTypeId = data.referenceTypeId ? resolveNodeId(data.referenceTypeId) : null;
        return new browse_service.BrowseDescription(data);
    }
}

/**
 * @method browse
 * @async
 * @param nodeToBrowse           {String|BrowseDescription}
 * @param callback               {Function}
 * @param callback.err           {Error|null}
 * @param callback.browseResult  {BrowseResult}
 *
 * @example
{'fraction_non_alphanumeric': 0.12823546812601685, 'fraction_numerical': 0.0016269782576541932, 'mean_word_length': 4.266355140186916, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2395261', 'n_tokens_mistral': 2041, 'n_tokens_neox': 2009, 'n_words': 345}