├── .appveyor.yml ├── .clang-format ├── .editorconfig ├── .github ├── actions │ ├── download-github-artifacts │ │ └── action.yml │ ├── get-artifact-for-stage-tests │ │ └── action.yml │ ├── run-ce-server │ │ └── run-ce-server.yml │ ├── run-ee-server-for-ext-container │ │ └── action.yml │ ├── run-ee-server │ │ └── action.yml │ ├── setup-docker-on-macos │ │ └── action.yml │ ├── update-version │ │ └── action.yml │ └── wait-for-as-server-to-start │ │ └── action.yml └── workflows │ ├── Dockerfile │ ├── build-artifacts.yml │ ├── build-bindings.yml │ ├── bump-dev-num.js │ ├── bump-stage-and-upload-to-jfrog.yml │ ├── bump-version.yml │ ├── config.conf.template │ ├── delete-artifacts.yml │ ├── dev-to-stage.yml │ ├── dev-workflow-p1.yml │ ├── docker-build-context │ ├── Dockerfile │ ├── roster.smd │ └── security.smd │ ├── download-jfrog-artifacts.yml │ ├── fast-forward-merge.yml │ ├── npm-install-script-test.yml │ ├── release-package.yml │ ├── release-workflow.yml │ ├── requirements.txt │ ├── stage-tests.yml │ ├── stage-workflow-p1.yml │ ├── test-artifacts.yml │ ├── test-dev-artifacts.yml │ ├── test-server-rc.yml │ ├── tests.yml │ ├── update-version.yml │ ├── upload-jfrog-build-to-npm.yml │ ├── upload-to-jfrog.yml │ ├── verify-npm-install.yml │ └── wait-for-as-server-to-start.bash ├── .gitignore ├── .gitmodules ├── .husky ├── .gitignore └── pre-commit ├── .jfrog └── projects │ └── npm.yaml ├── .mocharc.yml ├── .travis.yml ├── .travis ├── aerospike.conf └── start_cluster.sh ├── CHANGELOG.md ├── LICENSE ├── Makefile ├── README.md ├── README_WINDOWS.md ├── aerospike-client-c.ini ├── aerospike-client-c.sha256 ├── benchmarks ├── .npmignore ├── README.md ├── alerts.js ├── config.json ├── inspect.js ├── logging.js ├── main.js ├── memory.js ├── package-lock.json ├── package.json ├── stats.js └── worker.js ├── binding.gyp ├── docker └── README.md ├── eslint.config.mjs ├── examples ├── .npmignore ├── README.md ├── add.js ├── append.js ├── apply.js ├── batch.js ├── exists.js ├── geospatialMonteCarlo.js ├── get.js ├── info.js ├── lua │ ├── monte_carlo.lua │ ├── query.lua │ ├── sample.lua │ └── scan.lua ├── mrtAbort.js ├── mrtCommit.js ├── operate.js ├── package-lock.json ├── package.json ├── put.js ├── put_test.js ├── query.js ├── remove.js ├── run.js ├── scan.js ├── shared │ ├── cli.js │ ├── client.js │ ├── index.js │ ├── random.js │ ├── run.js │ └── streams.js ├── sindex.js ├── typescript.ts └── udf.js ├── incompatible.md ├── jsdoc.json ├── lib ├── abort_status.js ├── admin.js ├── aerospike.js ├── batch_type.js ├── bigint.js ├── bin.js ├── bitwise.js ├── cdt_context.js ├── client.js ├── commands │ ├── batch_command.js │ ├── command.js │ ├── connect_command.js │ ├── exists_command.js │ ├── index.js │ ├── query_background_command.js │ ├── read_record_command.js │ ├── stream_command.js │ └── write_record_command.js ├── commit_status.js ├── config.js ├── double.js ├── error.js ├── event_loop.js ├── exp.js ├── exp_bit.js ├── exp_hll.js ├── exp_lists.js ├── exp_maps.js ├── exp_operations.js ├── features.js ├── filter.js ├── geojson.js ├── hll.js ├── index_job.js ├── info.js ├── job.js ├── key.js ├── lists.js ├── maps.js ├── metrics_listeners.js ├── operations.js ├── policies │ ├── admin_policy.js │ ├── apply_policy.js │ ├── base_policy.js │ ├── batch_apply_policy.js │ ├── batch_policy.js │ ├── batch_read_policy.js │ ├── batch_remove_policy.js │ ├── batch_write_policy.js │ ├── bitwise_policy.js │ ├── command_queue_policy.js │ ├── hll_policy.js │ ├── info_policy.js │ ├── list_policy.js │ ├── map_policy.js │ ├── metrics_policy.js │ ├── operate_policy.js │ ├── query_policy.js │ ├── read_policy.js │ ├── remove_policy.js │ ├── scan_policy.js │ └── write_policy.js ├── policy.js ├── privilege.js ├── privilege_code.js ├── query.js ├── query_duration.js ├── record.js ├── record_stream.js ├── role.js ├── scan.js ├── status.js ├── transaction.js ├── transaction_pool.js ├── txn_capacity.js ├── txn_state.js ├── typedefs.js ├── udf_job.js ├── user.js └── utils.js ├── package-lock.json ├── package.json ├── scripts ├── Invoke-MsBuild.psm1 ├── build-c-client.ps1 ├── build-c-client.sh ├── build-commands.sh ├── build-package.ps1 ├── build-package.sh ├── build-package.sh-cclient-output.log ├── build_apidocs ├── change-install-command.js ├── os_version ├── prebuiltBinding.js ├── validate-c-client.sh ├── wait-for-node.sh └── watch_tests ├── src ├── include │ ├── async.h │ ├── client.h │ ├── command.h │ ├── config.h │ ├── conversions.h │ ├── enums.h │ ├── events.h │ ├── expressions.h │ ├── log.h │ ├── operations.h │ ├── policy.h │ ├── query.h │ ├── scan.h │ └── transaction.h └── main │ ├── aerospike.cc │ ├── async.cc │ ├── bit_operations.cc │ ├── cdt_ctx.cc │ ├── client.cc │ ├── command.cc │ ├── commands │ ├── apply_async.cc │ ├── batch_apply.cc │ ├── batch_exists.cc │ ├── batch_get.cc │ ├── batch_read_async.cc │ ├── batch_remove.cc │ ├── batch_select.cc │ ├── batch_write_async.cc │ ├── change_password.cc │ ├── disable_metrics.cc │ ├── enable_metrics.cc │ ├── exists_async.cc │ ├── get_async.cc │ ├── index_create.cc │ ├── index_remove.cc │ ├── info_any.cc │ ├── info_foreach.cc │ ├── info_host.cc │ ├── info_node.cc │ ├── job_info.cc │ ├── operate_async.cc │ ├── privilege_grant.cc │ ├── privilege_revoke.cc │ ├── put_async.cc │ ├── query_apply.cc │ ├── query_async.cc │ ├── query_background.cc │ ├── query_foreach.cc │ ├── query_pages.cc │ ├── query_role.cc │ ├── query_roles.cc │ ├── query_user.cc │ ├── query_users.cc │ ├── remove_async.cc │ ├── role_create.cc │ ├── role_drop.cc │ ├── role_grant.cc │ ├── role_revoke.cc │ ├── role_set_quotas.cc │ ├── role_set_whitelist.cc │ ├── scan_async.cc │ ├── scan_background.cc │ ├── scan_pages.cc │ ├── select_async.cc │ ├── set_xdr_filter.cc │ ├── transaction_abort.cc │ ├── transaction_commit.cc │ ├── truncate.cc │ ├── udf_register.cc │ ├── udf_remove.cc │ ├── user_create.cc │ └── user_drop.cc │ ├── config.cc │ ├── enums │ ├── abort_status.cc │ ├── batch_type.cc │ ├── bitwise_enum.cc │ ├── commit_status.cc │ ├── config_enum.cc │ ├── exp_enum.cc │ ├── exp_read_flags.cc │ ├── exp_write_flags.cc │ ├── hll_enum.cc │ ├── index.cc │ ├── job_status.cc │ ├── lists.cc │ ├── maps.cc │ ├── policy_enum.cc │ ├── predicates.cc │ ├── privilege_code.cc │ ├── query_duration.cc │ ├── scanPriority.cc │ ├── status.cc │ ├── ttl.cc │ ├── txn_capacity.cc │ ├── txn_state.cc │ └── udf_languages.cc │ ├── events.cc │ ├── exp_operations.cc │ ├── expressions.cc │ ├── hll_operations.cc │ ├── list_operations.cc │ ├── map_operations.cc │ ├── operations.cc │ ├── policy.cc │ ├── query.cc │ ├── scalar_operations.cc │ ├── scan.cc │ ├── stats.cc │ ├── transaction.cc │ └── util │ ├── conversions.cc │ ├── conversions_batch.cc │ └── log.cc ├── test ├── README.md ├── admin.js ├── aerospike.js ├── apply.js ├── batch_apply.js ├── batch_exists.js ├── batch_get.js ├── batch_read.js ├── batch_remove.js ├── batch_select.js ├── batch_write.js ├── bigint.js ├── bitwise.js ├── cdt_context.js ├── client.js ├── command.js ├── command_queue.js ├── config.js ├── double.js ├── enterprise.js ├── error.js ├── exists.js ├── exp.js ├── exp_bit.js ├── exp_hll.js ├── exp_list.js ├── exp_map.js ├── generators │ ├── key.js │ ├── metadata.js │ ├── put.js │ ├── record.js │ ├── util.js │ └── value.js ├── geojson.js ├── get.js ├── hll.js ├── index.js ├── index_job.js ├── info.js ├── key.js ├── lists.js ├── maps.js ├── operate.js ├── policy.js ├── put.js ├── query.js ├── remove.js ├── remove_bin.js ├── scan.js ├── select.js ├── stats.js ├── stress │ ├── perfdata.js │ ├── query.js │ └── scan.js ├── test_helper.js ├── truncate.js ├── udf.js ├── udf.lua ├── util │ ├── index.js │ ├── options.js │ ├── run_in_new_process.js │ ├── sleep.js │ └── statefulAsyncTest.js └── utils.js ├── ts-test ├── package-lock.json ├── package.json ├── scripts │ └── three_node.sh ├── tests │ ├── README.md │ ├── admin.ts │ ├── aerospike.ts │ ├── apply.ts │ ├── batch_apply.ts │ ├── batch_exists.ts │ ├── batch_get.ts │ ├── batch_read.ts │ ├── batch_remove.ts │ ├── batch_select.ts │ ├── batch_write.ts │ ├── bigint.ts │ ├── bitwise.ts │ ├── cdt_context.ts │ ├── client.ts │ ├── command.js │ ├── command_queue.js │ ├── config.ts │ ├── double.ts │ ├── enterprise.ts │ ├── error.ts │ ├── exists.ts │ ├── exp.ts │ ├── exp_bit.ts │ ├── exp_hll.ts │ ├── exp_list.ts │ ├── exp_map.ts │ ├── generators │ │ ├── key.ts │ │ ├── metadata.ts │ │ ├── put.ts │ │ ├── record.ts │ │ └── value.ts │ ├── geojson.ts │ ├── get.ts │ ├── hll.ts │ ├── index.ts │ ├── index_job.ts │ ├── info.js │ ├── key.ts │ ├── lists.ts │ ├── maps.ts │ ├── metrics.ts │ ├── metrics_cluster_name.ts │ ├── metrics_node_close.ts │ ├── mrt_api.ts │ ├── mrt_backward_compatible.ts │ ├── mrt_functionality.ts │ ├── operate.ts │ ├── policy.ts │ ├── prefer_rack.ts │ ├── put.ts │ ├── query.ts │ ├── remove.ts │ ├── remove_bin.ts │ ├── scan.ts │ ├── select.ts │ ├── set_xdr_filter.ts │ ├── stats.ts │ ├── status.ts │ ├── stress │ │ ├── perfdata.js │ │ ├── query.js │ │ └── scan.js │ ├── test_helper.ts │ ├── truncate.ts │ ├── types │ │ └── generators.types.ts │ ├── udf.lua │ ├── udf.ts │ ├── util │ │ ├── index.ts │ │ ├── options.ts │ │ ├── run_in_new_process.ts │ │ ├── sleep.ts │ │ └── statefulAsyncTest.ts │ └── utils.js └── tsconfig.json ├── tsconfig.json ├── tsconfig.tsbuildinfo └── typings └── index.d.ts /.appveyor.yml: -------------------------------------------------------------------------------- 1 | image: 2 | - Visual Studio 2019 3 | - Visual Studio 2022 4 | platform: x64 5 | environment: 6 | matrix: 7 | - nodejs_version: "18" 8 | - nodejs_version: "20" 9 | - nodejs_version: "22" 10 | 11 | install: 12 | - ps: Install-Product node $env:nodejs_version $env:platform 13 | - git submodule update --init --recursive 14 | - npm install 15 | 16 | build: off 17 | test_script: 18 | - set GLOBAL_CLIENT=false 19 | - npm test -- --grep "#noserver" 20 | 21 | #on_finish: 22 | # - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) 23 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | charset = utf-8 6 | trim_trailing_whitespace = true 7 | 8 | [{lib,test,examples,benchmarks}/**.js] 9 | indent_style = space 10 | indent_size = 2 11 | 12 | [src/**.{h,cc}] 13 | indent_style = tab 14 | indent_size = tab 15 | 16 | [Makefile] 17 | indent_style = tab 18 | indent_size = tab -------------------------------------------------------------------------------- /.github/actions/run-ee-server-for-ext-container/action.yml: -------------------------------------------------------------------------------- 1 | name: 'Run EE server for another Docker container' 2 | description: 'Run EE server and configure tests to connect to it from another Docker container' 3 | inputs: 4 | # All inputs in composite actions are strings 5 | use-server-rc: 6 | required: true 7 | default: false 8 | server-tag: 9 | required: true 10 | default: 'latest' 11 | # Github Composite Actions can't access secrets 12 | # so we need to pass them in as inputs 13 | docker-hub-username: 14 | required: false 15 | docker-hub-password: 16 | required: false 17 | 18 | runs: 19 | using: "composite" 20 | steps: 21 | - name: Run EE server 22 | uses: ./.github/actions/run-ee-server 23 | with: 24 | use-server-rc: ${{ inputs.use-server-rc }} 25 | server-tag: ${{ inputs.server-tag }} 26 | docker-hub-username: ${{ inputs.docker-hub-username }} 27 | docker-hub-password: ${{ inputs.docker-hub-password }} 28 | 29 | - name: Get IP address of Docker container hosting server 30 | id: get-server-ip-address 31 | run: echo server-ip=$(docker container inspect -f '{{ .NetworkSettings.IPAddress }}' aerospike) >> $GITHUB_OUTPUT 32 | shell: bash 33 | 34 | 35 | - name: Configure tests to connect to that Docker container 36 | run: | 37 | pipx install crudini --pip-args "-c ${{ github.workspace }}/.github/workflows/requirements.txt"; 38 | crudini --existing=param --set config.conf enterprise-edition hosts ${{ steps.get-server-ip-address.outputs.server-ip }}:3000; 39 | cat config.conf 40 | working-directory: .github/workflows 41 | shell: bash 42 | -------------------------------------------------------------------------------- /.github/actions/setup-docker-on-macos/action.yml: -------------------------------------------------------------------------------- 1 | name: 'Install Docker on macOS runner' 2 | description: 'Install Docker using colima' 3 | 4 | runs: 5 | using: "composite" 6 | steps: 7 | - name: Install Docker Engine 8 | run: brew install colima 9 | shell: bash 10 | 11 | - name: Install Docker client 12 | run: brew install docker 13 | shell: bash 14 | 15 | - name: Start Docker Engine 16 | run: colima start 17 | shell: bash 18 | -------------------------------------------------------------------------------- /.github/actions/update-version/action.yml: -------------------------------------------------------------------------------- 1 | name: 'Update version' 2 | description: 'Update version in repo without committing. Repo must already be checked out' 3 | inputs: 4 | new_version: 5 | description: Version string to set 6 | required: true 7 | 8 | runs: 9 | using: "composite" 10 | steps: 11 | - name: Update VERSION metadata 12 | run: npm version ${{ inputs.new_version }} --no-git-tag-version 13 | shell: bash 14 | -------------------------------------------------------------------------------- /.github/actions/wait-for-as-server-to-start/action.yml: -------------------------------------------------------------------------------- 1 | name: 'Wait for Aerospike server to start' 2 | description: Only tested on Linux and macOS 3 | inputs: 4 | container-name: 5 | required: true 6 | is-security-enabled: 7 | required: false 8 | default: 'false' 9 | is-strong-consistency-enabled: 10 | required: false 11 | default: 'false' 12 | 13 | runs: 14 | using: "composite" 15 | steps: 16 | - name: 'macOS: install timeout command' 17 | if: ${{ runner.os == 'macOS' }} 18 | run: brew install coreutils 19 | shell: bash 20 | 21 | # Composite actions doesn't support step-level timeout-minutes 22 | # Use timeout command and store polling logic in file to make it easier to read 23 | # Call bash shell explicitly since timeout uses "sh" shell by default, for some reason 24 | # Also, we don't want to fail if we timeout in case the server *did* finish starting up but the script couldn't detect it due to a bug 25 | # Effectively, this composite action is like calling "sleep" that is optimized to exit early when it detects an ok from the server 26 | - name: Wait for EE server to start 27 | run: timeout 30 bash ./.github/workflows/wait-for-as-server-to-start.bash ${{ inputs.container-name }} ${{ inputs.is-security-enabled }} ${{ inputs.is-strong-consistency-enabled }} || true 28 | shell: bash 29 | -------------------------------------------------------------------------------- /.github/workflows/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG image 2 | FROM $image 3 | RUN echo -e "security {\n\tenable-quotas true\n}\n" >> /etc/aerospike/aerospike.template.conf 4 | # security.smd was generated manually by 5 | # 1. Starting a new Aerospike EE server using Docker 6 | # 2. Creating the superuser user 7 | # 3. Copying /opt/aerospike/smd/security.smd from the container and committing it to this repo 8 | # This file should always work 9 | # TODO: generate this automatically, somehow 10 | COPY security.smd /opt/aerospike/smd/ 11 | -------------------------------------------------------------------------------- /.github/workflows/bump-dev-num.js: -------------------------------------------------------------------------------- 1 | const semver = require('semver') 2 | 3 | const versionString = process.argv[2] 4 | const promote = process.argv[3] 5 | 6 | const version = semver.parse(versionString) 7 | 8 | if (!version) { 9 | console.error('Invalid version string') 10 | process.exit(1) 11 | } 12 | 13 | if (version.prerelease.includes('dev')) { 14 | // Increment the dev release number 15 | if(promote){ 16 | version.prerelease = ['rc', 1]; // Transition to rc with the first RC number 17 | } 18 | else { 19 | version.inc('prerelease', 'dev') 20 | 21 | } 22 | } else if (version.prerelease.includes('rc')) { 23 | // Increment the RC number 24 | if(promote){ 25 | version.prerelease = [] 26 | version.inc('patch') // Bump to next minor version 27 | 28 | } 29 | else { 30 | version.inc('prerelease', 'rc') 31 | 32 | } 33 | } else { 34 | // Create the first dev pre-release 35 | version.prerelease = ['dev', 1]; // Transition to rc with the first RC number 36 | } 37 | 38 | console.log(version.format()) 39 | -------------------------------------------------------------------------------- /.github/workflows/bump-stage-and-upload-to-jfrog.yml: -------------------------------------------------------------------------------- 1 | on: 2 | workflow_call: 3 | inputs: 4 | passed-dev-tag: 5 | type: string 6 | description: Dev tag to fast forward the stage branch to 7 | required: true 8 | secrets: 9 | # Used to bump version in Github 10 | CLIENT_BOT_PAT: 11 | required: true 12 | # Used to upload to JFrog 13 | JFROG_PLATFORM_URL: 14 | required: true 15 | 16 | jobs: 17 | ff-stage-to-dev-tag: 18 | name: Fast forward stage branch to the dev tag that passed stage testing 19 | uses: ./.github/workflows/fast-forward-merge.yml 20 | with: 21 | ref_to_merge: ${{ inputs.passed-dev-tag }} 22 | base_branch: ${{ vars.STAGE_BRANCH_NAME }} 23 | secrets: inherit 24 | 25 | promote-dev-build-to-rc: 26 | name: Bump (promote) the dev version to an RC version in the stage branch 27 | needs: ff-stage-to-dev-tag 28 | uses: ./.github/workflows/bump-version.yml 29 | with: 30 | change: 'promote-dev-build-to-rc' 31 | ref: ${{ vars.STAGE_BRANCH_NAME }} 32 | secrets: inherit 33 | 34 | rebuild-artifacts-with-rc-version: 35 | needs: promote-dev-build-to-rc 36 | uses: ./.github/workflows/build-artifacts.yml 37 | secrets: inherit 38 | 39 | upload-rc-artifacts-to-jfrog: 40 | needs: [ 41 | rebuild-artifacts-with-rc-version, 42 | # We need the new RC version to label the build in JFrog 43 | promote-dev-build-to-rc 44 | ] 45 | name: Upload artifacts to JFrog 46 | uses: ./.github/workflows/upload-to-jfrog.yml 47 | with: 48 | version: ${{ needs.promote-dev-build-to-rc.outputs.new_version }} 49 | secrets: inherit 50 | 51 | # See reason for deleting artifacts in dev-workflow-p2.yml 52 | delete-artifacts: 53 | needs: upload-rc-artifacts-to-jfrog 54 | uses: ./.github/workflows/delete-artifacts.yml 55 | 56 | ff-dev-to-stage: 57 | name: Fast forward dev branch to stage branch to include the bump to RC commit 58 | needs: promote-dev-build-to-rc 59 | uses: ./.github/workflows/fast-forward-merge.yml 60 | with: 61 | ref_to_merge: origin/${{ vars.STAGE_BRANCH_NAME }} 62 | base_branch: ${{ vars.DEV_BRANCH_NAME }} 63 | secrets: inherit 64 | -------------------------------------------------------------------------------- /.github/workflows/config.conf.template: -------------------------------------------------------------------------------- 1 | [community-edition] 2 | hosts: 127.0.0.1:3000 3 | 4 | [enterprise-edition] 5 | hosts : 6 | user : 7 | password : 8 | -------------------------------------------------------------------------------- /.github/workflows/delete-artifacts.yml: -------------------------------------------------------------------------------- 1 | on: 2 | workflow_call: 3 | 4 | jobs: 5 | delete-artifacts: 6 | runs-on: ubuntu-22.04 7 | steps: 8 | - name: Remove artifacts with dev version 9 | uses: geekyeggo/delete-artifact@v5 10 | with: 11 | name: '*.node' 12 | -------------------------------------------------------------------------------- /.github/workflows/dev-workflow-p1.yml: -------------------------------------------------------------------------------- 1 | #name: Dev workflow (part 1) 2 | # 3 | ## 1. When a PR review is requested, run tests on that PR 4 | ## 2. If all of the tests pass, allow the PR to be merged into `dev` 5 | ## 3. Whenever a PR is merged to `dev`, bump version number in `dev` 6 | # 7 | #on: 8 | # pull_request: 9 | # types: 10 | # - opened 11 | # - review_requested 12 | # - synchronize 13 | # branches: 14 | # - 'dev*' 15 | # - 'dev-CICD' 16 | # - '2024-Pipeline-Improvement' 17 | # paths-ignore: 18 | # - 'docs/**' 19 | # - 'aerospike-stubs/**' 20 | # 21 | # # So we can test changes to the test-server-rc workflow 22 | # workflow_dispatch: 23 | # inputs: 24 | # run_server_release_tests: 25 | # description: 'DEBUG: Run server release tests in build-wheels workflow?' 26 | # type: boolean 27 | # default: false 28 | # 29 | #jobs: 30 | # test-with-server-release: 31 | # uses: ./.github/workflows/build-artifacts.yml 32 | # with: 33 | # run_tests: false 34 | # secrets: inherit 35 | # 36 | ## bump-dev-number: 37 | ## #if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true }} 38 | ## uses: ./.github/workflows/bump-version.yml 39 | ## needs: [ 40 | ## test-with-server-release 41 | ## ] 42 | ## with: 43 | ## change: 'bump-dev-num' 44 | ## secrets: inherit 45 | # 46 | # upload-to-jfrog: 47 | # name: Upload artifacts to JFrog 48 | # needs: [ 49 | # test-with-server-release, 50 | # #bump-dev-number 51 | # ] 52 | # uses: ./.github/workflows/upload-to-jfrog.yml 53 | # with: 54 | # version: 6.2.0-dev.14 55 | # secrets: inherit 56 | # 57 | # # We don't want the artifacts in JFrog to also exist in Github 58 | # delete-artifacts: 59 | # needs: upload-to-jfrog 60 | # uses: ./.github/workflows/delete-artifacts.yml 61 | ## -------------------------------------------------------------------------------- /.github/workflows/docker-build-context/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG server_image=aerospike/aerospike-server-enterprise:8.0.0.5 2 | ARG ROSTER_FILE_NAME=roster.smd 3 | # Temp file for passing node id from one build stage to another 4 | # Docker doesn't support command substitution for setting values for ARG variables, so we have to do this 5 | ARG NODE_ID_FILE_NAME=node_id 6 | 7 | FROM $server_image as configure-server 8 | 9 | WORKDIR /opt/aerospike/smd 10 | 11 | # Enable authentication 12 | 13 | ARG AEROSPIKE_CONF_TEMPLATE_PATH=/etc/aerospike/aerospike.template.conf 14 | 15 | # Not using asconfig to edit config because we are working with a template file, which may not have valid values yet 16 | RUN echo -e "security {\n\tenable-quotas true\n}\n" >> $AEROSPIKE_CONF_TEMPLATE_PATH 17 | # security.smd was generated manually by 18 | # 1. Starting a new Aerospike EE server using Docker 19 | # 2. Creating the superuser user 20 | # 3. Copying /opt/aerospike/smd/security.smd from the container and committing it to this repo 21 | # This file should always work 22 | # TODO: generate this automatically, somehow. 23 | COPY security.smd . 24 | 25 | # Enable strong consistency 26 | RUN sed -i "s/\(namespace.*{\)/\1\n\tstrong-consistency true/" $AEROSPIKE_CONF_TEMPLATE_PATH 27 | RUN sed -i "s/\(namespace.*{\)/\1\n\tstrong-consistency-allow-expunge true/" $AEROSPIKE_CONF_TEMPLATE_PATH 28 | RUN sed -i "s/\(namespace.*{\)/\1\n\tdefault-ttl 2592000/" $AEROSPIKE_CONF_TEMPLATE_PATH 29 | ARG ROSTER_FILE_NAME 30 | COPY $ROSTER_FILE_NAME . 31 | 32 | # Fetch node id from roster.smd 33 | 34 | # There's no tag for the latest major version to prevent breaking changes in jq 35 | # This is the next best thing 36 | FROM ghcr.io/jqlang/jq:1.7 as get-jq 37 | # jq docker image doesn't have a shell 38 | # We need a shell to fetch and pass the node id to the next build stage 39 | FROM busybox as get-node-id 40 | COPY --from=get-jq /jq /bin/ 41 | ARG ROSTER_FILE_NAME 42 | COPY $ROSTER_FILE_NAME . 43 | ARG NODE_ID_FILE_NAME 44 | RUN jq --raw-output '.[1].value' $ROSTER_FILE_NAME > $NODE_ID_FILE_NAME 45 | 46 | FROM configure-server as set-node-id 47 | ARG NODE_ID_FILE_NAME 48 | COPY --from=get-node-id $NODE_ID_FILE_NAME . 49 | RUN sed -i "s/\(^service {\)/\1\n\tnode-id $(cat $NODE_ID_FILE_NAME)/" $AEROSPIKE_CONF_TEMPLATE_PATH 50 | RUN rm $NODE_ID_FILE_NAME -------------------------------------------------------------------------------- /.github/workflows/docker-build-context/roster.smd: -------------------------------------------------------------------------------- 1 | [ 2 | [ 3 | 97107025374203, 4 | 1 5 | ], 6 | { 7 | "key": "test", 8 | "value": "a1", 9 | "generation": 1, 10 | "timestamp": 465602976982 11 | } 12 | ] -------------------------------------------------------------------------------- /.github/workflows/docker-build-context/security.smd: -------------------------------------------------------------------------------- 1 | [ 2 | [ 3 | 162276881999406, 4 | 14 5 | ], 6 | { 7 | "key": "admin|P", 8 | "value": "$2a$10$7EqJtq98hPqEX7fNZaFWoO1mVO/4MLpGzsqojz6E9Gef6iXDjXdDa", 9 | "generation": 1, 10 | "timestamp": 0 11 | }, 12 | { 13 | "key": "admin|R|user-admin", 14 | "value": "", 15 | "generation": 1, 16 | "timestamp": 0 17 | }, 18 | { 19 | "key": "superuser|P", 20 | "value": "$2a$10$7EqJtq98hPqEX7fNZaFWoOZX0o4mZCBUwvzt/iecIcG4JaDOC41zK", 21 | "generation": 3, 22 | "timestamp": 458774922440 23 | }, 24 | { 25 | "key": "superuser|R|read-write-udf", 26 | "value": "", 27 | "generation": 3, 28 | "timestamp": 458774922441 29 | }, 30 | { 31 | "key": "superuser|R|sys-admin", 32 | "value": "", 33 | "generation": 3, 34 | "timestamp": 458774922442 35 | }, 36 | { 37 | "key": "superuser|R|user-admin", 38 | "value": "", 39 | "generation": 3, 40 | "timestamp": 458774922442 41 | }, 42 | { 43 | "key": "superuser|R|data-admin", 44 | "value": null, 45 | "generation": 2, 46 | "timestamp": 458774718056 47 | } 48 | ] 49 | -------------------------------------------------------------------------------- /.github/workflows/fast-forward-merge.yml: -------------------------------------------------------------------------------- 1 | # As of this writing, there are no Github Actions in the marketplace 2 | # that allow fast forwarding using a personal access token 3 | # So we need to use this for now 4 | name: 'Fast forward merge' 5 | on: 6 | workflow_dispatch: 7 | inputs: 8 | ref_to_merge: 9 | type: string 10 | required: true 11 | base_branch: 12 | type: string 13 | required: true 14 | workflow_call: 15 | inputs: 16 | # If another branch, it must be origin/ 17 | ref_to_merge: 18 | type: string 19 | required: true 20 | base_branch: 21 | type: string 22 | required: true 23 | secrets: 24 | CLIENT_BOT_PAT: 25 | required: true 26 | 27 | jobs: 28 | merge: 29 | runs-on: ubuntu-22.04 30 | steps: 31 | - name: Checkout 32 | uses: actions/checkout@v4 33 | with: 34 | # Fetch the whole history to prevent unrelated history errors 35 | fetch-depth: '0' 36 | ref: ${{ inputs.base_branch }} 37 | token: ${{ secrets.CLIENT_BOT_PAT }} 38 | 39 | - name: Fast forward 40 | run: git merge --ff-only ${{ inputs.ref_to_merge }} 41 | 42 | - name: Upload changes to remote head branch 43 | run: git push 44 | -------------------------------------------------------------------------------- /.github/workflows/release-package.yml: -------------------------------------------------------------------------------- 1 | name: Release workflow 2 | 3 | on: 4 | workflow_call: 5 | workflow_dispatch: 6 | paths-ignore: 7 | - 'package.json' 8 | 9 | jobs: 10 | # bump-dev-number: 11 | # #if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true }} 12 | # uses: ./.github/workflows/bump-version.yml 13 | # with: 14 | # change: 'bump-dev-num' 15 | # secrets: inherit 16 | 17 | # rebuild-artifacts-with-new-dev-num: 18 | # name: Rebuild artifacts 19 | # uses: ./.github/workflows/build-artifacts.yml 20 | # with: 21 | # # On pull_request_target, the bump version commit will be ignored 22 | # # So we must pass it manually to the workflow 23 | # run_tests: false 24 | # secrets: inherit 25 | # 26 | # test-npm-install: 27 | # needs: rebuild-artifacts-with-new-dev-num 28 | # name: Test npm install command for npm package 29 | # uses: ./.github/workflows/npm-install-script-test.yml 30 | 31 | # upload-to-jfrog: 32 | # name: Upload artifacts to JFrog 33 | # needs: [ 34 | # bump-dev-number, 35 | # rebuild-artifacts-with-new-dev-num 36 | # ] 37 | # uses: ./.github/workflows/upload-to-jfrog.yml 38 | # with: 39 | # version: ${{ needs.bump-dev-number.outputs.new_version }} 40 | # secrets: inherit 41 | # 42 | # # We don't want the artifacts in JFrog to also exist in Github 43 | # delete-artifacts: 44 | # needs: upload-to-jfrog 45 | # uses: ./.github/workflows/delete-artifacts.yml 46 | # -------------------------------------------------------------------------------- /.github/workflows/requirements.txt: -------------------------------------------------------------------------------- 1 | parver==0.5 2 | crudini==0.9.4 3 | delocate==0.10.4 4 | mypy==1.10.0 5 | -------------------------------------------------------------------------------- /.github/workflows/stage-workflow-p1.yml: -------------------------------------------------------------------------------- 1 | #name: Stage workflow (part 1) 2 | # 3 | ## 1. When a PR review is requested, run tests on that PR 4 | ## 2. If all of the tests pass, allow the PR to be merged into `dev` 5 | ## 3. Whenever a PR is merged to `dev`, bump version number in `dev` 6 | # 7 | #on: 8 | # pull_request: 9 | # types: 10 | # - opened 11 | # - review_requested 12 | # - synchronize 13 | # branches: 14 | # - 'dev*' 15 | # - 'dev-CICD' 16 | # - '2024-Pipeline-Improvement' 17 | # paths-ignore: 18 | # - 'docs/**' 19 | # - 'aerospike-stubs/**' 20 | # 21 | # # So we can test changes to the test-server-rc workflow 22 | # workflow_dispatch: 23 | # inputs: 24 | # run_server_release_tests: 25 | # description: 'DEBUG: Run server release tests in build-wheels workflow?' 26 | # type: boolean 27 | # default: false 28 | # 29 | #jobs: 30 | # download-jfrog-artifacts: 31 | # uses: ./.github/workflows/download-jfrog-artifacts.yml 32 | # with: 33 | # version: 6.2.0-dev.14 34 | # secrets: inherit 35 | # 36 | ## test-with-server-release: 37 | ## uses: ./.github/workflows/test-artifacts.yml 38 | ## needs: [ 39 | ## download-jfrog-artifacts 40 | ## ] 41 | ## with: 42 | ## run_tests: true 43 | ## secrets: inherit 44 | # 45 | ## bump-dev-number: 46 | ## #if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true }} 47 | ## uses: ./.github/workflows/bump-version.yml 48 | ## needs: [ 49 | ## download-jfrog-artifacts, 50 | ## test-with-server-release 51 | ## ] 52 | ## with: 53 | ## change: 'bump-dev-num' 54 | ## secrets: inherit 55 | # 56 | # upload-to-jfrog: 57 | # name: Upload artifacts to JFrog 58 | # needs: [ 59 | # download-jfrog-artifacts, 60 | # #test-with-server-release, 61 | # #bump-dev-number 62 | # ] 63 | # uses: ./.github/workflows/upload-to-jfrog.yml 64 | # with: 65 | # stage: true 66 | # version: 6.2.0-rc.15 67 | # secrets: inherit 68 | # 69 | # # We don't want the artifacts in JFrog to also exist in Github 70 | # delete-artifacts: 71 | # needs: upload-to-jfrog 72 | # uses: ./.github/workflows/delete-artifacts.yml 73 | # 74 | ## test-with-server-rc: 75 | ## needs: test-with-server-release 76 | ## if: ${{ github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'new-server-features') }} 77 | ## uses: ./.github/workflows/test-server-rc.yml 78 | ## secrets: inherit 79 | ## -------------------------------------------------------------------------------- /.github/workflows/update-version.yml: -------------------------------------------------------------------------------- 1 | # Takes in a new version as input 2 | # Changes the version in the whole repo and outputs the commit hash as output 3 | 4 | name: Update version in repo 5 | on: 6 | workflow_dispatch: 7 | inputs: 8 | new_version: 9 | type: string 10 | description: Version string to set in the repo 11 | required: true 12 | workflow_call: 13 | inputs: 14 | new_version: 15 | type: string 16 | description: Version string to set in the repo 17 | required: true 18 | is_workflow_call: 19 | type: boolean 20 | default: true 21 | required: false 22 | secrets: 23 | CLIENT_BOT_PAT: 24 | required: true 25 | outputs: 26 | bump_sha: 27 | value: ${{ jobs.update-version-in-repo.outputs.bump_sha }} 28 | 29 | jobs: 30 | update-version-in-repo: 31 | name: Update version in repo 32 | runs-on: ubuntu-22.04 33 | outputs: 34 | bump_sha: ${{ steps.get-bump-commit-sha.outputs.bump_sha }} 35 | steps: 36 | 37 | - uses: actions/checkout@v4 38 | with: 39 | token: ${{ secrets.CLIENT_BOT_PAT }} 40 | ref: ${{ inputs.ref }} 41 | 42 | - name: Update version in repo 43 | uses: ./.github/actions/update-version 44 | with: 45 | new_version: ${{ inputs.new_version }} 46 | 47 | - name: Commit new version 48 | uses: stefanzweifel/git-auto-commit-action@v4 49 | with: 50 | commit_message: 'Auto-bump version to ${{ inputs.new_version }} [skip ci]' 51 | commit_author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> 52 | tagging_message: ${{ inputs.new_version }} 53 | branch: metrics-2025 54 | #branch: ${{ inputs.is_workflow_call && inputs.ref || github.ref }} 55 | 56 | - name: Output bump commit hash for next jobs to use 57 | id: get-bump-commit-sha 58 | run: echo "bump_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT 59 | -------------------------------------------------------------------------------- /.github/workflows/verify-npm-install.yml: -------------------------------------------------------------------------------- 1 | name: 'Donwload github artifacts' 2 | description: 'Download github artifacts for all supported versions' 3 | 4 | on: 5 | workflow_call: 6 | inputs: 7 | nodejs-tags: 8 | type: string 9 | required: false 10 | default: '[["v108", "18"], ["v115", "20"], ["v127", "22"], ["v131", "23"]]' 11 | 12 | jobs: 13 | run-npm-install-and-require-test: 14 | strategy: 15 | fail-fast: false 16 | matrix: 17 | os: [ubuntu-22.04, ubuntu-20.04, ubuntu-22.04-arm, macos-13-large, SMA2, windows-2022] 18 | nodejs-tag: ${{ fromJSON(inputs.nodejs-tags) }} 19 | runs-on: ${{ matrix.os }} 20 | steps: 21 | - name: Delete workspace 22 | if: ${{ matrix.os != 'windows-2022' }} 23 | run: rm -rf ${{ github.workspace }}/* 24 | 25 | - uses: actions/setup-node@v4 26 | with: 27 | node-version: ${{ matrix.nodejs-tag[1] }} 28 | 29 | - name: verify runs and is aligned 30 | run: | 31 | npm install aerospike@6.2.0 --omit-dev; 32 | node -e "const { BatchWritePolicy } = require('aerospike'); console.log(new BatchWritePolicy({onLockingOnly: true}));" -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .nyc_output/ 3 | .vscode/ 4 | lib/binding 5 | .idea/ 6 | build/ 7 | node_modules/ 8 | coverage/ 9 | npm-debug.log 10 | test.log 11 | aerospike-*.tgz 12 | scripts/build-c-client.sh-output.txt 13 | libuv* 14 | docs* 15 | ts-test/dist 16 | ts-test/metrics-* 17 | scripts/build-c-client.sh-cclient-output.log 18 | tsconfig.tsbuildinfos -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "aerospike-client-c"] 2 | path = aerospike-client-c 3 | url = https://github.com/aerospike/aerospike-client-c.git 4 | branch = master 5 | -------------------------------------------------------------------------------- /.husky/.gitignore: -------------------------------------------------------------------------------- 1 | _ 2 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | npm test -- --invert --fgrep "#slow" --reporter progress 5 | -------------------------------------------------------------------------------- /.jfrog/projects/npm.yaml: -------------------------------------------------------------------------------- 1 | version: 1 2 | type: npm 3 | resolver: 4 | repo: clients-npm-dev-local 5 | serverId: Default-Server 6 | deployer: 7 | repo: clients-npm-dev-local 8 | serverId: Default-Server 9 | -------------------------------------------------------------------------------- /.mocharc.yml: -------------------------------------------------------------------------------- 1 | require: 2 | - choma 3 | - mocha-clean 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '15' 4 | - '14' 5 | - '12' 6 | - '10' 7 | - '8' 8 | env: 9 | global: 10 | - AEROSPIKE_HOSTS=127.0.0.1:3000,127.0.0.1:3100 11 | - OPTIONS="--timeout 2000" 12 | sudo: false 13 | os: linux 14 | dist: xenial 15 | before_script: 16 | - .travis/start_cluster.sh 2 17 | install: 18 | - npm install 19 | script: 20 | - npm run coverage 21 | after_script: 22 | - npm run codecov 23 | notifications: 24 | email: 25 | - qe-notices@aerospike.com 26 | - qe-notices-clients@aerospike.com 27 | slack: 28 | secure: BMIMHhqOMQnP7STsq/5WDoTKUlvB0pWCn6g6YnqKmVN2v2tMoTIBEmJlleMXBEL+0Ou4dLUmTmQKzzpiAw9tXtvgIjVh3luE+tM2QLJfwLqGshRemqwtF7DSzv5+UYEiZh0g18pQrk3HUJdD7BkU1LKkdjorgxC4rsnt+7Iz8Z0= 29 | -------------------------------------------------------------------------------- /.travis/aerospike.conf: -------------------------------------------------------------------------------- 1 | # Aerospike database configuration file. 2 | 3 | # This stanza must come first. 4 | service { 5 | user ${user} 6 | group ${group} 7 | run-as-daemon 8 | paxos-single-replica-limit 1 # Number of nodes where the replica count is automatically reduced to 1. 9 | pidfile ${home}/var/run/aerospike.pid 10 | proto-fd-max 15000 11 | work-directory ${home}/var 12 | cluster-name testCluster 13 | } 14 | 15 | logging { 16 | # Log file must be an absolute path. 17 | file ${home}/var/log/aerospike.log { 18 | context any info 19 | } 20 | } 21 | 22 | mod-lua { 23 | user-path ${home}/var/udf/lua 24 | } 25 | 26 | network { 27 | service { 28 | address ${service_addr} 29 | port ${service_port} 30 | } 31 | 32 | heartbeat { 33 | mode multicast 34 | multicast-group ${multicast_addr} 35 | port ${multicast_port} 36 | 37 | interval 150 38 | timeout 10 39 | } 40 | 41 | fabric { 42 | port ${fabric_port} 43 | } 44 | 45 | info { 46 | port ${info_port} 47 | } 48 | } 49 | 50 | namespace test { 51 | replication-factor 2 52 | memory-size 1G 53 | allow-ttl-without-nsup true 54 | storage-engine memory 55 | } 56 | -------------------------------------------------------------------------------- /.travis/start_cluster.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################################################################ 3 | # Copyright 2013-2023 Aerospike, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | ################################################################################ 17 | 18 | nodes=${1:-1} 19 | home=$(pwd) 20 | 21 | function wait_for_node { 22 | log=$1 23 | if [ ! -f $log ] 24 | then 25 | echo "A log file does not exist at $(pwd)/${log}" 26 | exit 1 27 | fi 28 | 29 | i=0 30 | while [ $i -le 12 ] 31 | do 32 | sleep 1 33 | grep -i "there will be cake" ${log} 34 | if [ $? == 0 ]; then 35 | return 0 36 | else 37 | i=$(($i + 1)) 38 | echo -n "." 39 | fi 40 | done 41 | echo "The cake is a lie!" 42 | tail -n 1000 ${log} 43 | exit 2 44 | } 45 | 46 | function start_server { 47 | instance=$1 48 | dir="instance${instance}" 49 | port=$((2900 + 100 * $instance)) 50 | mkdir ${dir} 51 | ./bin/aerospike init --home ${dir} --instance ${instance} --service-port ${port} 52 | cd ${dir} 53 | ./bin/aerospike start 54 | wait_for_node "var/log/aerospike.log" 55 | cd .. 56 | } 57 | 58 | function install_server { 59 | wget -nv -O aerospike-server.tgz http://aerospike.com/download/server/latest/artifact/tgz 60 | tar xzf aerospike-server.tgz 61 | cp -f .travis/aerospike.conf ./aerospike-server/share/etc 62 | cd aerospike-server 63 | sed -i -e 's/\${me}/"root"/' share/libexec/aerospike-start 64 | sed -i -e 's/set_shmmax$/#set_shmmax/' share/libexec/aerospike-start 65 | sed -i -e 's/set_shmall$/#set_shmall/' share/libexec/aerospike-start 66 | sed -i -e 's/set_socket_buffer_limits$/#set_socket_buffer_limits/' share/libexec/aerospike-start 67 | sed -i -e 's/ulimit/#ulimit/' share/libexec/aerospike-start 68 | } 69 | 70 | echo "## Fetching Aerospike server distribution" 71 | install_server 72 | for ((node = 1; node <= nodes; node++)) 73 | do 74 | echo "## Starting Aerospike server instance ${node}/${nodes}" 75 | start_server $node 76 | done 77 | cd ${pwd} 78 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | VALGRIND_OPTS = --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes -v 4 | 5 | 6 | default: build 7 | 8 | .PHONY: build 9 | build: 10 | node-gyp build 11 | 12 | .PHONY: test 13 | test: build 14 | npm test 15 | 16 | .PHONY: empty-valgrind 17 | empty-valgrind: build 18 | mkdir -p valgrind 19 | valgrind $(VALGRIND_OPTS) node -e "" 1>valgrind/empty.out 2>valgrind/empty.valgrind 20 | 21 | .PHONY: test-valgrind 22 | test-valgrind: build 23 | mkdir -p valgrind 24 | valgrind $(VALGRIND_OPTS) npm test 1>valgrind/test.out 2>valgrind/test.valgrind 25 | 26 | .PHONY: benchmark-valgrind 27 | benchmark-valgrind: build 28 | mkdir -p valgrind 29 | valgrind $(VALGRIND_OPTS) node benchmarks/main.js -O 10000 -P 4 -R 0.5 1>valgrind/benchmark.out 2>valgrind/benchmark.valgrind 30 | 31 | .PHONY: put-valgrind 32 | put-valgrind: build 33 | mkdir -p valgrind 34 | valgrind $(VALGRIND_OPTS) node examples/put.js -q -I 100 foo 1>valgrind/put-100.out 2>valgrind/put-100.valgrind 35 | 36 | .PHONY: put 37 | put: build 38 | node examples/put.js -q -I 100 foo 39 | 40 | .PHONY: get-valgrind 41 | get-valgrind: build 42 | mkdir -p valgrind 43 | valgrind $(VALGRIND_OPTS) node examples/get.js -q -I 100 foo 1>valgrind/get-100.out 2>valgrind/get-100.valgrind 44 | 45 | .PHONY: get 46 | get: build 47 | node examples/get.js -q -I 100 foo 48 | 49 | .PHONY: query-valgrind 50 | query-valgrind: build 51 | mkdir -p valgrind 52 | node examples/index_create.js s idx_s string 53 | # valgrind $(VALGRIND_OPTS) node examples/query.js -I 1 1>valgrind/query-1.out 2>valgrind/query-1.valgrind 54 | valgrind $(VALGRIND_OPTS) node --expose-gc examples/query.js -q -I 100 1>valgrind/query-100.out 2>valgrind/query-100.valgrind 55 | # valgrind $(VALGRIND_OPTS) node examples/query.js -I 1000 1>valgrind/query-1000.out 2>valgrind/query-1000.valgrind 56 | # valgrind $(VALGRIND_OPTS) node examples/query.js -I 10000 1>valgrind/query-10000.out 2>valgrind/query-10000.valgrind 57 | 58 | .PHONY: query 59 | query: build 60 | node examples/index_create.js s idx_s string 61 | # node --expose-gc examples/query.js -I 1 62 | # node --expose-gc examples/query.js -I 100 63 | node --expose-gc examples/query.js -q -I 1000 64 | # node --expose-gc examples/query.js -I 10000 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /aerospike-client-c.ini: -------------------------------------------------------------------------------- 1 | 2 | # Version number of the dependencies package for C client (Windows only) 3 | AEROSPIKE_C_DEPS_VERSION=1.0.2 4 | -------------------------------------------------------------------------------- /aerospike-client-c.sha256: -------------------------------------------------------------------------------- 1 | BB7AEB63571E63FD6C9CD042DC1810743DF9C8F122C91EAFB705C2E08B87733A aerospike-client-c-dependencies.1.0.2.zip 2 | -------------------------------------------------------------------------------- /benchmarks/.npmignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /benchmarks/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "host" : "bob-cluster-a", 3 | "port" : 3000, 4 | "timeout" : 0, 5 | "totalTimeout" : 0, 6 | "ttl" : 10000, 7 | "log" : "INFO", 8 | "namespace" : "test", 9 | "set" : "demo", 10 | "user" : "generic_client", 11 | "password" : "generic_client", 12 | "json" : false, 13 | "silent" : false, 14 | "longevity" : false, 15 | "alert" : "CONSOLE", 16 | "filename" : null, 17 | "operations" : 10, 18 | "iterations" : null, 19 | "processes" : 4, 20 | "time" : "1h", 21 | "reads" : 1, 22 | "writes" : 1, 23 | "keyRange" : { 24 | "min" : 0, 25 | "max" : 100000 26 | }, 27 | "binSpec" : [ 28 | { 29 | "name" : "bin1", 30 | "type" : "STRING", 31 | "size" : 1024 32 | }, 33 | { 34 | "name" : "bin2", 35 | "type" : "BYTES", 36 | "size" : 1024 37 | }, 38 | { 39 | "name" : "bin3", 40 | "type" : "INTEGER" 41 | } 42 | ], 43 | "promises" : true, 44 | "summary" : true 45 | } 46 | -------------------------------------------------------------------------------- /benchmarks/logging.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | const { createLogger, format, transports } = require('winston') 18 | 19 | exports.logger = createLogger({ 20 | format: format.combine( 21 | format.splat(), 22 | format.simple() 23 | ), 24 | transports: [ 25 | new transports.Console({ 26 | level: 'info', 27 | silent: false, 28 | colorize: true 29 | }) 30 | ] 31 | }) 32 | -------------------------------------------------------------------------------- /benchmarks/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "aerospike-benchmark", 3 | "version": "v0.1.0", 4 | "description": "Aerospike Client Benchmark", 5 | "keywords": [ 6 | "aerospike", 7 | "database", 8 | "nosql", 9 | "benchmark" 10 | ], 11 | "license": "Apache-2.0", 12 | "engines": { 13 | "node": ">=4" 14 | }, 15 | "os": [ 16 | "linux", 17 | "darwin" 18 | ], 19 | "cpu": [ 20 | "x64" 21 | ], 22 | "repository": { 23 | "type": "git", 24 | "url": "https://github.com/aerospike/aerospike-client-nodejs" 25 | }, 26 | "dependencies": { 27 | "aerospike": "file:..", 28 | "cli-table": "^0.3.11", 29 | "winston": "^3.5.1", 30 | "yargs": "^16.2.0" 31 | }, 32 | "main": "main.js" 33 | } 34 | -------------------------------------------------------------------------------- /docker/README.md: -------------------------------------------------------------------------------- 1 | # Docker Examples 2 | 3 | The docker files that were previously located in this directory have been moved to 4 | the [Nodejs-Client-Examples](https://github.com/aerospike-examples/nodejs-client-examples) directory. 5 | 6 | Files in this directory are not intended for production use, but rather to demonstrate the steps 7 | necessary to install and build the client on various systems. -------------------------------------------------------------------------------- /eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import globals from 'globals' 2 | import pluginJs from '@eslint/js' 3 | import tseslint from 'typescript-eslint' 4 | 5 | export default [ 6 | { files: ['**/*.{js,mjs,cjs,ts}'] }, 7 | { languageOptions: { globals: globals.browser } }, 8 | pluginJs.configs.recommended, 9 | ...tseslint.configs.recommended 10 | ] 11 | -------------------------------------------------------------------------------- /examples/.npmignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /examples/add.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // ***************************************************************************** 3 | // Copyright 2013-2024 Aerospike, Inc. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License") 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // ***************************************************************************** 17 | 18 | const Aerospike = require('aerospike') 19 | const shared = require('./shared') 20 | 21 | shared.runner() 22 | 23 | async function add (client, argv) { 24 | const key = new Aerospike.Key(argv.namespace, argv.set, argv.key) 25 | const bins = shared.cli.parseBins(argv.bins) 26 | await client.add(key, bins) 27 | console.info('Record updated successfully:', key) 28 | } 29 | 30 | exports.command = 'add ' 31 | exports.describe = 'Add one or more values to existing bin(s)' 32 | exports.handler = shared.run(add) 33 | -------------------------------------------------------------------------------- /examples/append.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // ***************************************************************************** 3 | // Copyright 2013-2024 Aerospike, Inc. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License") 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // ***************************************************************************** 17 | 18 | const Aerospike = require('aerospike') 19 | const shared = require('./shared') 20 | 21 | shared.runner() 22 | 23 | async function append (client, argv) { 24 | const key = new Aerospike.Key(argv.namespace, argv.set, argv.key) 25 | const bins = shared.cli.parseBins(argv.bins) 26 | await client.append(key, bins) 27 | console.info('Record updated successfully:', key) 28 | } 29 | 30 | exports.command = 'append ' 31 | exports.describe = 'Append one or more values to existing bin(s)' 32 | exports.handler = shared.run(append) 33 | -------------------------------------------------------------------------------- /examples/apply.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // ***************************************************************************** 3 | // Copyright 2013-2024 Aerospike, Inc. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License") 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // ***************************************************************************** 17 | // 18 | const Aerospike = require('aerospike') 19 | const shared = require('./shared') 20 | 21 | shared.runner() 22 | 23 | async function apply (client, argv) { 24 | const key = new Aerospike.Key(argv.namespace, argv.set, argv.key) 25 | 26 | const udfCall = { 27 | module: argv.module, 28 | funcname: argv.function, 29 | args: argv.args.map(arg => { 30 | try { 31 | return JSON.parse(arg) 32 | } catch (error) { 33 | return '' + arg 34 | } 35 | }) 36 | } 37 | 38 | const result = await client.apply(key, udfCall) 39 | console.info(result) 40 | } 41 | 42 | exports.command = 'apply [args...]' 43 | exports.describe = 'Apply a User-Defined Function (UDF) to a record' 44 | exports.handler = shared.run(apply) 45 | -------------------------------------------------------------------------------- /examples/batch.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // ***************************************************************************** 3 | // Copyright 2013-2024 Aerospike, Inc. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License") 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // ***************************************************************************** 17 | // 18 | const Aerospike = require('aerospike') 19 | const shared = require('./shared') 20 | 21 | shared.runner() 22 | 23 | async function batchRead (client, argv) { 24 | const batch = argv.keys.map(key => { 25 | const request = { 26 | key: new Aerospike.Key(argv.namespace, argv.set, key) 27 | } 28 | if (argv.bins) { 29 | request.bins = argv.bins 30 | } else { 31 | request.readAllBins = true 32 | } 33 | return request 34 | }) 35 | 36 | const batchResults = await client.batchRead(batch) 37 | 38 | for (const result of batchResults) { 39 | const record = result.record 40 | console.info(record.key.key, ':', 41 | result.status === Aerospike.status.OK ? record.bins : 'NOT FOUND' 42 | ) 43 | } 44 | } 45 | 46 | exports.command = 'batch ' 47 | exports.describe = 'Fetch multiple records from the database in a batch' 48 | exports.handler = shared.run(batchRead) 49 | exports.builder = { 50 | bins: { 51 | describe: 'List of bins to fetch for each record', 52 | type: 'array', 53 | group: 'Command:' 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /examples/exists.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // ***************************************************************************** 3 | // Copyright 2013-2024 Aerospike, Inc. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License") 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // ***************************************************************************** 17 | 18 | const Aerospike = require('aerospike') 19 | const shared = require('./shared') 20 | 21 | shared.runner() 22 | 23 | async function exists (client, argv) { 24 | const key = new Aerospike.Key(argv.namespace, argv.set, argv.key) 25 | const exists = await client.exists(key) 26 | console.info('Key: ', key) 27 | console.info('Record exists: ', exists) 28 | } 29 | 30 | exports.command = 'exists ' 31 | exports.describe = 'Test whether a record exists in the database' 32 | exports.handler = shared.run(exists) 33 | -------------------------------------------------------------------------------- /examples/get.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // ***************************************************************************** 3 | // Copyright 2013-2024 Aerospike, Inc. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License") 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // ***************************************************************************** 17 | // 18 | const Aerospike = require('aerospike') 19 | const shared = require('./shared') 20 | 21 | shared.runner() 22 | 23 | async function get (client, argv) { 24 | const key = new Aerospike.Key(argv.namespace, argv.set, argv.key) 25 | let record 26 | if (argv.bins) { 27 | record = await client.select(key, argv.bins) 28 | } else { 29 | record = await client.get(key) 30 | } 31 | console.info(record) 32 | } 33 | 34 | exports.command = 'get ' 35 | exports.describe = 'Fetch a record from the database' 36 | exports.handler = shared.run(get) 37 | exports.builder = { 38 | bins: { 39 | desc: 'Select specific bins to fetch', 40 | type: 'array' 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /examples/lua/monte_carlo.lua: -------------------------------------------------------------------------------- 1 | local function one(rec) 2 | return 1 3 | end 4 | 5 | local function add(a, b) 6 | return a + b 7 | end 8 | 9 | function count(stream) 10 | return stream : map(one) : reduce(add) 11 | end 12 | -------------------------------------------------------------------------------- /examples/lua/query.lua: -------------------------------------------------------------------------------- 1 | -- A simple UDF that just returns the value of the bin 'test-bin'. 2 | local function get_test_bin(rec) 3 | return rec['i'] 4 | end 5 | 6 | -- A simple arithmetic UDF that adds two arguments and returns the result. 7 | local function add(a, b) 8 | return a + b 9 | end 10 | 11 | -- An aggregation UDF that uses the local UDFs above to execute a 'map reduce' 12 | -- operation and return the overall result. 13 | function sum_test_bin(stream) 14 | return stream : map(get_test_bin) : reduce(add) 15 | end 16 | 17 | -- A UDF that returns the sum of the argument and the bin value of 'test-bin'. 18 | local function add_test_bin(a, rec) 19 | return a + rec['i'] 20 | end 21 | 22 | -- An aggregation UDF that uses local UDFs above to execute an aggregation and 23 | -- return the overall result. 24 | function sum_test_bin_2(stream) 25 | return stream : aggregate(0, add_test_bin) : reduce(add) 26 | end 27 | 28 | -- A UDF that returns true if the bin value of 'test-bin' is even, false if not. 29 | local function even_test_bin(rec) 30 | return rec['i'] % 2 == 0 31 | end 32 | 33 | -- An aggregation UDF that uses local UDFs above to execute an aggregation after 34 | -- applying a filter, and return the overall result. 35 | function sum_test_bin_even(stream) 36 | return stream : filter(even_test_bin) : aggregate(0, add_test_bin) : reduce(add) 37 | end 38 | 39 | 40 | -- A UDF that parses the string in 'numbers-bin'. Each numeric token found is 41 | -- inserted (as a key) in supplied map m with initial value 1. If the key 42 | -- already exists the value is incremented. The resulting map m is returned. 43 | local function parse_numbers(m, rec) 44 | local s = rec['i'] 45 | for n in string.gmatch(s, "%d+") do 46 | m[n] = (m[n] or 0) + 1 47 | end 48 | return m 49 | end 50 | 51 | -- A UDF that merges two maps, such that the resulting map's keys are the union 52 | -- of the original maps' keys, and each resulting map value is the sum of the 53 | -- original maps' values at that key if both had the key, or the original map's 54 | -- value at that key if only one map had the key. 55 | local function map_merge(m1, m2) 56 | return map.merge(m1, m2, add) 57 | end 58 | 59 | -- An aggregation UDF that uses local UDFs above to execute an aggregation of 60 | -- map objects (not to be confused with the 'map' in 'map reduce') and return 61 | -- the overall result. 62 | function count_numbers(stream) 63 | return stream : aggregate(map(), parse_numbers) : reduce(map_merge) 64 | end 65 | -------------------------------------------------------------------------------- /examples/lua/sample.lua: -------------------------------------------------------------------------------- 1 | function greet() 2 | return "Hello World!" 3 | end 4 | 5 | function greet_name(rec, name) 6 | return "Hello " .. tostring(name) .. "!" 7 | end 8 | -------------------------------------------------------------------------------- /examples/lua/scan.lua: -------------------------------------------------------------------------------- 1 | function increment(rec, bin, amount) 2 | bin = bin or 'i'; 3 | amount = amount or 1; 4 | trace("Incrementing bin '%s' by %i", bin, amount); 5 | rec[bin] = rec[bin] + amount; 6 | aerospike:update(rec); 7 | end 8 | -------------------------------------------------------------------------------- /examples/mrtAbort.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // ***************************************************************************** 3 | // Copyright 2013-2024 Aerospike, Inc. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License") 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // ***************************************************************************** 17 | // 18 | const Aerospike = require('aerospike') 19 | const shared = require('./shared') 20 | 21 | shared.runner() 22 | 23 | async function mrtAbort (client, argv) { 24 | // sconst record1 = { abc: 123 } 25 | const record2 = { def: 456 } 26 | 27 | const mrt = new Aerospike.Transaction() 28 | 29 | const policy = { 30 | txn: mrt 31 | } 32 | const keyList = [] 33 | for (let i = 0; i < argv.keys.length; i++) { 34 | keyList.push(new Aerospike.Key(argv.namespace, argv.set, argv.keys[i])) 35 | } 36 | 37 | for (let i = 0; i < keyList.length; i++) { 38 | await client.put(keyList[i], record2, policy) 39 | await client.get(keyList[i], policy) 40 | } 41 | 42 | console.log(keyList) 43 | 44 | console.log('aborting multi-record transaction with %d operations.', keyList.length * 2) 45 | await client.abort(mrt) 46 | console.info('multi-record transaction has been aborted.') 47 | } 48 | 49 | exports.command = 'mrtAbort ' 50 | exports.describe = 'Abort a multi-record transaction' 51 | exports.handler = shared.run(mrtAbort) 52 | exports.builder = { 53 | keys: { 54 | desc: 'Provide keys for the records in the multi-record transaction', 55 | type: 'array', 56 | group: 'Command:' 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /examples/mrtCommit.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // ***************************************************************************** 3 | // Copyright 2013-2024 Aerospike, Inc. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License") 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // ***************************************************************************** 17 | // 18 | const Aerospike = require('aerospike') 19 | const shared = require('./shared') 20 | 21 | shared.runner() 22 | 23 | async function mrtCommit (client, argv) { 24 | // const record1 = { abc: 123 } 25 | const record2 = { def: 456 } 26 | 27 | const mrt = new Aerospike.Transaction() 28 | 29 | const policy = { 30 | txn: mrt 31 | } 32 | const keyList = [] 33 | for (let i = 0; i < argv.keys.length; i++) { 34 | keyList.push(new Aerospike.Key(argv.namespace, argv.set, argv.keys[i])) 35 | } 36 | for (let i = 0; i < argv.keys.length; i++) { 37 | await client.put(keyList[i], record2, policy) 38 | await client.get(keyList[i], policy) 39 | } 40 | 41 | console.log(keyList) 42 | 43 | console.log('committing multi-record transaction with %d operations.', keyList.length * 2) 44 | await client.commit(mrt) 45 | console.info('multi-record transaction has been committed.') 46 | } 47 | 48 | exports.command = 'mrtCommit ' 49 | exports.describe = 'Commit a multi-record transaction' 50 | exports.handler = shared.run(mrtCommit) 51 | exports.builder = { 52 | keys: { 53 | desc: 'Provide keys for the records in the multi-record transaction', 54 | type: 'array', 55 | group: 'Command:' 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /examples/operate.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // ***************************************************************************** 3 | // Copyright 2013-2024 Aerospike, Inc. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License") 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // ***************************************************************************** 17 | // 18 | const Aerospike = require('aerospike') 19 | const shared = require('./shared') 20 | const op = Aerospike.operations 21 | const lists = Aerospike.lists 22 | 23 | shared.runner() 24 | 25 | async function operate (client, argv) { 26 | const key = new Aerospike.Key(argv.namespace, argv.set, argv.key) 27 | const i = shared.random.int(1, 10) 28 | const ops = [ 29 | lists.append('values', i), 30 | op.read('values'), 31 | op.incr('sum', i), 32 | op.read('sum') 33 | ] 34 | const results = await client.operate(key, ops) 35 | console.info(results) 36 | } 37 | 38 | exports.command = 'operate ' 39 | exports.describe = 'Perform multiple operations on a single record' 40 | exports.handler = shared.run(operate) 41 | -------------------------------------------------------------------------------- /examples/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "aerospike-client-examples", 3 | "description": "Aerospike Client Library Examples", 4 | "license": "Apache-2.0", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/aerospike/aerospike-client-nodejs" 8 | }, 9 | "engines": { 10 | "node": ">=8" 11 | }, 12 | "main": "run.js", 13 | "dependencies": { 14 | "aerospike": "file:..", 15 | "yargs": "^16.2.0" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/put_test.js: -------------------------------------------------------------------------------- 1 | const Aerospike = require('aerospike') 2 | 3 | const config = { 4 | hosts: '172.17.0.3:3000', 5 | log: { 6 | level: Aerospike.log.DEBUG, 7 | file: process.stdout.fd 8 | } 9 | } 10 | const key = new Aerospike.Key('test', 'demo', 'demo') 11 | 12 | // process.on('uncaughtException', (err, origin) => { 13 | // fs.writeSync( 14 | // process.stderr.fd, 15 | // `Caught exception: ${err}\n` + 16 | // `Exception origin: ${origin}` 17 | // ); 18 | // }); 19 | 20 | console.log('Connect') 21 | Aerospike.connect(config) 22 | .then(client => { 23 | const bins = { 24 | i: 123, 25 | s: 'hello', 26 | b: Buffer.from('world'), 27 | d: new Aerospike.Double(3.1415), 28 | g: new Aerospike.GeoJSON({ type: 'Point', coordinates: [103.913, 1.308] }), 29 | l: [1, 'a', { x: 'y' }], 30 | m: { foo: 4, bar: 7 } 31 | } 32 | const meta = { ttl: 0 } 33 | const policy = new Aerospike.WritePolicy({ 34 | exists: Aerospike.policy.exists.CREATE_OR_REPLACE, 35 | timeout: 20000 36 | }) 37 | 38 | console.log('Put') 39 | return client.put(key, bins, meta, policy) 40 | .then(() => { 41 | const ops = [ 42 | Aerospike.operations.incr('i', 1), 43 | Aerospike.operations.read('i'), 44 | Aerospike.lists.append('l', 'z'), 45 | Aerospike.maps.removeByKey('m', 'bar') 46 | ] 47 | 48 | console.log('Operate') 49 | return client.operate(key, ops) 50 | }) 51 | .then(result => { 52 | console.log(result.bins) // => { c: 4, i: 124, m: null } 53 | 54 | return client.get(key) 55 | }) 56 | .then(record => { 57 | console.log(record.bins) // => { i: 124, 58 | // s: 'hello', 59 | // b: , 60 | // d: 3.1415, 61 | // g: '{"type":"Point","coordinates":[103.913,1.308]}', 62 | // l: [ 1, 'a', { x: 'y' }, 'z' ], 63 | // m: { foo: 4 } } 64 | }) 65 | .then(() => client.close()) 66 | .catch(error => { 67 | console.log('Error') 68 | client.close() 69 | return Promise.reject(error) 70 | }) 71 | }) 72 | .catch(error => console.log(error)) 73 | -------------------------------------------------------------------------------- /examples/remove.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // ***************************************************************************** 3 | // Copyright 2013-2024 Aerospike, Inc. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License") 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // ***************************************************************************** 17 | 18 | const Aerospike = require('aerospike') 19 | const shared = require('./shared') 20 | 21 | shared.runner() 22 | 23 | async function remove (client, argv) { 24 | const key = new Aerospike.Key(argv.namespace, argv.set, argv.key) 25 | await client.remove(key) 26 | console.info('Removed record:', key) 27 | } 28 | 29 | exports.command = 'remove ' 30 | exports.describe = 'Remove a record from the database' 31 | exports.handler = shared.run(remove) 32 | -------------------------------------------------------------------------------- /examples/shared/cli.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2018-2023 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | const util = require('util') 18 | 19 | function str2num (value) { 20 | return isNaN(value) ? value : +value 21 | } 22 | 23 | // @param { String[] } binStrs - list of "=" pairs 24 | exports.parseBins = function (binStrs) { 25 | return binStrs.reduce((bins, current) => { 26 | const [name, value] = current.toString().split('=') 27 | bins[name] = str2num(value) 28 | return bins 29 | }, {}) 30 | } 31 | 32 | exports.printRecord = function (record) { 33 | const key = record.key.key || record.key.digest.toString('hex') 34 | console.info('%s: %s', key, util.inspect(record.bins)) 35 | } 36 | -------------------------------------------------------------------------------- /examples/shared/client.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2018-2023 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | const Aerospike = require('aerospike') 18 | const path = require('path') 19 | 20 | const UDF_USERDIR = path.normalize(path.join(__dirname, '..', 'lua')) 21 | 22 | module.exports = function (argv) { 23 | const config = defaultConfig(argv) 24 | Aerospike.setDefaultLogging(config.log) 25 | const client = Aerospike.client(config) 26 | client.captureStackTraces = argv.debugStacktraces 27 | return client 28 | } 29 | 30 | function defaultConfig (argv) { 31 | const defaultPolicy = { 32 | timeout: argv.totalTimeout, 33 | totalTimeout: argv.totalTimeout 34 | } 35 | return { 36 | hosts: argv.hosts, 37 | port: argv.port, 38 | policies: { 39 | apply: defaultPolicy, 40 | batch: defaultPolicy, 41 | info: defaultPolicy, 42 | operate: defaultPolicy, 43 | query: defaultPolicy, 44 | read: defaultPolicy, 45 | remove: defaultPolicy, 46 | scan: defaultPolicy, 47 | write: defaultPolicy 48 | }, 49 | modlua: { 50 | userPath: UDF_USERDIR 51 | }, 52 | log: { 53 | level: Aerospike.log.WARN + argv.verbose 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /examples/shared/index.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2018-2023 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | const path = require('path') 18 | 19 | exports.cli = require('./cli') 20 | exports.client = require('./client') 21 | exports.random = require('./random') 22 | exports.run = require('./run') 23 | exports.streams = require('./streams') 24 | 25 | // Check whether example has been executed directly or via the runner 26 | // (./run.js); if directly, invoke the runner instead and pass the command 27 | // line arguments. 28 | let started = false 29 | exports.runner = function () { 30 | if (started || require.main !== module.parent) { 31 | return 32 | } 33 | started = true 34 | 35 | const example = process.argv[1] 36 | const runner = path.join(example, '../run.js') 37 | const cmd = path.basename(example, '.js') 38 | 39 | process.argv.splice(1, 1, runner, cmd) 40 | delete require.cache[require.resolve(example)] 41 | 42 | require(runner) 43 | } 44 | -------------------------------------------------------------------------------- /examples/shared/random.js: -------------------------------------------------------------------------------- 1 | const crypto = require('crypto') 2 | 3 | exports.identifier = function () { 4 | return crypto.randomBytes(10).toString('hex') 5 | } 6 | 7 | exports.int = function (min, max) { 8 | min = Math.ceil(min) 9 | max = Math.floor(max) + 1 // range inclusive maximum 10 | return min + Math.floor(Math.random() * (max - min)) 11 | } 12 | 13 | exports.float = function (min, max) { 14 | return min + Math.random() * (max - min) 15 | } 16 | -------------------------------------------------------------------------------- /examples/shared/run.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2018-2023 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | const shared = require('./') 18 | 19 | module.exports = function (handler) { 20 | return async function (argv) { 21 | const client = shared.client(argv) 22 | try { 23 | await client.connect() 24 | await handler(client, argv) 25 | } catch (error) { 26 | console.error(error) 27 | } 28 | client.close() 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/shared/streams.js: -------------------------------------------------------------------------------- 1 | exports.consume = function (stream) { 2 | return new Promise(function (resolve, reject) { 3 | stream.on('error', reject) 4 | stream.on('end', resolve) 5 | }) 6 | } 7 | -------------------------------------------------------------------------------- /examples/typescript.ts: -------------------------------------------------------------------------------- 1 | import * as Aerospike from 'aerospike'; 2 | 3 | (async function () { 4 | let client = null; 5 | try { 6 | client = await Aerospike.connect(); 7 | const key = new Aerospike.Key('test', 'test', 'abcd'); 8 | const bins = { 9 | name: 'Norma', 10 | age: 31 11 | }; 12 | 13 | await client.put(key, bins); 14 | const record = await client.get(key); 15 | console.info('Record:', record); 16 | await client.remove(key); 17 | } catch (error) { 18 | console.error('Error:', error); 19 | process.exit(1); 20 | } finally { 21 | if (client) client.close(); 22 | } 23 | })(); 24 | -------------------------------------------------------------------------------- /examples/udf.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // ***************************************************************************** 3 | // Copyright 2013-2024 Aerospike, Inc. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License") 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // ***************************************************************************** 17 | // 18 | const shared = require('./shared') 19 | const path = require('path') 20 | 21 | shared.runner() 22 | 23 | async function udfRegister (client, argv) { 24 | const module = argv.module 25 | const job = await client.udfRegister(module) 26 | await job.waitUntilDone() 27 | console.info('UDF module registered successfully') 28 | } 29 | 30 | async function udfRemove (client, argv) { 31 | const module = path.basename(argv.module) 32 | const job = await client.udfRemove(module) 33 | await job.waitUntilDone() 34 | console.info('UDF module removed successfully') 35 | } 36 | 37 | exports.command = 'udf ' 38 | exports.describe = 'Manage User-Defined Functions (UDF)' 39 | exports.builder = yargs => { 40 | return yargs 41 | .command({ 42 | command: 'register ', 43 | desc: 'Register a new UDF module with the cluster', 44 | handler: shared.run(udfRegister) 45 | }) 46 | .command({ 47 | command: 'remove ', 48 | desc: 'Remove a UDF module from the cluster', 49 | handler: shared.run(udfRemove) 50 | }) 51 | } 52 | -------------------------------------------------------------------------------- /incompatible.md: -------------------------------------------------------------------------------- 1 | # Backward Incompatible API Changes 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | ## [5.12.1] 6 | ### Client no longer supports Node.js version 21 7 | 8 | ## [5.9.0] 9 | 10 | ### Client no longer supports Red Hat Enterprise Linux 7 11 | ### Client no longer supports Amazon Linux 2 12 | ### Client no longer supports Oracle Linux 7 13 | ### Client no longer supports CentOS 7 14 | ### Client no longer supports Debian 10 15 | ### Client no longer supports macOS 11 16 | 17 | ## [5.8.0] 18 | 19 | ### Client no longer supports Node.js version 19 20 | ### Client no longer supports Node.js version 16 21 | 22 | ## [5.5.0] 23 | 24 | ### Client no longer supports Node.js version 14 25 | 26 | ## [5.4.0] 27 | 28 | ### Client no longer supports Ubuntu 18.04 29 | ### Client no longer supports Debian 10 on ARM64 architecture 30 | 31 | ## [5.2.0] 32 | 33 | ### Client does not support Node.js LTS version 14 on macOS using ARM architecture 34 | 35 | ## [5.0.0] 36 | 37 | ### Predicate Expression Filter Replaced by New Filter Expressions 38 | * Usage 39 | * New Filter Expressions 40 | ``` 41 | const query = client.query(helper.namespace, helper.set) 42 | const queryPolicy = { filterExpression: exp.eq(exp.binInt('a'), exp.int(9))} 43 | const stream = query.foreach(queryPolicy) 44 | ``` 45 | * Deprecated PredicateExpression Filter 46 | ``` 47 | const query = client.query(helper.namespace, helper.set) 48 | const pexp = Aerospike.predexp 49 | query.where([pexp.IntVar('a'), pexp.IntValue(9),pexp.stringEqual()]) 50 | const stream = query.foreach() 51 | ``` 52 | 53 | ## [4.0.0] 54 | 55 | ### totalTimeout Replaced by timeout Info Policy Option 56 | * Usage 57 | * New "timeout" InfoPolicy 58 | 59 | const subject = new Aerospike.InfoPolicy({ 60 | timeout: 1000, 61 | sendAsIs: true, 62 | checkBounds: false 63 | }) 64 | 65 | * Deprecated "totalTimeout" InfoPolicy 66 | 67 | const subject = new Aerospike.InfoPolicy({ 68 | totalTimeout: 1000, 69 | sendAsIs: true, 70 | checkBounds: false 71 | }) 72 | -------------------------------------------------------------------------------- /jsdoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "source": { 3 | "include": [ 4 | "lib", 5 | "lib/policies", 6 | "lib/commands" 7 | ] 8 | }, 9 | "plugins": ["plugins/markdown"], 10 | "templates": { 11 | "cleverLinks": true, 12 | "monospaceLinks": false, 13 | "outputSourceFiles": true, 14 | "systemName": "Aerospike", 15 | "footer": "
High performance NoSQL database delivering speed at scale - Aerospike.com
", 16 | "copyright": "© 2013-2022 Aerospike, Inc.", 17 | "navType": "vertical", 18 | "theme": "simplex", 19 | "linenums": true, 20 | "collapseSymbols": false, 21 | "inverseNav": true, 22 | "analytics": { 23 | "ua": "UA-50452230-2", 24 | "domain": "aerospike.com" 25 | } 26 | }, 27 | "docdash": { 28 | "sectionOrder": [ 29 | "Modules", 30 | "Classes", 31 | "Events", 32 | "Tutorials", 33 | "Global" 34 | ],"meta": { 35 | "title": "Aerospike Node.js Client API Documentation", 36 | "description": "Explore the comprehensive documentation for the Aerospike Node.js Client API, covering usage, configuration, and examples. Learn how to integrate Aerospike with your Node.js applications efficiently.", 37 | "keyword": "Aerospike, Node.js, Client API, Documentation, Usage, Configuration, Examples, Integration" 38 | } 39 | }, 40 | "opts": { 41 | "destination": "./build/apidocs", 42 | "template": "./node_modules/docdash", 43 | "readme": "./docs/overview.md", 44 | "tutorials" : "./docs/tutorials", 45 | "recurse": true, 46 | "verbose": true 47 | } 48 | 49 | 50 | } -------------------------------------------------------------------------------- /lib/abort_status.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the 'License') 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an 'AS IS' BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | const as = require('bindings')('aerospike.node') 20 | const abortStatus = as.abortStatus 21 | 22 | module.exports = { 23 | OK: abortStatus.OK, 24 | ALREADY_ABORTED: abortStatus.ALREADY_ABORTED, 25 | ROLL_BACK_ABANDONED: abortStatus.ROLL_BACK_ABANDONED, 26 | CLOSE_ABANDONED: abortStatus.CLOSE_ABANDONED 27 | } 28 | -------------------------------------------------------------------------------- /lib/admin.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2023 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the 'License') 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an 'AS IS' BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | /** 20 | * @module aerospike/admin 21 | * 22 | * @description The admin module contains classes associated with RBAC (Role Based Access Control) security 23 | * methods defined in {@link Client} 24 | * 25 | */ 26 | 27 | /** 28 | * The {@link User} class holds role and database usage information for individual users. 29 | * 30 | * @summary User. 31 | */ 32 | exports.User = require('./user') 33 | 34 | /** 35 | * The {@link Privilege} class contains a {@link aerospike/privilegeCode | privilegeCode} as well as 36 | * an namespace and set. 37 | * 38 | * @summary Privilege 39 | */ 40 | exports.Privilege = require('./privilege') 41 | 42 | /** 43 | * The {@link Role} class holds quota, whitelist, and privilege information for an specified role. 44 | * 45 | * @summary Role 46 | */ 47 | exports.Role = require('./role') 48 | -------------------------------------------------------------------------------- /lib/batch_type.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2022-2023 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the 'License') 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an 'AS IS' BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | const as = require('bindings')('aerospike.node') 20 | const batchType = as.batchTypes 21 | 22 | /** 23 | * @module aerospike/batchType 24 | * 25 | * @description Identifies batch record type with designated enumerated type 26 | */ 27 | 28 | // ======================================================================== 29 | // Constants 30 | // ======================================================================== 31 | module.exports = { 32 | /** 33 | * Indicates that a {@link Record} instance is used in a batch for read operations. 34 | * @const {number} 35 | */ 36 | BATCH_READ: batchType.BATCH_READ, 37 | 38 | /** 39 | * Indicates that a {@link Record} instance is used in a batch for write operations. 40 | * @const {number} 41 | */ 42 | BATCH_WRITE: batchType.BATCH_WRITE, 43 | 44 | /** 45 | * Indicates that a {@link Record} instance is used in a batch for applying record. 46 | * @const {number} 47 | */ 48 | BATCH_APPLY: batchType.BATCH_APPLY, 49 | 50 | /** 51 | * Indicates that a {@link Record} instance is used in a batch for removal operations. 52 | * @const {number} 53 | */ 54 | BATCH_REMOVE: batchType.BATCH_REMOVE 55 | 56 | } 57 | -------------------------------------------------------------------------------- /lib/bigint.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | // keep eslint happy 20 | const BigInt = global.BigInt || (() => {}) 21 | const MIN_INT64 = BigInt(-2) ** BigInt(63) 22 | const MAX_INT64 = BigInt(2) ** BigInt(63) - BigInt(1) 23 | 24 | exports.BigInt = global.BigInt || 25 | (() => { throw new Error('BigInt not supported on this version of Node.js') }) 26 | exports.bigIntSupported = !!global.BigInt 27 | 28 | exports.isInt64 = function (value) { 29 | return MIN_INT64 <= BigInt(value) && BigInt(value) <= MAX_INT64 30 | } 31 | -------------------------------------------------------------------------------- /lib/bin.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2023 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | /** 20 | * @class Bin 21 | * @classdesc Aerospike Bin 22 | * 23 | * In the Aerospike database, each record (similar to a row in a relational database) stores 24 | * data using one or more bins (like columns in a relational database). The major difference 25 | * between bins and RDBMS columns is that you don't need to define a schema. Each record can 26 | * have multiple bins. Bins accept the data types listed {@link https://docs.aerospike.com/apidocs/nodejs/#toc4__anchor|here}. 27 | * 28 | * For information about these data types and how bins support them, see {@link https://docs.aerospike.com/server/guide/data-types/scalar-data-types|this}. 29 | * 30 | * Although the bin for a given record or object must be typed, bins in different rows do not 31 | * have to be the same type. There are some internal performance optimizations for single-bin namespaces. 32 | * 33 | * @summary Construct a new Aerospike Bin instance. 34 | * 35 | */ 36 | class Bin { 37 | /** @private */ 38 | constructor (name, value, mapOrder) { 39 | /** 40 | * Bin name. 41 | * 42 | * @member {String} Bin#name 43 | */ 44 | this.name = name 45 | 46 | /** 47 | * Bin value. 48 | * 49 | * @member {Any} Bin#value 50 | */ 51 | if (mapOrder === 1) { 52 | this.value = new Map(Object.entries(value)) 53 | } else { 54 | this.value = value 55 | } 56 | } 57 | } 58 | 59 | module.exports = Bin 60 | -------------------------------------------------------------------------------- /lib/commands/batch_command.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | const Command = require('./command') 20 | const Record = require('../record') 21 | 22 | class BatchResult { 23 | constructor (status, record, inDoubt) { 24 | this.status = status 25 | this.record = record 26 | this.inDoubt = inDoubt 27 | } 28 | } 29 | 30 | module.exports = asCommand => class BatchCommand extends Command(asCommand) { 31 | convertResult (results) { 32 | if (!results) return [] 33 | 34 | return results.map(result => { 35 | const record = new Record(result.key, result.bins, result.meta) 36 | return new BatchResult(result.status, record, result.inDoubt) 37 | }) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /lib/commands/connect_command.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | const Command = require('./command') 20 | 21 | module.exports = asCommand => class ConnectCommand extends Command(asCommand) { 22 | constructor (client, callback) { 23 | super(client, [], callback) 24 | this.ensureConnected = false 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lib/commands/exists_command.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | const status = require('../status') 20 | const Command = require('./command') 21 | const Record = require('../record') 22 | 23 | module.exports = asCommand => class ExistsCommand extends Command(asCommand) { 24 | constructor (client, key, args, callback) { 25 | if (key) { 26 | args = [key].concat(args) 27 | } 28 | super(client, args, callback) 29 | this.key = key 30 | } 31 | 32 | convertResponse (error, bins, metadata) { 33 | error = this.convertError(error) 34 | if (error && error.code === status.ERR_RECORD_NOT_FOUND) { 35 | if (this.key) { 36 | return [null, this.convertResult({ ttl: null, gen: null })] 37 | } 38 | return [null, false] 39 | } else if (error) { 40 | return [error, null] 41 | } else { 42 | if (this.key) { 43 | return [null, this.convertResult(metadata)] 44 | } 45 | return [null, true] 46 | } 47 | } 48 | 49 | convertResult (metadata) { 50 | return new Record(this.key, null, metadata) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /lib/commands/query_background_command.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | const Job = require('../job') 20 | const Command = require('./command') 21 | 22 | function notEmpty (value) { 23 | return Array.isArray(value) && value.length > 0 24 | } 25 | 26 | function hasFilter (queryOrScan) { 27 | return notEmpty(queryOrScan.filters) 28 | } 29 | 30 | function moduleName (queryOrScan) { 31 | return hasFilter(queryOrScan) ? 'query' : 'scan' 32 | } 33 | 34 | // This command is used for both background queries and background scans, including 35 | // scans/queries that execute record UDFs, or one or more (write-only) operations. 36 | module.exports = asCommand => class QueryBackgroundBaseCommand extends Command(asCommand) { 37 | constructor (client, ns, set, queryObj, policy, queryID, callback) { 38 | queryID = queryID || Job.safeRandomJobID() 39 | const args = [ns, set, queryObj, policy, queryID] 40 | super(client, args, callback) 41 | 42 | this.client = client 43 | this.queryID = queryID 44 | this.queryObj = queryObj 45 | } 46 | 47 | convertResult () { 48 | return new Job(this.client, this.queryID, moduleName(this.queryObj)) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /lib/commands/read_record_command.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | const Command = require('./command') 20 | const Record = require('../record') 21 | 22 | module.exports = asCommand => class ReadRecordCommand extends Command(asCommand) { 23 | constructor (client, key, args, callback) { 24 | args = [key].concat(args) 25 | super(client, args, callback) 26 | this.key = key 27 | } 28 | 29 | convertResult (bins, metadata) { 30 | return new Record(this.key, bins, metadata) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lib/commands/stream_command.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | const Command = require('./command') 20 | const Key = require('../key') 21 | const Record = require('../record') 22 | 23 | module.exports = asCommand => class StreamCommand extends Command(asCommand) { 24 | constructor (stream, args) { 25 | super(stream.client, args) 26 | this.stream = stream 27 | } 28 | 29 | callback (error, record) { 30 | if (error) { 31 | this.stream.emit('error', error) 32 | } else if ('state' in record) { 33 | this.stream.emit('end', record.state) 34 | } else { 35 | this.stream.emit('data', record) 36 | } 37 | return !this.stream.aborted 38 | } 39 | 40 | convertResult (bins, meta, asKey) { 41 | if (!bins) return { state: meta } 42 | const key = Key.fromASKey(asKey) 43 | return new Record(key, bins, meta) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/commands/write_record_command.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | const Command = require('./command') 20 | 21 | module.exports = asCommand => class WriteRecordCommand extends Command(asCommand) { 22 | constructor (client, key, args, callback) { 23 | args = [key].concat(args) 24 | super(client, args, callback) 25 | this.key = key 26 | } 27 | 28 | convertResult () { 29 | return this.key 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lib/commit_status.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the 'License') 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an 'AS IS' BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | const as = require('bindings')('aerospike.node') 20 | const commitStatus = as.commitStatus 21 | 22 | module.exports = { 23 | OK: commitStatus.OK, 24 | ALREADY_COMMITTED: commitStatus.ALREADY_COMMITTED, 25 | VERIFY_FAILED: commitStatus.VERIFY_FAILED, 26 | MARK_ROLL_FORWARD_ABANDONED: commitStatus.MARK_ROLL_FORWARD_ABANDONED, 27 | ROLL_FORWARD_ABANDONED: commitStatus.ROLL_FORWARD_ABANDONED, 28 | CLOSE_ABANDONED: commitStatus.CLOSE_ABANDONED 29 | } 30 | -------------------------------------------------------------------------------- /lib/features.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2019-2023 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | exports.CDT_MAP = 'cdt-map' 18 | exports.CDT_LIST = 'cdt-list' 19 | exports.BLOB_BITS = 'blob-bits' 20 | -------------------------------------------------------------------------------- /lib/metrics_listeners.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2025 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | class MetricsListeners { 20 | constructor (options) { 21 | this.enableListener = options.enableListener 22 | this.snapshotListener = options.snapshotListener 23 | this.nodeCloseListener = options.nodeCloseListener 24 | this.disableListener = options.disableListener 25 | } 26 | } 27 | 28 | module.exports = MetricsListeners 29 | -------------------------------------------------------------------------------- /lib/policies/admin_policy.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2023 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | /** 20 | * A policy affecting the behavior of adminstraation operations. 21 | * 22 | * Please note that `AdminPolicy` does not derive from {@link BasePolicy}. 23 | * 24 | * @since v3.0.0 25 | */ 26 | class AdminPolicy { 27 | /** 28 | * Initializes a new AdminPolicy from the provided policy values. 29 | * 30 | * @param {Object} [props] - Policy values 31 | */ 32 | constructor (props) { 33 | props = props || {} 34 | 35 | /** 36 | * Maximum time in milliseconds to wait for the operation to complete. 37 | * 38 | * @type number 39 | */ 40 | this.timeout = props.timeout 41 | } 42 | } 43 | 44 | module.exports = AdminPolicy 45 | -------------------------------------------------------------------------------- /lib/policies/bitwise_policy.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2019-2023 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | /** 20 | * A policy affecting the behavior of {@link module:aerospike/bitwise|bitwise} operations. 21 | * 22 | * @since v3.13.0 23 | */ 24 | class BitwisePolicy { 25 | /** 26 | * Initializes a new BitwisePolicy from the provided policy values. 27 | * 28 | * @param {Object} [props] - Policy values 29 | */ 30 | constructor (props) { 31 | props = props || {} 32 | 33 | /** 34 | * Specifies the behavior when writing byte values. 35 | * 36 | * @type number 37 | * @default Aerospike.bitwise.writeFlags.DEFAULT 38 | * @see {@link module:aerospike/bitwise.writeFlags} for supported policy values. 39 | */ 40 | this.writeFlags = props.writeFlags 41 | } 42 | } 43 | 44 | module.exports = BitwisePolicy 45 | -------------------------------------------------------------------------------- /lib/policies/hll_policy.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2020-2023 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | /** 20 | * A policy affecting the behavior of {@link module:aerospike/hll|HLL} operations. 21 | * 22 | * @since v3.16.0 23 | */ 24 | class HLLPolicy { 25 | /** 26 | * Initializes a new HLLPolicy from the provided policy values. 27 | * 28 | * @param {Object} [props] - Policy values 29 | */ 30 | constructor (props) { 31 | props = props || {} 32 | 33 | /** 34 | * Specifies the behavior when writing byte values. 35 | * 36 | * @type number 37 | * @default Aerospike.hll.writeFlags.DEFAULT 38 | * @see {@link module:aerospike/hll.writeFlags} for supported policy values. 39 | */ 40 | this.writeFlags = props.writeFlags 41 | } 42 | } 43 | 44 | module.exports = HLLPolicy 45 | -------------------------------------------------------------------------------- /lib/policies/info_policy.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | /** 20 | * A policy affecting the behavior of info operations. 21 | * 22 | * Please note that `InfoPolicy` does not derive from {@link BasePolicy} and that 23 | * info commands do not support automatic retry. 24 | * 25 | * @since v3.0.0 26 | */ 27 | class InfoPolicy { 28 | /** 29 | * Initializes a new InfoPolicy from the provided policy values. 30 | * 31 | * @param {Object} [props] - Policy values 32 | */ 33 | constructor (props) { 34 | props = props || {} 35 | 36 | /** 37 | * Maximum time in milliseconds to wait for the operation to complete. 38 | * 39 | * @type number 40 | */ 41 | this.timeout = props.timeout 42 | 43 | /** 44 | * Send request without any further processing. 45 | * 46 | * @type boolean 47 | */ 48 | this.sendAsIs = props.sendAsIs 49 | 50 | /** 51 | * Ensure the request is within allowable size limits. 52 | * 53 | * @type boolean 54 | */ 55 | this.checkBounds = props.checkBounds 56 | } 57 | } 58 | 59 | module.exports = InfoPolicy 60 | -------------------------------------------------------------------------------- /lib/policies/list_policy.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2018-2023 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | /** 20 | * A policy affecting the behavior of list operations. 21 | * 22 | * @since v3.3.0 23 | */ 24 | class ListPolicy { 25 | /** 26 | * Initializes a new ListPolicy from the provided policy values. 27 | * 28 | * @param {Object} [props] - Policy values 29 | */ 30 | constructor (props) { 31 | props = props || {} 32 | 33 | /** 34 | * Sort order for the list. 35 | * 36 | * @type number 37 | * @default Aerospike.lists.order.UNORDERED 38 | * @see {@link module:aerospike/lists.order} for supported policy values. 39 | */ 40 | this.order = props.order 41 | 42 | /** 43 | * Specifies the behavior when replacing or inserting list items. 44 | * 45 | * @type number 46 | * @default Aerospike.lists.writeFlags.DEFAULT 47 | * @see {@link module:aerospike/lists.writeFlags} for supported policy values. 48 | */ 49 | this.writeFlags = props.writeFlags 50 | } 51 | } 52 | 53 | module.exports = ListPolicy 54 | -------------------------------------------------------------------------------- /lib/policies/map_policy.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | /** 20 | * A policy affecting the behavior of map operations. 21 | * 22 | * @since v3.0.0 23 | */ 24 | class MapPolicy { 25 | /** 26 | * Initializes a new MapPolicy from the provided policy values. 27 | * 28 | * @param {Object} [props] - Policy values 29 | */ 30 | constructor (props) { 31 | props = props || {} 32 | 33 | /** 34 | * Sort order for the map. 35 | * 36 | * @type number 37 | * @default Aerospike.maps.order.UNORDERED 38 | * @see {@link module:aerospike/maps.order} for supported policy values. 39 | */ 40 | this.order = props.order 41 | 42 | /** 43 | * Specifies the behavior when replacing or inserting map items. 44 | * 45 | * Map write mode should only be used for server versions prior to v4.3. 46 | * For server versions v4.3 or later, the use of {@link 47 | * MapPolicy#writeFlags|writeFlags} is recommended. 48 | * 49 | * @type number 50 | * @default Aerospike.maps.writeMode.UPDATE 51 | * @see {@link module:aerospike/maps.writeMode} for supported policy values. 52 | * @deprecated since v3.5 53 | */ 54 | this.writeMode = props.writeMode 55 | 56 | /** 57 | * Specifies the behavior when replacing or inserting map items. 58 | * 59 | * Map write flags require server version v4.3 or later. For earier server 60 | * versions, set the {@link MapPolicy#writeMode|writeMode} instead. 61 | * 62 | * @type number 63 | * @default Aerospike.maps.writeFlags.DEFAULT 64 | * @see {@link module:aerospike/maps.writeFlags} for supported policy values. 65 | * @since v3.5 66 | */ 67 | this.writeFlags = props.writeFlags 68 | } 69 | } 70 | 71 | module.exports = MapPolicy 72 | -------------------------------------------------------------------------------- /lib/policies/metrics_policy.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2025 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | class MetricsPolicy { 20 | constructor (props) { 21 | props = props || {} 22 | 23 | this.metricsListeners = props.metricsListeners 24 | 25 | this.reportDir = props.reportDir 26 | 27 | this.reportSizeLimit = props.reportSizeLimit 28 | 29 | this.interval = props.interval 30 | 31 | this.latencyColumns = props.latencyColumns 32 | 33 | this.latencyShift = props.latecnyShift 34 | } 35 | } 36 | 37 | module.exports = MetricsPolicy 38 | -------------------------------------------------------------------------------- /lib/privilege.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2023 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | /** 20 | * @class Privilege 21 | * 22 | * @summary User privileges including a permission code, namespace, and set. 23 | * 24 | */ 25 | function Privilege (code, options) { 26 | options = options || {} 27 | this.code = code 28 | this.namespace = options.namespace || '' 29 | this.set = options.set || '' 30 | } 31 | 32 | module.exports = Privilege 33 | -------------------------------------------------------------------------------- /lib/role.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2023 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | /** 20 | * @class Role 21 | * 22 | * @summary Contains user roles and other user related information 23 | * 24 | */ 25 | function Role (options) { 26 | this.name = options.name 27 | this.readQuota = options.readQuota 28 | this.writeQuota = options.writeQuota 29 | this.whitelist = options.whitelist 30 | this.privileges = options.privileges 31 | } 32 | 33 | module.exports = Role 34 | -------------------------------------------------------------------------------- /lib/txn_capacity.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the 'License') 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an 'AS IS' BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | const as = require('bindings')('aerospike.node') 20 | const capacity = as.txnCapacity 21 | 22 | module.exports = { 23 | READ_DEFAULT: capacity.READ_DEFAULT, 24 | WRITE_DEFAULT: capacity.WRITE_DEFAULT 25 | } 26 | -------------------------------------------------------------------------------- /lib/txn_state.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the 'License') 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an 'AS IS' BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | const as = require('bindings')('aerospike.node') 20 | const state = as.txnState 21 | 22 | module.exports = { 23 | OK: state.OPEN, 24 | VERIFIED: state.VERIFIED, 25 | COMMITTED: state.COMMITTED, 26 | ABORTED: state.ABORTED 27 | } 28 | -------------------------------------------------------------------------------- /lib/user.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2023 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | /** 20 | * @class User 21 | * 22 | * @summary Contains user roles and other user related information 23 | * 24 | */ 25 | function User (options) { 26 | this.connsInUse = options.connsInUse 27 | this.name = options.name 28 | this.readInfo = options.readInfo 29 | this.writeInfo = options.writeInfo 30 | this.roles = options.roles 31 | } 32 | 33 | module.exports = User 34 | -------------------------------------------------------------------------------- /lib/utils.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | const HOST_RE = /^(\[[0-9a-f:]+]|(?:\d{1,3}\.){3}\d{1,3}|[a-z][a-z0-9\-.]+)(?::([a-z][a-z0-9\-.]+))?(?::(\d+))?$/i 20 | 21 | function parseHostString (hostString) { 22 | const parts = hostString.match(HOST_RE) 23 | if (!parts) { 24 | throw new Error('Invalid host address: ' + hostString) 25 | } 26 | 27 | const host = {} 28 | 29 | let addr = parts[1] 30 | if (addr.startsWith('[') && addr.endsWith(']')) { 31 | addr = addr.substr(1, addr.length - 2) 32 | } 33 | host.addr = addr 34 | 35 | const tlsName = parts[2] 36 | if (tlsName) { 37 | host.tlsname = tlsName 38 | } 39 | 40 | const port = parts[3] 41 | host.port = port ? Number.parseInt(port, 10) : 3000 42 | 43 | return host 44 | } 45 | 46 | function print (err, result) { 47 | if (err) { 48 | console.error('Error:', err.message) 49 | } else { 50 | console.info('Result:', result) 51 | } 52 | } 53 | 54 | module.exports = { 55 | parseHostString, 56 | print 57 | } 58 | -------------------------------------------------------------------------------- /scripts/build-c-client.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################################################################ 3 | # Copyright 2013-2023 Aerospike, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | ################################################################################ 17 | 18 | 19 | ################################################################################ 20 | # 21 | # This script is used to build dependancy c-client sub-module. 22 | # 23 | ################################################################################ 24 | 25 | CWD=$(pwd) 26 | SCRIPT_DIR=$(dirname $0) 27 | BASE_DIR=$(cd "${SCRIPT_DIR}/.."; pwd) 28 | 29 | . ${SCRIPT_DIR}/build-commands.sh 30 | 31 | download_libuv 32 | rebuild_libuv 33 | 34 | rebuild_c_client 35 | 36 | perform_check 37 | 38 | cd ${CWD} 39 | -------------------------------------------------------------------------------- /scripts/build-package.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################################################################ 3 | # Copyright 2013-2023 Aerospike, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | ################################################################################ 17 | 18 | 19 | ################################################################################ 20 | # 21 | # This script is used to build various node versions packages. 22 | # 23 | ################################################################################ 24 | 25 | CWD=$(pwd) 26 | SCRIPT_DIR=$(dirname $0) 27 | BASE_DIR=$(cd "${SCRIPT_DIR}/.."; pwd) 28 | AS_HOST="bob-cluster-a" 29 | AS_USER="generic_client" 30 | AS_PWD="generic_client" 31 | AS_PORT="3000" 32 | AS_NAMESPACE="ssd-store" 33 | 34 | . ${SCRIPT_DIR}/build-commands.sh 35 | 36 | build_nodejs_client() { 37 | rm -rf ./node_modules 38 | rm -f package-lock.json 39 | nvm install $1 40 | nvm use $1 41 | npm install --unsafe-perm --build-from-source 42 | # node ${CWD}/node_modules/.bin/mocha --exit --U ${AS_USER} --P ${AS_PWD} --h ${AS_HOST} --port ${AS_PORT} --namespace ${AS_NAMESPACE} 43 | } 44 | 45 | configure_nvm 46 | 47 | download_libuv 48 | rebuild_libuv 49 | 50 | rebuild_c_client 51 | 52 | perform_check 53 | 54 | rm -rf ${AEROSPIKE_NODEJS_RELEASE_HOME}/node-*-${OS_FLAVOR}-* 55 | 56 | 57 | build_nodejs_client v18 58 | build_nodejs_client v20 59 | build_nodejs_client v22 60 | build_nodejs_client v23 61 | 62 | nvm use v22 63 | 64 | cd ${CWD} 65 | -------------------------------------------------------------------------------- /scripts/build-package.sh-cclient-output.log: -------------------------------------------------------------------------------- 1 | project/modules.mk:16: *************************************************************** 2 | project/modules.mk:17: * 3 | project/modules.mk:18: * COMMON is '/home/dpelini/Documents/MRT/aerospike-client-nodejs/aerospike-client-c/modules/common' 4 | project/modules.mk:19: * COMMON doesn't contain 'Makefile'. 5 | project/modules.mk:20: * COMMON should be set to a valid path. 6 | project/modules.mk:21: * 7 | project/modules.mk:22: *************************************************************** 8 | project/modules.mk:23: *** . Stop. 9 | -------------------------------------------------------------------------------- /scripts/build_apidocs: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | BUILD_DIR=./build 3 | APIDOCS_DIR=$BUILD_DIR/apidocs 4 | APIDOCS_ARCHIVE=aerospike-client-nodejs-apidocs.zip 5 | 6 | rm -rf $APIDOCS_DIR $BUILD_DIR/$APIDOCS_ARCHIVE 7 | npm run apidocs 8 | (cd $APIDOCS_DIR; zip -r ../$APIDOCS_ARCHIVE .) 9 | -------------------------------------------------------------------------------- /scripts/change-install-command.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | 3 | // Path to package.json 4 | const packageJsonPath = './package.json' 5 | 6 | // Read and parse package.json 7 | const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) 8 | 9 | // Update the install script 10 | packageJson.scripts.install = 'npm-run-all removeExtraBinaries build' 11 | 12 | // Write the updated package.json back 13 | fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8') 14 | 15 | console.log('Updated the install script in package.json successfully.') 16 | -------------------------------------------------------------------------------- /scripts/validate-c-client.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################################################################ 3 | # Copyright 2013-2023 Aerospike, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | ################################################################################ 17 | 18 | 19 | ################################################################################ 20 | # 21 | # This script is used by bindings.gyp, to detect if libaerospike.a is 22 | # installed and exporting the proper environment variables. 23 | # 24 | ################################################################################ 25 | 26 | CWD=$(pwd) 27 | SCRIPT_DIR=$(dirname $0) 28 | BASE_DIR=$(cd "${SCRIPT_DIR}/.."; pwd) 29 | 30 | . ${SCRIPT_DIR}/build-commands.sh 31 | 32 | perform_check 33 | -------------------------------------------------------------------------------- /scripts/wait-for-node.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | ################################################################################ 3 | # Copyright 2013-2023 Aerospike, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | ################################################################################ 17 | 18 | LOG=$1 19 | if [ ! -f $LOG ]; then 20 | echo "A log file does not exist at $LOG" 21 | exit 1 22 | fi 23 | 24 | i=0 25 | while [ $i -le 12 ] 26 | do 27 | sleep 1 28 | grep -i "there will be cake" $LOG 29 | if [ $? == 0 ]; then 30 | exit 0 31 | else 32 | i=$(($i + 1)) 33 | echo -n "." 34 | fi 35 | done 36 | echo "the cake is a lie!" 37 | tail -n 1000 $LOG 38 | exit 2 -------------------------------------------------------------------------------- /scripts/watch_tests: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Watch for changes to tests and re-run then. 3 | if [ ! -x "$(command -v fswatch)" ]; then 4 | echo "Please install fswatch to use this script. On Mac OS, you can install it via Homebrew." 5 | exit -1 6 | fi 7 | echo "Watching test dir for changes..." 8 | fswatch test/*.js | xargs -n 1 mocha 9 | -------------------------------------------------------------------------------- /src/include/config.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2013-2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include "log.h" 21 | 22 | extern "C" { 23 | #include 24 | } 25 | 26 | int config_from_jsobject(as_config *config, v8::Local obj, 27 | const LogInfo *log); 28 | -------------------------------------------------------------------------------- /src/include/enums.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2013-2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #define TTL_NAMESPACE_DEFAULT 0 22 | #define TTL_NEVER_EXPIRE -1 23 | #define TTL_DONT_UPDATE -2 24 | #define TTL_CLIENT_DEFAULT -3 25 | 26 | v8::Local auth_mode_enum_values(); 27 | v8::Local bitwise_enum_values(); 28 | v8::Local generation_policy_values(); 29 | v8::Local hll_enum_values(); 30 | v8::Local indexDataType(); 31 | v8::Local indexType(); 32 | v8::Local jobStatus(); 33 | v8::Local key_policy_values(); 34 | v8::Local languages(); 35 | v8::Local list_enum_values(); 36 | v8::Local log_enum_values(); 37 | v8::Local map_enum_values(); 38 | v8::Local policy(); 39 | v8::Local predicates(); 40 | v8::Local retry_policy_values(); 41 | v8::Local status(); 42 | v8::Local ttl_enum_values(); 43 | v8::Local batchTypes(); 44 | v8::Local queryDuration(); 45 | v8::Local privilegeCode(); 46 | v8::Local expReadFlags(); 47 | v8::Local expWriteFlags(); 48 | v8::Local abortStatus(); 49 | v8::Local commitStatus(); 50 | v8::Local txnState(); 51 | v8::Local txnCapacity(); 52 | -------------------------------------------------------------------------------- /src/include/events.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright 2013-2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #include "log.h" 22 | 23 | extern "C" { 24 | #include 25 | } 26 | 27 | void events_callback_init(as_config *config, v8::Local callback, 28 | LogInfo *log); 29 | void events_callback_close(as_config *config); 30 | -------------------------------------------------------------------------------- /src/include/expressions.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2021-2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | extern "C" { 22 | #include 23 | } 24 | 25 | v8::Local exp_opcode_values(); 26 | int compile_expression(v8::Local exp_ary, as_exp **filter_exp, 27 | const LogInfo *log); 28 | -------------------------------------------------------------------------------- /src/include/query.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2013-2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #pragma once 18 | 19 | extern "C" { 20 | #include 21 | } 22 | 23 | #include 24 | 25 | #include "log.h" 26 | 27 | 28 | struct query_udata { 29 | as_query* query; 30 | AsyncCommand* cmd; 31 | uint32_t count; 32 | uint32_t max_records; 33 | }; 34 | 35 | void setup_query(as_query *query, v8::Local ns, 36 | v8::Local set, v8::Local maybe_options, 37 | as_cdt_ctx* context, bool* with_context, LogInfo *log); 38 | void setup_options(as_query *query, v8::Local options, as_cdt_ctx* context, bool* with_context, LogInfo *log); 39 | void setup_query_pages(as_query ** query, v8::Local ns, v8::Local set, 40 | v8::Localmaybe_options, uint8_t* bytes, uint32_t bytes_size, 41 | as_cdt_ctx* context, bool* with_context, LogInfo *log); 42 | void free_query(as_query *query, as_policy_query *policy); 43 | -------------------------------------------------------------------------------- /src/include/scan.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2013-2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | extern "C" { 18 | #include 19 | } 20 | 21 | #include 22 | 23 | #include "log.h" 24 | 25 | struct scan_udata { 26 | as_scan* scan; 27 | AsyncCommand * cmd; 28 | uint32_t count; 29 | uint32_t max_records; 30 | }; 31 | 32 | void setup_scan(as_scan *scan, v8::Local ns, 33 | v8::Local set, v8::Local maybe_options, 34 | LogInfo *log); 35 | 36 | void setup_options(as_scan *scan, v8::Local options, LogInfo *log); 37 | 38 | void setup_scan_pages(as_scan **scan, v8::Local ns, v8::Local set, 39 | v8::Local maybe_options, uint8_t* bytes, uint32_t bytes_size, LogInfo *log); -------------------------------------------------------------------------------- /src/include/transaction.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2013-2024 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | #pragma once 17 | 18 | #include 19 | #include 20 | 21 | extern "C" { 22 | #include 23 | } 24 | 25 | #include "log.h" 26 | #include "command.h" 27 | 28 | class Transaction : public Nan::ObjectWrap { 29 | 30 | /*************************************************************************** 31 | * PUBLIC 32 | **************************************************************************/ 33 | public: 34 | static void Init(); 35 | static v8::Local NewInstance(v8::Local capacity_obj); 36 | 37 | Nan::Persistent persistent; 38 | as_txn *txn; 39 | 40 | Transaction(); 41 | ~Transaction(); 42 | 43 | /*************************************************************************** 44 | * PRIVATE 45 | **************************************************************************/ 46 | private: 47 | 48 | static inline Nan::Persistent &constructor() 49 | { 50 | static Nan::Persistent my_constructor; 51 | return my_constructor; 52 | } 53 | 54 | static NAN_METHOD(New); 55 | 56 | static NAN_METHOD(GetId); 57 | static NAN_METHOD(GetInDoubt); 58 | static NAN_METHOD(GetTimeout); 59 | static NAN_METHOD(GetState); 60 | 61 | static NAN_METHOD(SetTimeout); 62 | 63 | static NAN_METHOD(Close); 64 | 65 | }; 66 | -------------------------------------------------------------------------------- /src/main/commands/disable_metrics.cc: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2013-2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #include "client.h" 18 | #include "command.h" 19 | 20 | 21 | 22 | extern "C" { 23 | #include 24 | } 25 | 26 | using namespace v8; 27 | 28 | NAN_METHOD(AerospikeClient::DisableMetrics) 29 | { 30 | TYPE_CHECK_REQ(info[0], IsFunction, "Callback must be a function"); 31 | 32 | AerospikeClient *client = 33 | Nan::ObjectWrap::Unwrap(info.This()); 34 | AsyncCommand *cmd = 35 | new AsyncCommand("DisableMetrics", client, info[0].As()); 36 | 37 | if (aerospike_disable_metrics(client->as, &cmd->err) != AEROSPIKE_OK) { 38 | cmd->ErrorCallback(&cmd->err); 39 | goto Cleanup; 40 | } 41 | else{ 42 | Local argv[] = {Nan::Null(), Nan::Null()}; 43 | cmd->Callback(2, argv); 44 | } 45 | 46 | Cleanup: 47 | delete cmd; 48 | } -------------------------------------------------------------------------------- /src/main/commands/transaction_abort.cc: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2013-2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #include "client.h" 18 | #include "command.h" 19 | #include "conversions.h" 20 | #include "log.h" 21 | #include "async.h" 22 | #include "transaction.h" 23 | 24 | using namespace v8; 25 | 26 | NAN_METHOD(AerospikeClient::TransactionAbort) 27 | { 28 | // TYPE_CHECK_REQ(info[0], is_transaction_value, "Transaction must be an object"); 29 | TYPE_CHECK_REQ(info[1], IsFunction, "Callback must be a function"); 30 | 31 | AerospikeClient *client = 32 | Nan::ObjectWrap::Unwrap(info.This()); 33 | AsyncCommand *cmd = new AsyncCommand("Abort", client, info[1].As()); 34 | LogInfo *log = client->log; 35 | 36 | Transaction *transaction; 37 | as_status status; 38 | 39 | 40 | if (is_transaction_value(info[0])) { 41 | transaction = Nan::ObjectWrap::Unwrap(info[0].As()); 42 | } 43 | else { 44 | CmdErrorCallback(cmd, AEROSPIKE_ERR_PARAM, "Transaction object invalid"); 45 | goto Cleanup; 46 | } 47 | 48 | status = aerospike_abort_async(client->as, &cmd->err, transaction->txn, async_abort_listener, cmd, NULL); 49 | as_v8_debug(log, "Sending transaction abort command"); 50 | 51 | if (status == AEROSPIKE_OK) { 52 | cmd = NULL; // async callback responsible for deleting the command 53 | } 54 | else { 55 | cmd->ErrorCallback(); 56 | } 57 | 58 | Cleanup: 59 | delete cmd; 60 | } -------------------------------------------------------------------------------- /src/main/commands/transaction_commit.cc: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2013-2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #include "client.h" 18 | #include "command.h" 19 | #include "conversions.h" 20 | #include "log.h" 21 | #include "async.h" 22 | #include "transaction.h" 23 | 24 | using namespace v8; 25 | 26 | 27 | NAN_METHOD(AerospikeClient::TransactionCommit) 28 | { 29 | //TYPE_CHECK_REQ(info[0], is_transaction_value, "Transaction must be an object"); 30 | TYPE_CHECK_REQ(info[1], IsFunction, "Callback must be a function"); 31 | 32 | AerospikeClient *client = 33 | Nan::ObjectWrap::Unwrap(info.This()); 34 | AsyncCommand *cmd = new AsyncCommand("Commit", client, info[1].As()); 35 | LogInfo *log = client->log; 36 | 37 | Transaction *transaction; 38 | as_status status; 39 | 40 | if (is_transaction_value(info[0])) { 41 | transaction = Nan::ObjectWrap::Unwrap(info[0].As()); 42 | } 43 | else { 44 | CmdErrorCallback(cmd, AEROSPIKE_ERR_PARAM, "Transaction object invalid"); 45 | goto Cleanup; 46 | } 47 | 48 | status = aerospike_commit_async(client->as, &cmd->err, transaction->txn , async_commit_listener, cmd, NULL); 49 | as_v8_debug(log, "Sending transaction commit command"); 50 | 51 | if (status == AEROSPIKE_OK) { 52 | cmd = NULL; // async callback responsible for deleting the command 53 | } 54 | else { 55 | cmd->ErrorCallback(); 56 | } 57 | 58 | Cleanup: 59 | delete cmd; 60 | 61 | } -------------------------------------------------------------------------------- /src/main/enums/abort_status.cc: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2024 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #include 18 | #include 19 | 20 | extern "C" { 21 | #include 22 | } 23 | 24 | using namespace v8; 25 | 26 | #define set(__obj, __name, __value) \ 27 | Nan::Set(__obj, Nan::New(__name).ToLocalChecked(), Nan::New(__value)) 28 | 29 | Local abortStatus() 30 | { 31 | Nan::EscapableHandleScope scope; 32 | Local obj = Nan::New(); 33 | set(obj, "OK", AS_ABORT_OK); 34 | set(obj, "ALREADY_ABORTED", AS_ABORT_ALREADY_ABORTED); 35 | set(obj, "ROLL_BACK_ABANDONED", AS_ABORT_ROLL_BACK_ABANDONED); 36 | set(obj, "CLOSE_ABANDONED", AS_ABORT_CLOSE_ABANDONED); 37 | return scope.Escape(obj); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/enums/batch_type.cc: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2022-2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #include 18 | #include 19 | 20 | extern "C" { 21 | #include 22 | } 23 | 24 | using namespace v8; 25 | 26 | #define set(__obj, __name, __value) \ 27 | Nan::Set(__obj, Nan::New(__name).ToLocalChecked(), Nan::New(__value)) 28 | 29 | Local batchTypes() 30 | { 31 | Nan::EscapableHandleScope scope; 32 | Local obj = Nan::New(); 33 | set(obj, "BATCH_READ", AS_BATCH_READ); 34 | set(obj, "BATCH_WRITE", AS_BATCH_WRITE); 35 | set(obj, "BATCH_APPLY", AS_BATCH_APPLY); 36 | set(obj, "BATCH_REMOVE", AS_BATCH_REMOVE); 37 | return scope.Escape(obj); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/enums/commit_status.cc: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2024 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #include 18 | #include 19 | 20 | extern "C" { 21 | #include 22 | } 23 | 24 | using namespace v8; 25 | 26 | #define set(__obj, __name, __value) \ 27 | Nan::Set(__obj, Nan::New(__name).ToLocalChecked(), Nan::New(__value)) 28 | 29 | Local commitStatus() 30 | { 31 | Nan::EscapableHandleScope scope; 32 | Local obj = Nan::New(); 33 | set(obj, "OK", AS_COMMIT_OK); 34 | set(obj, "ALREADY_COMMITTED", AS_COMMIT_ALREADY_COMMITTED); 35 | set(obj, "VERIFY_FAILED", AS_COMMIT_VERIFY_FAILED); 36 | set(obj, "MARK_ROLL_FORWARD_ABANDONED", AS_COMMIT_MARK_ROLL_FORWARD_ABANDONED); 37 | set(obj, "ROLL_FORWARD_ABANDONED", AS_COMMIT_ROLL_FORWARD_ABANDONED); 38 | set(obj, "CLOSE_ABANDONED", AS_COMMIT_CLOSE_ABANDONED); 39 | return scope.Escape(obj); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/enums/config_enum.cc: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2013-2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #include 18 | #include 19 | 20 | extern "C" { 21 | #include 22 | #include 23 | } 24 | 25 | using namespace v8; 26 | 27 | #define set(__obj, __name, __value) \ 28 | Nan::Set(__obj, Nan::New(__name).ToLocalChecked(), Nan::New(__value)) 29 | 30 | Local log_enum_values() 31 | { 32 | Nan::EscapableHandleScope scope; 33 | Local obj = Nan::New(); 34 | set(obj, "OFF", -1); 35 | set(obj, "ERROR", AS_LOG_LEVEL_ERROR); 36 | set(obj, "WARN", AS_LOG_LEVEL_WARN); 37 | set(obj, "INFO", AS_LOG_LEVEL_INFO); 38 | set(obj, "DEBUG", AS_LOG_LEVEL_DEBUG); 39 | set(obj, "TRACE", AS_LOG_LEVEL_TRACE); 40 | set(obj, "DETAIL", 41 | AS_LOG_LEVEL_TRACE); // renamed in v3.4 - keep old name for backwards compatibility 42 | return scope.Escape(obj); 43 | } 44 | 45 | Local auth_mode_enum_values() 46 | { 47 | Nan::EscapableHandleScope scope; 48 | Local obj = Nan::New(); 49 | set(obj, "INTERNAL", AS_AUTH_INTERNAL); 50 | set(obj, "EXTERNAL", AS_AUTH_EXTERNAL); 51 | set(obj, "EXTERNAL_INSECURE", AS_AUTH_EXTERNAL_INSECURE); 52 | set(obj, "AUTH_PKI", AS_AUTH_PKI); 53 | return scope.Escape(obj); 54 | } 55 | -------------------------------------------------------------------------------- /src/main/enums/exp_read_flags.cc: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #include 18 | #include 19 | 20 | extern "C" { 21 | #include 22 | } 23 | 24 | using namespace v8; 25 | 26 | #define set(__obj, __name, __value) \ 27 | Nan::Set(__obj, Nan::New(__name).ToLocalChecked(), Nan::New(__value)) 28 | 29 | Local expReadFlags() 30 | { 31 | Nan::EscapableHandleScope scope; 32 | Local obj = Nan::New(); 33 | set(obj, "DEFAULT", AS_EXP_READ_DEFAULT); 34 | set(obj, "EVAL_NO_FAIL", AS_EXP_READ_EVAL_NO_FAIL); 35 | 36 | return scope.Escape(obj); 37 | } -------------------------------------------------------------------------------- /src/main/enums/exp_write_flags.cc: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #include 18 | #include 19 | 20 | extern "C" { 21 | #include 22 | } 23 | 24 | using namespace v8; 25 | 26 | #define set(__obj, __name, __value) \ 27 | Nan::Set(__obj, Nan::New(__name).ToLocalChecked(), Nan::New(__value)) 28 | 29 | Local expWriteFlags() 30 | { 31 | Nan::EscapableHandleScope scope; 32 | Local obj = Nan::New(); 33 | set(obj, "DEFAULT", AS_EXP_WRITE_DEFAULT); 34 | set(obj, "CREATE_ONLY", AS_EXP_WRITE_CREATE_ONLY); 35 | set(obj, "UPDATE_ONLY", AS_EXP_WRITE_UPDATE_ONLY); 36 | set(obj, "ALLOW_DELETE", AS_EXP_WRITE_ALLOW_DELETE); 37 | set(obj, "POLICY_NO_FAIL", AS_EXP_WRITE_POLICY_NO_FAIL); 38 | set(obj, "EVAL_NO_FAIL", AS_EXP_WRITE_EVAL_NO_FAIL); 39 | 40 | return scope.Escape(obj); 41 | } -------------------------------------------------------------------------------- /src/main/enums/hll_enum.cc: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2020-2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #include 18 | #include 19 | 20 | extern "C" { 21 | #include 22 | } 23 | 24 | using namespace v8; 25 | 26 | #define set(__obj, __name, __value) \ 27 | Nan::Set(__obj, Nan::New(__name).ToLocalChecked(), Nan::New(__value)) 28 | 29 | Local hll_enum_values() 30 | { 31 | Nan::EscapableHandleScope scope; 32 | 33 | // as_hll_write_flags 34 | Local write_flags = Nan::New(); 35 | set(write_flags, "DEFAULT", AS_HLL_WRITE_DEFAULT); 36 | set(write_flags, "CREATE_ONLY", AS_HLL_WRITE_CREATE_ONLY); 37 | set(write_flags, "UPDATE_ONLY", AS_HLL_WRITE_UPDATE_ONLY); 38 | set(write_flags, "NO_FAIL", AS_HLL_WRITE_NO_FAIL); 39 | set(write_flags, "ALLOW_FOLD", AS_HLL_WRITE_ALLOW_FOLD); 40 | 41 | // as_hll_op 42 | Local opcodes = Nan::New(); 43 | set(opcodes, "INIT", AS_HLL_OP_INIT); 44 | set(opcodes, "ADD", AS_HLL_OP_ADD); 45 | set(opcodes, "UNION", AS_HLL_OP_UNION); 46 | set(opcodes, "REFRESH_COUNT", AS_HLL_OP_REFRESH_COUNT); 47 | set(opcodes, "FOLD", AS_HLL_OP_FOLD); 48 | set(opcodes, "COUNT", AS_HLL_OP_COUNT); 49 | set(opcodes, "GET_UNION", AS_HLL_OP_GET_UNION); 50 | set(opcodes, "UNION_COUNT", AS_HLL_OP_UNION_COUNT); 51 | set(opcodes, "INTERSECT_COUNT", AS_HLL_OP_INTERSECT_COUNT); 52 | set(opcodes, "SIMILARITY", AS_HLL_OP_SIMILARITY); 53 | set(opcodes, "DESCRIBE", AS_HLL_OP_DESCRIBE); 54 | set(opcodes, "MAY_CONTAIN", AS_HLL_OP_MAY_CONTAIN); 55 | 56 | Local enums = Nan::New(); 57 | Nan::Set(enums, Nan::New("writeFlags").ToLocalChecked(), write_flags); 58 | Nan::Set(enums, Nan::New("opcodes").ToLocalChecked(), opcodes); 59 | return scope.Escape(enums); 60 | } 61 | -------------------------------------------------------------------------------- /src/main/enums/index.cc: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2013-2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #include 18 | #include 19 | 20 | extern "C" { 21 | #include 22 | } 23 | 24 | using namespace v8; 25 | 26 | #define set(__obj, __name, __value) \ 27 | Nan::Set(__obj, Nan::New(__name).ToLocalChecked(), Nan::New(__value)) 28 | 29 | Local indexDataType() 30 | { 31 | Nan::EscapableHandleScope scope; 32 | Local obj = Nan::New(); 33 | set(obj, "STRING", AS_INDEX_STRING); 34 | set(obj, "NUMERIC", AS_INDEX_NUMERIC); 35 | set(obj, "GEO2DSPHERE", AS_INDEX_GEO2DSPHERE); 36 | set(obj, "BLOB", AS_INDEX_BLOB); 37 | return scope.Escape(obj); 38 | } 39 | 40 | Local indexType() 41 | { 42 | Nan::EscapableHandleScope scope; 43 | Local obj = Nan::New(); 44 | set(obj, "DEFAULT", AS_INDEX_TYPE_DEFAULT); 45 | set(obj, "LIST", AS_INDEX_TYPE_LIST); 46 | set(obj, "MAPKEYS", AS_INDEX_TYPE_MAPKEYS); 47 | set(obj, "MAPVALUES", AS_INDEX_TYPE_MAPVALUES); 48 | return scope.Escape(obj); 49 | } 50 | -------------------------------------------------------------------------------- /src/main/enums/job_status.cc: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2013-2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #include 18 | #include 19 | 20 | extern "C" { 21 | #include 22 | } 23 | 24 | using namespace v8; 25 | 26 | #define set(__obj, __name, __value) \ 27 | Nan::Set(__obj, Nan::New(__name).ToLocalChecked(), Nan::New(__value)) 28 | 29 | Local jobStatus() 30 | { 31 | Nan::EscapableHandleScope scope; 32 | Local obj = Nan::New(); 33 | set(obj, "UNDEF", AS_JOB_STATUS_UNDEF); 34 | set(obj, "INPROGRESS", AS_JOB_STATUS_INPROGRESS); 35 | set(obj, "COMPLETED", AS_JOB_STATUS_COMPLETED); 36 | return scope.Escape(obj); 37 | } 38 | -------------------------------------------------------------------------------- /src/main/enums/predicates.cc: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2013-2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #include 18 | #include 19 | 20 | extern "C" { 21 | #include 22 | } 23 | 24 | using namespace v8; 25 | 26 | #define set(__obj, __name, __value) \ 27 | Nan::Set(__obj, Nan::New(__name).ToLocalChecked(), Nan::New(__value)) 28 | 29 | Local predicates() 30 | { 31 | Nan::EscapableHandleScope scope; 32 | Local obj = Nan::New(); 33 | set(obj, "EQUAL", AS_PREDICATE_EQUAL); 34 | set(obj, "RANGE", AS_PREDICATE_RANGE); 35 | return scope.Escape(obj); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/enums/privilege_code.cc: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #include 18 | #include 19 | 20 | extern "C" { 21 | #include 22 | } 23 | 24 | using namespace v8; 25 | 26 | #define set(__obj, __name, __value) \ 27 | Nan::Set(__obj, Nan::New(__name).ToLocalChecked(), Nan::New(__value)) 28 | 29 | Local privilegeCode() 30 | { 31 | Nan::EscapableHandleScope scope; 32 | Local obj = Nan::New(); 33 | set(obj, "USER_ADMIN", AS_PRIVILEGE_USER_ADMIN); 34 | set(obj, "SYS_ADMIN", AS_PRIVILEGE_SYS_ADMIN); 35 | set(obj, "DATA_ADMIN", AS_PRIVILEGE_DATA_ADMIN); 36 | set(obj, "UDF_ADMIN", AS_PRIVILEGE_UDF_ADMIN); 37 | set(obj, "SINDEX_ADMIN", AS_PRIVILEGE_SINDEX_ADMIN); 38 | set(obj, "READ", AS_PRIVILEGE_READ); 39 | set(obj, "READ_WRITE", AS_PRIVILEGE_READ_WRITE); 40 | set(obj, "READ_WRITE_UDF", AS_PRIVILEGE_READ_WRITE_UDF); 41 | set(obj, "WRITE", AS_PRIVILEGE_WRITE); 42 | set(obj, "TRUNCATE", AS_PRIVILEGE_TRUNCATE); 43 | return scope.Escape(obj); 44 | } -------------------------------------------------------------------------------- /src/main/enums/query_duration.cc: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #include 18 | #include 19 | 20 | extern "C" { 21 | #include 22 | } 23 | 24 | using namespace v8; 25 | 26 | #define set(__obj, __name, __value) \ 27 | Nan::Set(__obj, Nan::New(__name).ToLocalChecked(), Nan::New(__value)) 28 | 29 | Local queryDuration() 30 | { 31 | Nan::EscapableHandleScope scope; 32 | Local obj = Nan::New(); 33 | set(obj, "LONG", AS_QUERY_DURATION_LONG); 34 | set(obj, "SHORT", AS_QUERY_DURATION_SHORT); 35 | set(obj, "LONG_RELAX_AP", AS_QUERY_DURATION_LONG_RELAX_AP); 36 | 37 | return scope.Escape(obj); 38 | } -------------------------------------------------------------------------------- /src/main/enums/scanPriority.cc: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2013-2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #include 18 | #include 19 | 20 | extern "C" { 21 | #include 22 | } 23 | 24 | using namespace v8; 25 | 26 | #define set(__obj, __name, __value) \ 27 | Nan::Set(__obj, Nan::New(__name).ToLocalChecked(), Nan::New(__value)) 28 | -------------------------------------------------------------------------------- /src/main/enums/ttl.cc: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2013-2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #include 18 | #include 19 | 20 | #include "enums.h" 21 | 22 | using namespace v8; 23 | 24 | #define set(__obj, __name, __value) \ 25 | Nan::Set(__obj, Nan::New(__name).ToLocalChecked(), Nan::New(__value)) 26 | 27 | Local ttl_enum_values() 28 | { 29 | Nan::EscapableHandleScope scope; 30 | Local obj = Nan::New(); 31 | set(obj, "NAMESPACE_DEFAULT", TTL_NAMESPACE_DEFAULT); 32 | set(obj, "NEVER_EXPIRE", TTL_NEVER_EXPIRE); 33 | set(obj, "DONT_UPDATE", TTL_DONT_UPDATE); 34 | set(obj, "CLIENT_DEFAULT", TTL_CLIENT_DEFAULT); 35 | return scope.Escape(obj); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/enums/txn_capacity.cc: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2022-2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #include 18 | #include 19 | 20 | extern "C" { 21 | #include 22 | } 23 | 24 | using namespace v8; 25 | 26 | #define set(__obj, __name, __value) \ 27 | Nan::Set(__obj, Nan::New(__name).ToLocalChecked(), Nan::New(__value)) 28 | 29 | Local txnCapacity() 30 | { 31 | Nan::EscapableHandleScope scope; 32 | Local obj = Nan::New(); 33 | set(obj, "READ_DEFAULT", AS_TXN_READ_CAPACITY_DEFAULT); 34 | set(obj, "WRITE_DEFAULT", AS_TXN_WRITE_CAPACITY_DEFAULT); 35 | 36 | return scope.Escape(obj); 37 | } 38 | -------------------------------------------------------------------------------- /src/main/enums/txn_state.cc: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2022-2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #include 18 | #include 19 | 20 | extern "C" { 21 | #include 22 | } 23 | 24 | using namespace v8; 25 | 26 | #define set(__obj, __name, __value) \ 27 | Nan::Set(__obj, Nan::New(__name).ToLocalChecked(), Nan::New(__value)) 28 | 29 | Local txnState() 30 | { 31 | Nan::EscapableHandleScope scope; 32 | Local obj = Nan::New(); 33 | set(obj, "OPEN", AS_TXN_STATE_OPEN); 34 | set(obj, "VERIFIED", AS_TXN_STATE_VERIFIED); 35 | set(obj, "COMMITTED", AS_TXN_STATE_COMMITTED); 36 | set(obj, "ABORTED", AS_TXN_STATE_ABORTED); 37 | return scope.Escape(obj); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/enums/udf_languages.cc: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2013-2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #include 18 | #include 19 | 20 | using namespace v8; 21 | 22 | #define set(__obj, __name, __value) \ 23 | Nan::Set(__obj, Nan::New(__name).ToLocalChecked(), Nan::New(__value)) 24 | 25 | Local languages() 26 | { 27 | Nan::EscapableHandleScope scope; 28 | Local obj = Nan::New(); 29 | set(obj, "LUA", 0); 30 | return scope.Escape(obj); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/operations.cc: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2013-2023 Aerospike, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | 17 | #include 18 | #include 19 | 20 | #include "operations.h" 21 | #include "conversions.h" 22 | #include "log.h" 23 | 24 | using namespace v8; 25 | 26 | int add_operation(as_operations *ops, uint32_t opcode, Local params, 27 | LogInfo *log) 28 | { 29 | switch (opcode & OPS_MASK) { 30 | case SCALAR_OPS_OFFSET: 31 | return add_scalar_op(ops, opcode, params, log); 32 | case LIST_OPS_OFFSET: 33 | return add_list_op(ops, opcode, params, log); 34 | case MAP_OPS_OFFSET: 35 | return add_map_op(ops, opcode, params, log); 36 | case BIT_OPS_OFFSET: 37 | return add_bit_op(ops, opcode, params, log); 38 | case HLL_OPS_OFFSET: 39 | return add_hll_op(ops, opcode, params, log); 40 | case EXPOP_OPS_OFFSET: 41 | return add_exp_op(ops, opcode, params, log); 42 | default: 43 | return AS_NODE_PARAM_ERR; 44 | } 45 | } 46 | 47 | int operations_from_jsarray(as_operations *ops, Local arr, LogInfo *log) 48 | { 49 | uint32_t capacity = arr->Length(); 50 | if (capacity == 0) { 51 | as_v8_error(log, "Operations list is empty"); 52 | return AS_NODE_PARAM_ERR; 53 | } 54 | as_v8_detail(log, "Converting operations list: size=%d", capacity); 55 | 56 | int result = AS_NODE_PARAM_OK; 57 | uint32_t op; 58 | for (uint32_t i = 0; i < capacity; i++) { 59 | Local obj = Nan::Get(arr, i).ToLocalChecked().As(); 60 | result = get_uint32_property(&op, obj, "op", log); 61 | if (result == AS_NODE_PARAM_OK) { 62 | result = add_operation(ops, op, obj, log); 63 | } 64 | if (result != AS_NODE_PARAM_OK) { 65 | as_v8_error(log, "invalid operation [%i] - result: %i", op, result); 66 | break; 67 | } 68 | } 69 | 70 | return result; 71 | } 72 | -------------------------------------------------------------------------------- /test/README.md: -------------------------------------------------------------------------------- 1 | # Testing Aerospike Node.js Client 2 | 3 | ## Installation 4 | 5 | We also recommend installing Aerospike dependencies by running the following 6 | from the module's root directory: 7 | 8 | $ npm update 9 | 10 | This will install all required dependencies. 11 | 12 | ## Usage 13 | 14 | To run the test cases: 15 | 16 | $ npm test 17 | 18 | The tests are written and run using [`mocha`](http://visionmedia.github.io/mocha). 19 | You can choose to use `mocha` directly, but you must first install `mocha`: 20 | 21 | $ npm install -g mocha 22 | 23 | Note: some users may need to run this as sudo. 24 | 25 | Then to run the tests via mocha, you will want to run it from the modules' root 26 | directory: 27 | 28 | $ mocha -R spec 29 | 30 | ## Options 31 | 32 | You can modify the test with various options: 33 | 34 | --help Display this message. 35 | --host, -h Aerospike database address. [default: "127.0.0.1"] 36 | --port, -p Aerospike database port. [default: 3000] 37 | --timeout, -t Timeout in milliseconds. [default: 10] 38 | --log, -l Log level [0-5] [default: 2] 39 | --namespace, -n Namespace for the keys. [default: "test"] 40 | --set, -s Set for the keys. [default: "demo"] 41 | 42 | Options can be set via an environment variable `OPTIONS`: 43 | 44 | $ OPTIONS="--port 3010" npm test 45 | -------------------------------------------------------------------------------- /test/aerospike.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | /* global expect, describe, it */ 20 | 21 | const Aerospike = require('../lib/aerospike') 22 | const helper = require('./test_helper') 23 | 24 | describe('Aerospike', function () { 25 | describe('Aerospike.client() #noserver', function () { 26 | it('instantiates a new client instance', function (done) { 27 | const client = Aerospike.client(helper.config) 28 | expect(client).to.be.instanceof(Aerospike.Client) 29 | done() 30 | }) 31 | }) 32 | 33 | describe('Aerospike.connect()', function () { 34 | it('instantiates a new client instance and connects to the cluster', function (done) { 35 | Aerospike.connect(helper.config, (error, client) => { 36 | if (error) throw error 37 | expect(client).to.be.instanceof(Aerospike.Client) 38 | client.infoAny(error => { 39 | if (error) throw error 40 | client.close(false) 41 | done() 42 | }) 43 | }) 44 | }) 45 | 46 | it('returns a Promise that resolves to a client', function () { 47 | return Aerospike.connect(helper.config) 48 | .then(client => { 49 | expect(client).to.be.instanceof(Aerospike.Client) 50 | return client 51 | }) 52 | .then(client => client.close(false)) 53 | }) 54 | }) 55 | }) 56 | -------------------------------------------------------------------------------- /test/bigint.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | /* eslint-env mocha */ 20 | /* global expect */ 21 | 22 | const helper = require('./test_helper') 23 | const bigint = require('../lib/bigint') 24 | 25 | describe('bigint', function () { 26 | context('BigInt supported - Node.js 10 and later', function () { 27 | helper.skipUnless(this, bigint.bigIntSupported) 28 | 29 | describe('BigInt', function () { 30 | it('is an alias for the built-in BigInt', function () { 31 | expect(bigint.BigInt(42)).to.eq(global.BigInt(42)) 32 | }) 33 | }) 34 | }) 35 | 36 | context('BigInt not supported - Node.js 8 and earlier', function () { 37 | helper.skipUnless(this, !bigint.bigIntSupported) 38 | 39 | describe('BigInt', function () { 40 | it('raises an exception if used', function () { 41 | expect(() => { bigint.BigInt(42) }).to.throw(Error, 'BigInt not supported') 42 | }) 43 | }) 44 | }) 45 | }) 46 | -------------------------------------------------------------------------------- /test/command.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | /* eslint-env mocha */ 20 | /* global expect */ 21 | 22 | require('./test_helper') 23 | const Command = require('../lib/commands/command') 24 | 25 | describe('Command', function () { 26 | context('Extend Command', function () { 27 | class TestCommand extends Command('testCmd') { 28 | foo () { return 'bar' } 29 | } 30 | 31 | it('creates subclasses with informative constructor names', function () { 32 | const cmd = new TestCommand({}) 33 | expect(cmd.constructor.name).to.equal('TestCommand') 34 | }) 35 | 36 | it('keeps a reference to the client instance', function () { 37 | const client = {} 38 | const cmd = new TestCommand(client) 39 | expect(cmd.client).to.equal(client) 40 | }) 41 | }) 42 | }) 43 | -------------------------------------------------------------------------------- /test/double.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | /* global expect, describe, it */ 20 | 21 | const Aerospike = require('../lib/aerospike') 22 | const Double = Aerospike.Double 23 | 24 | require('./test_helper.js') 25 | 26 | describe('Aerospike.Double #noserver', function () { 27 | describe('constructor', function () { 28 | it('returns a new Double value', function () { 29 | const subject = new Double(3.1415) 30 | 31 | expect(subject).to.be.instanceof(Double) 32 | expect(subject.Double).to.equal(3.1415) 33 | }) 34 | 35 | it('throws an error if not passed a number', function () { 36 | const fn = () => new Double('four point nine') 37 | expect(fn).to.throw(TypeError) 38 | }) 39 | 40 | it('throws an error if called without `new`', function () { 41 | const fn = () => Double(3.1415) 42 | expect(fn).to.throw('Invalid use of Double constructor') 43 | }) 44 | }) 45 | 46 | describe('#value()', function () { 47 | const subject = new Double(3.1415) 48 | 49 | it('returns the double value', function () { 50 | expect(subject.value()).to.equal(3.1415) 51 | }) 52 | }) 53 | }) 54 | -------------------------------------------------------------------------------- /test/generators/key.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | const Key = require('../../lib/key') 20 | const valgen = require('./value') 21 | 22 | // 23 | // Returns a generator for bytes keys. 24 | // 25 | function bytes (namespace, set, options) { 26 | const bgen = valgen.bytes(options) 27 | return function () { 28 | return new Key(namespace, set, bgen()) 29 | } 30 | } 31 | 32 | // 33 | // Returns a generator for string keys. 34 | // 35 | function string (namespace, set, options) { 36 | const sgen = valgen.string(options) 37 | return function () { 38 | return new Key(namespace, set, sgen()) 39 | } 40 | } 41 | 42 | // 43 | // Returns a generator for integer keys. 44 | // 45 | function integer (namespace, set, options) { 46 | const igen = valgen.integer(options) 47 | return function () { 48 | return new Key(namespace, set, igen()) 49 | } 50 | } 51 | 52 | function range (keygen, end, start) { 53 | start = start || 0 54 | end = end || start + 1 55 | const a = [] 56 | for (let i = 0; i < end; i++) { 57 | a.push(keygen()) 58 | } 59 | return a 60 | } 61 | 62 | module.exports = { 63 | bytes, 64 | integer, 65 | string, 66 | range 67 | } 68 | -------------------------------------------------------------------------------- /test/generators/metadata.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | // 20 | // Returns a static record. 21 | // 22 | function constant (metadata) { 23 | return function () { 24 | return metadata 25 | } 26 | } 27 | 28 | module.exports = { 29 | constant 30 | } 31 | -------------------------------------------------------------------------------- /test/generators/record.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | // 20 | // Returns a static record. 21 | // 22 | function constant (bins) { 23 | return function () { 24 | return bins 25 | } 26 | } 27 | 28 | // 29 | // Returns a record from bins spec'd using generators record. 30 | // 31 | function record (bins) { 32 | return function () { 33 | const out = {} 34 | for (const bin in bins) { 35 | out[bin] = bins[bin]() 36 | } 37 | return out 38 | } 39 | } 40 | 41 | module.exports = { 42 | constant, 43 | record 44 | } 45 | -------------------------------------------------------------------------------- /test/generators/util.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | function range (end, start) { 20 | start = start || 0 21 | end = end || start + 1 22 | let i, j 23 | const a = Array(end - start + 1) 24 | for (i = 0, j = start; j < end; i++, j++) { 25 | a[i] = j 26 | } 27 | return a 28 | } 29 | 30 | module.exports = { 31 | range 32 | } 33 | -------------------------------------------------------------------------------- /test/remove_bin.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | const { expect } = require('chai') 20 | /* global describe, context, it */ 21 | 22 | const Aerospike = require('../lib/aerospike') 23 | const helper = require('./test_helper') 24 | 25 | const keygen = helper.keygen 26 | 27 | const status = Aerospike.status 28 | const AerospikeError = Aerospike.AerospikeError 29 | 30 | describe('client.put(null bin)', function () { 31 | const client = helper.client 32 | 33 | context('with simple put null value', function () { 34 | it('delete bin using null put', function () { 35 | const key = keygen.string(helper.namespace, helper.set, { prefix: 'test/remove_bin/' })() 36 | 37 | return client.put(key, { str: 'abcde' }) 38 | .then(() => { 39 | client.put(key, { str: null }) 40 | .then(() => { 41 | client.get(key, function (err, bins, meta) { 42 | expect(err).to.be.instanceof(AerospikeError).with.property('code', status.ERR_RECORD_NOT_FOUND) 43 | }) 44 | }) 45 | }) 46 | }) 47 | }) 48 | }) 49 | -------------------------------------------------------------------------------- /test/stats.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2018-2023 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | /* eslint-env mocha */ 20 | /* global expect */ 21 | /* eslint-disable no-unused-expressions */ 22 | 23 | const helper = require('./test_helper') 24 | const client = helper.client 25 | 26 | describe('Client#stats', function () { 27 | before(function (done) { 28 | // Send an async command to each node ensure we have at least 1 async 29 | // connection open. At least 1 sync connection has been opened to send some 30 | // info commands. 31 | client.scan(helper.namespace, 'noSuchSet').foreach().on('end', done) 32 | }) 33 | 34 | it('returns command queue stats', function () { 35 | const stats = client.stats() 36 | expect(stats.commands).to.not.be.empty 37 | expect(stats.commands.inFlight).to.be.at.least(0) 38 | expect(stats.commands.queued).to.be.at.least(0) 39 | }) 40 | 41 | it('returns cluster node stats', function () { 42 | const stats = client.stats() 43 | expect(stats.nodes).to.be.an('array').that.is.not.empty 44 | 45 | const node = stats.nodes.pop() 46 | expect(node.name).to.be.a('string').of.length(15) 47 | for (const connStats of [node.syncConnections, node.asyncConnections]) { 48 | expect(connStats.inPool).to.be.at.least(1) 49 | expect(connStats.inUse).to.be.at.least(0) 50 | expect(connStats.opened).to.be.at.least(1) 51 | expect(connStats.closed).to.be.at.least(0) 52 | } 53 | }) 54 | }) 55 | -------------------------------------------------------------------------------- /test/udf.lua: -------------------------------------------------------------------------------- 1 | function withArguments(rec, value) 2 | return value 3 | end 4 | 5 | function withoutArguments(rec) 6 | return 1 7 | end 8 | 9 | function noop(rec) 10 | end 11 | 12 | 13 | function createRecord(rec, binName, binValue) 14 | rec[binName] = binValue 15 | if (aerospike:exists(rec)) then 16 | status = aerospike:update(rec) 17 | else 18 | status = aerospike:create(rec) 19 | end 20 | return status 21 | end 22 | 23 | function updateRecord(rec, binName, binValue) 24 | rec[binName] = binValue 25 | aerospike:update(rec) 26 | return rec 27 | end 28 | 29 | function count(stream) 30 | local function mapper(rec) 31 | return 1 32 | end 33 | local function reducer(v1, v2) 34 | return v1 + v2 35 | end 36 | return stream : map(mapper) : reduce(reducer) 37 | end 38 | 39 | function countGreaterThan(stream, binName, value) 40 | local function mapper(rec) 41 | if rec[binName] > value then 42 | return 1 43 | else 44 | return 0 45 | end 46 | end 47 | local function reducer(v1, v2) 48 | return v1 + v2 49 | end 50 | return stream : map(mapper) : reduce(reducer) 51 | end 52 | 53 | function even(stream, bin) 54 | local function filt(rec) 55 | return rec.value % 2 == 0 56 | end 57 | local function mapper(rec) 58 | return rec.value 59 | end 60 | return stream : filter(filt) : map(mapper) 61 | end 62 | -------------------------------------------------------------------------------- /test/util/index.js: -------------------------------------------------------------------------------- 1 | const sleep = require('./sleep') 2 | module.exports = exports = { 3 | ...sleep 4 | } 5 | -------------------------------------------------------------------------------- /test/util/run_in_new_process.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | const childProcess = require('child_process') 20 | const tmp = require('tmp') 21 | const fs = require('fs') 22 | 23 | function generateTestSource (fn, data) { 24 | return ` 25 | 'use strict' 26 | const Aerospike = require(process.cwd()) 27 | const fn = ${fn.toString()} 28 | const data = JSON.parse(\`${JSON.stringify(data)}\`) 29 | const report = (result) => new Promise((resolve) => process.send(result, resolve)) 30 | 31 | ;(async () => { 32 | try { 33 | const result = await fn(Aerospike, data) 34 | await report({ result }) 35 | } catch (error) { 36 | await report({ error }) 37 | } 38 | process.exit() 39 | })() 40 | ` 41 | } 42 | 43 | function createTempFile (fn, data) { 44 | const source = generateTestSource(fn, data) 45 | const temp = tmp.fileSync({ postfix: '.js' }) 46 | fs.writeSync(temp.fd, source) 47 | return temp.name 48 | } 49 | 50 | function forkAndRun (fn, env, data) { 51 | const temp = createTempFile(fn, data) 52 | return childProcess.fork(temp, { env }) 53 | } 54 | 55 | module.exports = function runInNewProcess (fn, env, data) { 56 | return new Promise((resolve, reject) => { 57 | const child = forkAndRun(fn, env, data) 58 | child.on('message', message => { 59 | child.disconnect() 60 | if (message.error) { 61 | reject(new Error(message.error)) 62 | } else { 63 | resolve(message.result) 64 | } 65 | }) 66 | child.on('error', error => 67 | console.error('Error for PID %s: %s', child.pid, error.message)) 68 | }) 69 | } 70 | -------------------------------------------------------------------------------- /test/util/sleep.js: -------------------------------------------------------------------------------- 1 | exports.sleep = function sleep (ms) { 2 | return new Promise((resolve) => setTimeout(resolve, ms)) 3 | } 4 | -------------------------------------------------------------------------------- /ts-test/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ts-test", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "directories": { 6 | "test": "tests" 7 | }, 8 | "scripts": { 9 | "test": "echo \"Error: no test specified\" && exit 1" 10 | }, 11 | "author": "", 12 | "license": "ISC", 13 | "description": "", 14 | "dependencies": { 15 | "@types/tmp": "^0.2.6", 16 | "aerospike": "file:..", 17 | "dockerode": "^4.0.4", 18 | "mocha": "^11.1.0", 19 | "typescript": "^5.7.3" 20 | }, 21 | "devDependencies": { 22 | "@types/chai": "^5.0.1", 23 | "@types/jest": "^29.5.14", 24 | "@types/mocha": "^10.0.10", 25 | "@types/semver": "^7.5.8", 26 | "@types/tmp": "^0.2.6", 27 | "@types/yargs": "^17.0.33", 28 | "mocha": "^10.7.3", 29 | "ts-node": "^10.9.2", 30 | "typedoc": "^0.26.7", 31 | "typescript": "^5.5.4" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ts-test/scripts/three_node.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | set -x 5 | 6 | # Setup a cluster with RF=3 and 3 nodes in individual racks 7 | aerolab cluster create --count=3 --start=n -i=22.04 -f features.conf 8 | 9 | # Configure rack ids for each node 10 | aerolab conf rackid --nodes=1 --id=1 --no-restart 11 | aerolab conf rackid --nodes=2 --id=2 --no-restart 12 | aerolab conf rackid --nodes=3 --id=3 --no-restart 13 | 14 | # Set RF = 3 for all nodes 15 | aerolab attach shell -l all -- sed -i "s/replication-factor 2/replication-factor 3/" /etc/aerospike/aerospike.conf 16 | 17 | # restart 18 | aerolab aerospike restart 19 | 20 | # Get ip address of seed node 21 | echo SEED_IP=$(aerolab cluster list -j | jq ".[0].IpAddress" | tr -d \") 22 | -------------------------------------------------------------------------------- /ts-test/tests/README.md: -------------------------------------------------------------------------------- 1 | # Testing Aerospike Node.js Client 2 | 3 | ## Installation 4 | 5 | We also recommend installing Aerospike dependencies by running the following 6 | from the module's root directory: 7 | 8 | $ npm update 9 | 10 | This will install all required dependencies. 11 | 12 | ## Usage 13 | 14 | To run the test cases: 15 | 16 | $ npm test 17 | 18 | The tests are written and run using [`mocha`](http://visionmedia.github.io/mocha). 19 | You can choose to use `mocha` directly, but you must first install `mocha`: 20 | 21 | $ npm install -g mocha 22 | 23 | Note: some users may need to run this as sudo. 24 | 25 | Then to run the tests via mocha, you will want to run it from the modules' root 26 | directory: 27 | 28 | $ mocha -R spec 29 | 30 | ## Options 31 | 32 | You can modify the test with various options: 33 | 34 | --help Display this message. 35 | --host, -h Aerospike database address. [default: "127.0.0.1"] 36 | --port, -p Aerospike database port. [default: 3000] 37 | --timeout, -t Timeout in milliseconds. [default: 10] 38 | --log, -l Log level [0-5] [default: 2] 39 | --namespace, -n Namespace for the keys. [default: "test"] 40 | --set, -s Set for the keys. [default: "demo"] 41 | 42 | Options can be set via an environment variable `OPTIONS`: 43 | 44 | $ OPTIONS="--port 3010" npm test 45 | -------------------------------------------------------------------------------- /ts-test/tests/aerospike.ts: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | /* global expect, describe, it */ 20 | 21 | import Aerospike, { Client } from 'aerospike'; 22 | 23 | import { expect } from 'chai'; 24 | import * as helper from './test_helper'; 25 | let client: Client 26 | describe('Aerospike', function () { 27 | describe('Aerospike.client() #noserver', function () { 28 | it('instantiates a new client instance', function (done) { 29 | client = Aerospike.client(helper.config) 30 | expect(client).to.be.instanceof(Aerospike.Client) 31 | done() 32 | }) 33 | }) 34 | 35 | describe('Aerospike.connect()', function () { 36 | it('instantiates a new client instance and connects to the cluster', function (done) { 37 | Aerospike.connect(helper.config, (error?: Error, client?) => { 38 | if (error) throw error 39 | expect(client).to.be.instanceof(Aerospike.Client) 40 | client?.infoAny((err?: Error) => { 41 | if (err) throw err 42 | client.close(false) 43 | done() 44 | }) 45 | }) 46 | }) 47 | 48 | it('returns a Promise that resolves to a client', function () { 49 | return Aerospike.connect(helper.config) 50 | .then(client => { 51 | expect(client).to.be.instanceof(Aerospike.Client) 52 | return client 53 | }) 54 | .then(client => client.close(false)) 55 | }) 56 | }) 57 | }) 58 | -------------------------------------------------------------------------------- /ts-test/tests/bigint.ts: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | /* eslint-env mocha */ 20 | /* global expect */ 21 | 22 | 23 | import * as helper from './test_helper'; 24 | 25 | import { expect } from 'chai'; 26 | 27 | describe('bigint', function () { 28 | context('BigInt supported - Node.js 10 and later', function () { 29 | describe('BigInt', function () { 30 | it('is an alias for the built-in BigInt', function () { 31 | expect(BigInt(42)).to.eq(global.BigInt(42)) 32 | }) 33 | }) 34 | }) 35 | }) 36 | -------------------------------------------------------------------------------- /ts-test/tests/command.js: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | /* eslint-env mocha */ 20 | /* global expect */ 21 | 22 | require('./test_helper') 23 | const Command = require('../lib/commands/command') 24 | 25 | describe('Command', function () { 26 | context('Extend Command', function () { 27 | class TestCommand extends Command('testCmd') { 28 | foo () { return 'bar' } 29 | } 30 | 31 | it('creates subclasses with informative constructor names', function () { 32 | const cmd = new TestCommand({}) 33 | expect(cmd.constructor.name).to.equal('TestCommand') 34 | }) 35 | 36 | it('keeps a reference to the client instance', function () { 37 | const client = {} 38 | const cmd = new TestCommand(client) 39 | expect(cmd.client).to.equal(client) 40 | }) 41 | }) 42 | }) 43 | -------------------------------------------------------------------------------- /ts-test/tests/double.ts: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | /* global expect, describe, it */ 20 | 21 | import Aerospike, { Double as Doub } from 'aerospike'; 22 | 23 | import { expect } from 'chai'; 24 | 25 | const Double = Aerospike.Double 26 | 27 | describe('Aerospike.Double #noserver', function () { 28 | describe('constructor', function () { 29 | it('returns a new Double value', function () { 30 | const subject: Doub = new Double(3.1415) 31 | 32 | expect(subject).to.be.instanceof(Double) 33 | expect(subject.Double).to.equal(3.1415) 34 | }) 35 | /* 36 | it('throws an error if not passed a number', function () { 37 | const fn = () => new Double('four point nine') 38 | expect(fn).to.throw(TypeError) 39 | }) 40 | 41 | it('throws an error if called without `new`', function () { 42 | const fn = () => Double(3.1415) 43 | expect(fn).to.throw('Invalid use of Double constructor') 44 | }) 45 | */ 46 | }) 47 | 48 | describe('#value()', function () { 49 | const subject: Doub = new Double(3.1415) 50 | 51 | it('returns the double value', function () { 52 | expect(subject.value()).to.equal(3.1415) 53 | }) 54 | }) 55 | }) 56 | -------------------------------------------------------------------------------- /ts-test/tests/generators/key.ts: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | import Aerospike from 'aerospike'; 19 | const Key = Aerospike.Key 20 | import * as valgen from './value'; 21 | 22 | // 23 | // Returns a generator for bytes keys. 24 | // 25 | export function bytes (namespace: any, set: any, options?: any) { 26 | const bgen = valgen.bytes(options) 27 | return function () { 28 | return new Key(namespace, set, bgen()) 29 | } 30 | } 31 | 32 | // 33 | // Returns a generator for string keys. 34 | // 35 | export function string (namespace: any, set: any, options?: any) { 36 | const sgen = valgen.string(options) 37 | return function () { 38 | return new Key(namespace, set, sgen()) 39 | } 40 | } 41 | 42 | // 43 | // Returns a generator for integer keys. 44 | // 45 | export function integer (namespace: any, set: any, options?: any) { 46 | const igen = valgen.integer(options) 47 | return function () { 48 | return new Key(namespace, set, igen()) 49 | } 50 | } 51 | 52 | export function range (keygen: any, end: number, start?: number) { 53 | start = start || 0 54 | end = end || start + 1 55 | const a = [] 56 | for (let i = 0; i < end; i++) { 57 | a.push(keygen()) 58 | } 59 | return a 60 | } -------------------------------------------------------------------------------- /ts-test/tests/generators/metadata.ts: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | // 20 | // Returns a static record. 21 | // 22 | export function constant (metadata: any): () => any { 23 | return function (): any { 24 | return metadata 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ts-test/tests/generators/record.ts: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | import Aerospike, {ConfigOptions, Host, AerospikeBins} from 'aerospike'; 19 | 20 | // 21 | // Returns a static record. 22 | // 23 | export function constant (bins: any): () => AerospikeBins { 24 | return function (): AerospikeBins { 25 | return bins 26 | } 27 | } 28 | 29 | // 30 | // Returns a record from bins spec'd using generators record. 31 | // 32 | export function record (bins: any): () => AerospikeBins { 33 | return function () { 34 | const out: AerospikeBins = {} 35 | for (const bin in bins) { 36 | out[bin] = bins[bin]() 37 | } 38 | return out 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /ts-test/tests/remove_bin.ts: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2013-2024 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | /* global describe, context, it */ 19 | 20 | import Aerospike, { AerospikeError as ASError, status as statusModule, Client as Cli, Key } from 'aerospike'; 21 | 22 | import { expect } from 'chai'; 23 | import * as helper from './test_helper'; 24 | 25 | const keygen = helper.keygen 26 | 27 | const status: typeof statusModule = Aerospike.status 28 | const AerospikeError: typeof ASError = Aerospike.AerospikeError 29 | 30 | describe('client.put(null bin)', function () { 31 | const client: Cli = helper.client 32 | 33 | context('with simple put null value', function () { 34 | it('delete bin using null put', function () { 35 | const key: Key = keygen.string(helper.namespace, helper.set, { prefix: 'test/remove_bin/' })() 36 | 37 | return client.put(key, { str: 'abcde' }) 38 | .then(() => { 39 | client.put(key, { str: null }) 40 | .then(() => { 41 | client.get(key, function (err?: ASError) { 42 | expect(err!).to.be.instanceof(AerospikeError).with.property('code', status.ERR_RECORD_NOT_FOUND) 43 | }) 44 | }) 45 | }) 46 | }) 47 | }) 48 | }) 49 | -------------------------------------------------------------------------------- /ts-test/tests/stats.ts: -------------------------------------------------------------------------------- 1 | // ***************************************************************************** 2 | // Copyright 2018-2023 Aerospike, Inc. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License") 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ***************************************************************************** 16 | 17 | 'use strict' 18 | 19 | /* eslint-env mocha */ 20 | /* global expect */ 21 | /* eslint-disable no-unused-expressions */ 22 | 23 | 24 | import { expect } from 'chai'; 25 | import * as helper from './test_helper'; 26 | 27 | const client = helper.client 28 | 29 | describe('Client#stats', function () { 30 | before(function (done) { 31 | // Send an async command to each node ensure we have at least 1 async 32 | // connection open. At least 1 sync connection has been opened to send some 33 | // info commands. 34 | client.scan(helper.namespace, 'noSuchSet').foreach().on('end', done) 35 | }) 36 | 37 | it('returns command queue stats', function () { 38 | const stats = client.stats() 39 | expect(stats.commands).to.not.be.empty 40 | expect(stats.commands.inFlight).to.be.at.least(0) 41 | expect(stats.commands.queued).to.be.at.least(0) 42 | }) 43 | 44 | it('returns cluster node stats', function () { 45 | const stats = client.stats() 46 | expect(stats.nodes).to.be.an('array').that.is.not.empty 47 | 48 | const node: any = stats.nodes.pop() 49 | expect(node.name).to.be.a('string') 50 | 51 | //const config: ConfigOptions = { 52 | // hosts: helper.config.hosts, 53 | //} 54 | 55 | //const dummyClient = await Aerospike.connect(config) 56 | 57 | for (const connStats of [node.syncConnections, node.asyncConnections]) { 58 | expect(connStats.inPool).to.be.at.least(0) 59 | expect(connStats.inUse).to.be.at.least(0) 60 | expect(connStats.opened).to.be.at.least(1) 61 | expect(connStats.closed).to.be.at.least(0) 62 | } 63 | }) 64 | }) 65 | -------------------------------------------------------------------------------- /ts-test/tests/types/generators.types.ts: -------------------------------------------------------------------------------- 1 | // types/arrayDefaults.ts 2 | 3 | export type StringDefaults = { 4 | random: boolean; 5 | length: { 6 | min: number; 7 | max: number; 8 | }; 9 | prefix: string; 10 | suffix: string; 11 | charset: string; 12 | }; 13 | 14 | export type BytesDefaults = { 15 | length: { 16 | min: number; 17 | max: number; 18 | }; 19 | byte: { 20 | min: number; 21 | max: number; 22 | }; 23 | }; 24 | 25 | export type IntegerDefaults = { 26 | random: boolean; 27 | min: number; 28 | max: number; 29 | }; 30 | 31 | export type DoubleDefaults = { 32 | random: boolean; 33 | min: number; 34 | max: number; 35 | step: number; 36 | }; 37 | 38 | export type GeneratorFunction = () => number | string | Uint8Array; 39 | 40 | export type ArrayDefaults = { 41 | values: GeneratorFunction[]; 42 | }; 43 | 44 | export interface Options { 45 | help: boolean; 46 | host: string | null; 47 | port: number | null; 48 | totalTimeout: number; 49 | log: number; 50 | log_file: number; 51 | namespace: string; 52 | set: string; 53 | user: string | null; 54 | password: string | null; 55 | clusterName?: string; 56 | cafile?: string; 57 | keyfile?: string; 58 | keyfilePassword?: string; 59 | certfile?: string; 60 | auth?: string; 61 | } 62 | 63 | export type Defaults = StringDefaults | BytesDefaults | IntegerDefaults | DoubleDefaults | ArrayDefaults; 64 | 65 | export interface TypeOptions { 66 | defaults: Defaults 67 | } 68 | 69 | export interface ExtendedOptions extends Options, TypeOptions {} 70 | 71 | -------------------------------------------------------------------------------- /ts-test/tests/udf.lua: -------------------------------------------------------------------------------- 1 | function withArguments(rec, value) 2 | return value 3 | end 4 | 5 | function withoutArguments(rec) 6 | return 1 7 | end 8 | 9 | function noop(rec) 10 | end 11 | 12 | 13 | function createRecord(rec, binName, binValue) 14 | rec[binName] = binValue 15 | if (aerospike:exists(rec)) then 16 | status = aerospike:udpate(rec) 17 | else 18 | status = aerospike:create(rec) 19 | end 20 | return status 21 | end 22 | 23 | function updateRecord(rec, binName, binValue) 24 | rec[binName] = binValue 25 | aerospike:update(rec) 26 | return rec 27 | end 28 | 29 | function count(stream) 30 | local function mapper(rec) 31 | return 1 32 | end 33 | local function reducer(v1, v2) 34 | return v1 + v2 35 | end 36 | return stream : map(mapper) : reduce(reducer) 37 | end 38 | 39 | function countGreaterThan(stream, binName, value) 40 | local function mapper(rec) 41 | if rec[binName] > value then 42 | return 1 43 | else 44 | return 0 45 | end 46 | end 47 | local function reducer(v1, v2) 48 | return v1 + v2 49 | end 50 | return stream : map(mapper) : reduce(reducer) 51 | end 52 | 53 | function even(stream, bin) 54 | local function filt(rec) 55 | return rec.value % 2 == 0 56 | end 57 | local function mapper(rec) 58 | return rec.value 59 | end 60 | return stream : filter(filt) : map(mapper) 61 | end 62 | -------------------------------------------------------------------------------- /ts-test/tests/util/index.ts: -------------------------------------------------------------------------------- 1 | export * from './options'; 2 | export * from './run_in_new_process'; 3 | export * from './sleep' 4 | export * from './statefulAsyncTest' -------------------------------------------------------------------------------- /ts-test/tests/util/sleep.ts: -------------------------------------------------------------------------------- 1 | export function sleep (ms: number) { 2 | return new Promise((resolve) => setTimeout(resolve, ms)) 3 | } 4 | -------------------------------------------------------------------------------- /ts-test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "module": "commonjs", 5 | "outDir": "./dist", 6 | "strict": true, 7 | "esModuleInterop": true, 8 | "skipLibCheck": true, 9 | "forceConsistentCasingInFileNames": true 10 | }, 11 | "include": ["tests/**/*.ts", "tests/*.ts", "tests/util/*.ts"] 12 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": ["typings/index.d.ts"], 3 | "compilerOptions": { 4 | /* Visit https://aka.ms/tsconfig.json to read more about this file */ 5 | "strict": true, 6 | "module": "commonjs", 7 | "moduleResolution": "node", 8 | "target": "es5", 9 | "lib": [ 10 | "es5", 11 | "dom" 12 | ], 13 | "allowJs": true, 14 | "declaration": true, 15 | "emitDeclarationOnly": true, 16 | "removeComments": true, 17 | "alwaysStrict": true, 18 | "pretty": false, 19 | "incremental": true, 20 | "noEmitHelpers": true, 21 | "importHelpers": true, 22 | "esModuleInterop": true, 23 | "experimentalDecorators": true, 24 | "emitDecoratorMetadata": true, 25 | "noImplicitAny": false, 26 | "resolveJsonModule": true, 27 | "isolatedModules": false, 28 | "skipLibCheck": true, 29 | "baseUrl": ".", 30 | "paths": { 31 | "*": ["typings/*"] 32 | } 33 | } 34 | } 35 | --------------------------------------------------------------------------------