pelias-schema 9.1.0 → 10.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ name: Unit Tests
2
+ on: workflow_call
3
+ jobs:
4
+ unit-tests:
5
+ runs-on: '${{ matrix.os }}'
6
+ strategy:
7
+ matrix:
8
+ os:
9
+ - ubuntu-24.04
10
+ node-version: [ 22.x, 24.x, 26.x ]
11
+ steps:
12
+ - uses: actions/checkout@v6
13
+ - name: 'Install node.js ${{ matrix.node-version }}'
14
+ uses: actions/setup-node@v6
15
+ with:
16
+ node-version: '${{ matrix.node-version }}'
17
+ - name: Run unit tests
18
+ run: |
19
+ [[ -f ./bin/ci-setup ]] && ./bin/ci-setup
20
+ npm install
21
+ npm run ci
@@ -4,8 +4,4 @@ jobs:
4
4
  unit-tests:
5
5
  # only run this job for forks
6
6
  if: github.event.pull_request.head.repo.full_name != github.repository
7
- uses: ./.github/workflows/_unit_tests.yml
8
- integration-tests:
9
- # only run this job for forks
10
- if: github.event.pull_request.head.repo.full_name != github.repository
11
- uses: ./.github/workflows/_integration_tests.yml
7
+ uses: ./.github/workflows/_test.yml
@@ -1,37 +1,36 @@
1
- name: 'Continuous Integration'
2
- on:
3
- push:
4
- branches-ignore:
5
- - 'v[0-9]+.[0-9]+.[0-9]+'
1
+ name: Continuous Integration
2
+ on: push
6
3
  jobs:
7
4
  unit-tests:
8
- uses: ./.github/workflows/_unit_tests.yml
9
- integration-tests:
10
- uses: ./.github/workflows/_integration_tests.yml
5
+ uses: ./.github/workflows/_test.yml
11
6
  npm-publish:
12
- needs: [unit-tests, integration-tests]
13
- if: github.ref == 'refs/heads/master' && github.event_name == 'push'
14
- runs-on: ubuntu-22.04
7
+ needs: unit-tests
8
+ if: github.ref == 'refs/heads/master' && needs.unit-tests.result == 'success'
9
+ runs-on: ubuntu-24.04
10
+ permissions:
11
+ id-token: write
12
+ contents: write
15
13
  steps:
16
- - uses: actions/checkout@v4
17
- - name: Install Node.js
18
- uses: actions/setup-node@v4
19
- with:
20
- node-version: 20.x
21
- - name: Run semantic-release
22
- env:
23
- GH_TOKEN: ${{ secrets.GH_SEMANTIC_RELEASE_TOKEN }}
24
- NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
25
- run: |
26
- curl "https://raw.githubusercontent.com/pelias/ci-tools/master/semantic-release.sh" | bash -
14
+ - uses: actions/checkout@v6
15
+ - name: Install Node.js
16
+ uses: actions/setup-node@v6
17
+ with:
18
+ node-version: 22.x
19
+ - name: Run semantic-release
20
+ env:
21
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22
+ run: >
23
+ if [[ "${{ github.repository_owner }}" == "pelias" ]]; then
24
+ curl "https://raw.githubusercontent.com/pelias/ci-tools/master/semantic-release.sh" | bash -
25
+ fi
27
26
  build-docker-images:
28
27
  # run this job if the unit tests passed and the npm-publish job was a success or was skipped
29
28
  # note: github actions won't run a job if you don't call one of the status check functions, so `always()` is called since it evalutes to `true`
30
29
  if: ${{ always() && needs.unit-tests.result == 'success' && (needs.npm-publish.result == 'success' || needs.npm-publish.result == 'skipped') }}
31
- needs: [unit-tests, integration-tests, npm-publish]
32
- runs-on: ubuntu-22.04
30
+ needs: [unit-tests, npm-publish]
31
+ runs-on: ubuntu-24.04
33
32
  steps:
34
- - uses: actions/checkout@v4
33
+ - uses: actions/checkout@v6
35
34
  - name: Build Docker images
36
35
  env:
37
36
  DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
package/.jshintrc CHANGED
@@ -2,7 +2,7 @@
2
2
  "node": true,
3
3
  "curly": true,
4
4
  "eqeqeq": true,
5
- "esversion": 6,
5
+ "esversion": 11,
6
6
  "freeze": true,
7
7
  "immed": true,
8
8
  "indent": 2,
@@ -13,8 +13,10 @@
13
13
  "nonbsp": true,
14
14
  "nonew": true,
15
15
  "plusplus": false,
16
+ "quotmark": "single",
16
17
  "undef": true,
17
18
  "unused": false,
18
19
  "maxparams": 4,
19
- "maxdepth": 4
20
+ "maxdepth": 4,
21
+ "maxlen": 140
20
22
  }
package/bin/ci ADDED
@@ -0,0 +1,29 @@
1
+ #!/bin/bash
2
+
3
+ # run the unit and integration tests against both icuTokenizer settings
4
+ set -euo pipefail
5
+
6
+ BASE_CONFIG="${PELIAS_CONFIG:-${HOME}/pelias.json}"
7
+ WORKDIR="$(mktemp -d)"
8
+ trap 'rm -rf "${WORKDIR}"' EXIT
9
+
10
+ # write a copy of the config with the icuTokenizer setting overridden
11
+ write_config() {
12
+ local base='{}'
13
+ if [[ -f "${BASE_CONFIG}" ]]; then base="$(cat "${BASE_CONFIG}")"; fi
14
+ jq -n --argjson base "${base}" --argjson icu "$1" \
15
+ '$base * { schema: { icuTokenizer: $icu } }' > "${WORKDIR}/pelias.json"
16
+ }
17
+
18
+ for ICU_TOKENIZER in false true; do
19
+ echo "--- icuTokenizer: ${ICU_TOKENIZER} ---"
20
+ write_config "${ICU_TOKENIZER}"
21
+ export PELIAS_CONFIG="${WORKDIR}/pelias.json"
22
+
23
+ npm run test
24
+
25
+ # the index is recreated per variant to assert the schema is valid for both
26
+ node scripts/drop_index --force-yes &> /dev/null || true
27
+ npm run create_index
28
+ npm run integration
29
+ done
@@ -1,8 +1,11 @@
1
1
  #!/bin/bash
2
- set -e
2
+ set -eo pipefail
3
+
4
+ # the integration tests require a running elasticsearch server
5
+ ES_VERSION="${ES_VERSION:-7.6.1}"
3
6
 
4
7
  # create elasticsearch directory
5
- mkdir /tmp/elasticsearch
8
+ mkdir -p /tmp/elasticsearch
6
9
 
7
10
  # download and install elasticsearch with ICU plugin
8
11
  FILENAME="elasticsearch-${ES_VERSION}-linux-x86_64.tar.gz"
@@ -25,7 +28,7 @@ wget -O - "https://artifacts.elastic.co/downloads/elasticsearch/${FILENAME}" \
25
28
 
26
29
  # wait for server to boot up
27
30
  # logs show that on travis-ci it can take ~17s to boot an ES6 server
28
- source "${BASH_SOURCE%/*}/elastic_wait.sh"
31
+ source "${BASH_SOURCE%/*}/../scripts/elastic_wait.sh"
29
32
  (elastic_wait)
30
33
 
31
34
  # set the correct esclient.apiVersion in pelias.json
@@ -3,11 +3,15 @@ const Joi = require('@hapi/joi');
3
3
  // Schema Configuration
4
4
  // schema.indexName: populated by defaults if not overridden
5
5
  // schema.icuTokenizer: boolean, optional, defaults to false
6
+ // schema.unstoredFields: array of field paths to index but omit from _source, optional
7
+ // schema.excludedFields: array of field paths to remove from the mapping, optional
6
8
  // esclient: object, validation performed by elasticsearch module
7
9
  const schema = Joi.object().required().keys({
8
10
  schema: Joi.object().required().keys({
9
11
  indexName: Joi.string().required(),
10
- icuTokenizer: Joi.boolean().optional()
12
+ icuTokenizer: Joi.boolean().optional(),
13
+ unstoredFields: Joi.array().items(Joi.string()).optional(),
14
+ excludedFields: Joi.array().items(Joi.string()).optional()
11
15
  }),
12
16
  esclient: Joi.object().required()
13
17
  }).unknown(true);
@@ -0,0 +1,28 @@
1
+ const _ = require('lodash');
2
+
3
+ // convert a dotted field path such as 'parent.county_a' into its location in a mapping
4
+ const mappingPath = (field) => _.flatMap(field.split('.'), (part) => ['properties', part]);
5
+
6
+ /**
7
+ * apply field configuration from `schema` section of pelias config to a mapping
8
+ *
9
+ * unstoredFields: fields that are indexed but omitted from _source
10
+ * excludedFields: fields removed from the mapping entirely
11
+ */
12
+ function configureFields(mapping, schemaConfig) {
13
+ const unstored = _.get(schemaConfig, 'unstoredFields', []);
14
+ const excluded = _.get(schemaConfig, 'excludedFields', []);
15
+
16
+ const configured = _.cloneDeep(mapping);
17
+
18
+ if (!_.isEmpty(unstored)) {
19
+ const excludes = _.get(configured, '_source.excludes', []);
20
+ _.set(configured, '_source.excludes', _.union(excludes, unstored));
21
+ }
22
+
23
+ excluded.forEach((field) => _.unset(configured, mappingPath(field)));
24
+
25
+ return configured;
26
+ }
27
+
28
+ module.exports = configureFields;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pelias-schema",
3
- "version": "9.1.0",
3
+ "version": "10.1.0",
4
4
  "author": "pelias",
5
5
  "description": "Elasticsearch schema files and tooling for Pelias",
6
6
  "homepage": "https://github.com/pelias/schema",
@@ -8,6 +8,7 @@
8
8
  "main": "schema.js",
9
9
  "scripts": {
10
10
  "test": "./bin/test",
11
+ "ci": "./bin/ci",
11
12
  "integration": "./bin/integration",
12
13
  "create_index": "./bin/create_index",
13
14
  "drop_index": "node scripts/drop_index",
@@ -25,7 +26,7 @@
25
26
  "url": "https://github.com/pelias/schema/issues"
26
27
  },
27
28
  "engines": {
28
- "node": ">=10.0.0"
29
+ "node": ">=22.0.0"
29
30
  },
30
31
  "dependencies": {
31
32
  "@hapi/joi": "^16.1.8",
@@ -33,8 +34,8 @@
33
34
  "elasticsearch": "^16.0.0",
34
35
  "glob": "^7.1.6",
35
36
  "lodash": "^4.17.15",
36
- "pelias-config": "^6.0.0",
37
- "pelias-logger": "^1.3.0",
37
+ "pelias-config": "^7.0.0",
38
+ "pelias-logger": "^2.0.0",
38
39
  "semver": "^7.1.1"
39
40
  },
40
41
  "devDependencies": {
package/schema.js CHANGED
@@ -1,6 +1,9 @@
1
+ const config = require('pelias-config').generate();
2
+ const configureFields = require('./mappings/configureFields');
3
+
1
4
  const schema = {
2
5
  settings: require('./settings')(),
3
- mappings: require('./mappings/document'),
6
+ mappings: configureFields(require('./mappings/document'), config.schema),
4
7
  };
5
8
 
6
9
  module.exports = schema;
@@ -84,6 +84,43 @@ module.exports.tests.interface = function(test, common) {
84
84
 
85
85
  });
86
86
 
87
+ test('config with array of strings for unstoredFields and excludedFields should not throw error', function(t) {
88
+ var config = {
89
+ schema: {
90
+ indexName: 'example_index',
91
+ unstoredFields: ['addendum', 'parent.county_a'],
92
+ excludedFields: ['popularity']
93
+ },
94
+ esclient: {}
95
+ };
96
+
97
+ t.doesNotThrow(function() {
98
+ configValidation.validate(config);
99
+ }, 'no error should have been thrown');
100
+
101
+ t.end();
102
+ });
103
+
104
+ test('config with non-array unstoredFields or excludedFields should throw error', function(t) {
105
+ ['unstoredFields', 'excludedFields'].forEach((key) => {
106
+ [null, 17, 'addendum', {}, true, [17]].forEach((value) => {
107
+ var config = {
108
+ schema: {
109
+ indexName: 'example_index',
110
+ [key]: value
111
+ },
112
+ esclient: {}
113
+ };
114
+
115
+ t.throws(function() {
116
+ configValidation.validate(config);
117
+ }, new RegExp(`"schema.${key}(\\[0\\])?" must be`), `${key} must be an array of strings`);
118
+ });
119
+ });
120
+
121
+ t.end();
122
+ });
123
+
87
124
  };
88
125
 
89
126
  module.exports.all = function (tape, common) {
@@ -0,0 +1,49 @@
1
+ const configureFields = require('../mappings/configureFields');
2
+ const document = require('../mappings/document');
3
+
4
+ module.exports.tests = {};
5
+
6
+ module.exports.tests.unstored = function(test, common) {
7
+ test('no config leaves mapping unchanged', function(t) {
8
+ t.deepEqual(configureFields(document, undefined), document);
9
+ t.deepEqual(configureFields(document, {}), document);
10
+ t.end();
11
+ });
12
+
13
+ test('unstored fields are appended to _source excludes', function(t) {
14
+ const mapping = configureFields(document, { unstoredFields: ['addendum', 'parent.*_a', 'shape'] });
15
+ t.deepEqual(mapping._source.excludes, ['shape', 'phrase', 'addendum', 'parent.*_a']);
16
+ t.deepEqual(mapping.properties, document.properties, 'properties unchanged');
17
+ t.end();
18
+ });
19
+ };
20
+
21
+ module.exports.tests.excluded = function(test, common) {
22
+ test('excluded fields are removed from mapping', function(t) {
23
+ const mapping = configureFields(document, { excludedFields: ['popularity', 'parent.county_a', 'not_a_field'] });
24
+ t.false(mapping.properties.popularity, 'top level field removed');
25
+ t.false(mapping.properties.parent.properties.county_a, 'nested field removed');
26
+ t.true(mapping.properties.parent.properties.county, 'sibling field kept');
27
+ t.true(mapping.properties.population, 'other fields kept');
28
+ t.end();
29
+ });
30
+
31
+ test('original mapping is not modified', function(t) {
32
+ configureFields(document, { unstoredFields: ['addendum'], excludedFields: ['popularity', 'parent.county_a'] });
33
+ t.deepEqual(document._source.excludes, ['shape', 'phrase']);
34
+ t.true(document.properties.popularity);
35
+ t.true(document.properties.parent.properties.county_a);
36
+ t.end();
37
+ });
38
+ };
39
+
40
+ module.exports.all = function (tape, common) {
41
+
42
+ function test(name, testFunction) {
43
+ return tape('configureFields: ' + name, testFunction);
44
+ }
45
+
46
+ for( var testCase in module.exports.tests ){
47
+ module.exports.tests[testCase](test, common);
48
+ }
49
+ };
package/test/run.js CHANGED
@@ -11,6 +11,7 @@ var common = {
11
11
  var tests = [
12
12
  require('./compile.js'),
13
13
  require('./document.js'),
14
+ require('./configureFields.js'),
14
15
  require('./partial-centroid.js'),
15
16
  require('./partial-admin.js'),
16
17
  require('./partial-keyword.js'),
@@ -1,32 +0,0 @@
1
- name: Integration Tests
2
- on: workflow_call
3
- jobs:
4
- integration-tests:
5
- runs-on: ${{ matrix.os }}
6
- strategy:
7
- matrix:
8
- os:
9
- - ubuntu-22.04
10
- node-version: [ 20.x, 22.x, 24.x ]
11
- es-version: [7.6.1]
12
- icuTokenizer: [true, false]
13
- steps:
14
- - uses: actions/checkout@v4
15
- - name: Install node.js ${{ matrix.node-version }}
16
- uses: actions/setup-node@v4
17
- with:
18
- node-version: ${{ matrix.node-version }}
19
- - name: Start elasticsearch ${{ matrix.es-version }}
20
- env:
21
- ES_VERSION: ${{ matrix.es-version }}
22
- run: ./scripts/setup_ci.sh
23
- - name: Run integration tests
24
- run: |
25
- if [ "${{ matrix.icuTokenizer }}" = "true" ]; then
26
- jq -n '{ schema: { icuTokenizer: true } }' > $(pwd)/config-icu.json
27
- export PELIAS_CONFIG=$(pwd)/config-icu.json
28
- fi
29
- npm install
30
- curl http://127.0.0.1:9200/
31
- ./bin/create_index
32
- npm run integration
@@ -1,25 +0,0 @@
1
- name: Unit Tests
2
- on: workflow_call
3
- jobs:
4
- unit-tests:
5
- runs-on: ${{ matrix.os }}
6
- strategy:
7
- matrix:
8
- os:
9
- - ubuntu-22.04
10
- node-version: [ 20.x, 22.x, 24.x ]
11
- icuTokenizer: [true, false]
12
- steps:
13
- - uses: actions/checkout@v4
14
- - name: Install node.js ${{ matrix.node-version }}
15
- uses: actions/setup-node@v4
16
- with:
17
- node-version: ${{ matrix.node-version }}
18
- - name: Run unit tests
19
- run: |
20
- npm install
21
- if [ "${{ matrix.icuTokenizer }}" = "true" ]; then
22
- jq -n '{ schema: { icuTokenizer: true } }' > $(pwd)/config-icu.json
23
- export PELIAS_CONFIG=$(pwd)/config-icu.json
24
- fi
25
- npm run test