Skip to content

Commit 210b0a6

Browse files
authored
build: Add Elastic v2 licence (#14)
1 parent 6ace2e7 commit 210b0a6

191 files changed

Lines changed: 826 additions & 924 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

LICENCE.txt

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
Elastic License 2.0
2+
3+
URL: https://www.elastic.co/licensing/elastic-license
4+
5+
## Acceptance
6+
7+
By using the software, you agree to all of the terms and conditions below.
8+
9+
## Copyright License
10+
11+
The licensor grants you a non-exclusive, royalty-free, worldwide,
12+
non-sublicensable, non-transferable license to use, copy, distribute, make
13+
available, and prepare derivative works of the software, in each case subject to
14+
the limitations and conditions below.
15+
16+
## Limitations
17+
18+
You may not provide the software to third parties as a hosted or managed
19+
service, where the service provides users with access to any substantial set of
20+
the features or functionality of the software.
21+
22+
You may not move, change, disable, or circumvent the license key functionality
23+
in the software, and you may not remove or obscure any functionality in the
24+
software that is protected by the license key.
25+
26+
You may not alter, remove, or obscure any licensing, copyright, or other notices
27+
of the licensor in the software. Any use of the licensor’s trademarks is subject
28+
to applicable law.
29+
30+
## Patents
31+
32+
The licensor grants you a license, under any patent claims the licensor can
33+
license, or becomes able to license, to make, have made, use, sell, offer for
34+
sale, import and have imported the software, in each case subject to the
35+
limitations and conditions in this license. This license does not cover any
36+
patent claims that you cause to be infringed by modifications or additions to
37+
the software. If you or your company make any written claim that the software
38+
infringes or contributes to infringement of any patent, your patent license for
39+
the software granted under these terms ends immediately. If your company makes
40+
such a claim, your patent license ends immediately for work on behalf of your
41+
company.
42+
43+
## Notices
44+
45+
You must ensure that anyone who gets a copy of any part of the software from you
46+
also gets a copy of these terms.
47+
48+
If you modify the software, you must include in any modified copies of the
49+
software prominent notices stating that you have modified the software.
50+
51+
## No Other Rights
52+
53+
These terms do not imply any licenses other than those expressly granted in
54+
these terms.
55+
56+
## Termination
57+
58+
If you use the software in violation of these terms, such use is not licensed,
59+
and your licenses will automatically terminate. If the licensor provides you
60+
with a notice of your violation, and you cease all violation of this license no
61+
later than 30 days after you receive that notice, your licenses will be
62+
reinstated retroactively. However, if you violate these terms after such
63+
reinstatement, any additional violation of these terms will cause your licenses
64+
to terminate automatically and permanently.
65+
66+
## No Liability
67+
68+
*As far as the law allows, the software comes as is, without any warranty or
69+
condition, and the licensor will not be liable to you for any damages arising
70+
out of these terms or the use or nature of the software, under any kind of
71+
legal claim.*
72+
73+
## Definitions
74+
75+
The **licensor** is the entity offering these terms, and the **software** is the
76+
software the licensor makes available under these terms, including any portion
77+
of it.
78+
79+
**you** refers to the individual or entity agreeing to these terms.
80+
81+
**your company** is any legal entity, sole proprietorship, or other kind of
82+
organization that you work for, plus all organizations that have control over,
83+
are under the control of, or are under common control with that
84+
organization. **control** means ownership of substantially all the assets of an
85+
entity, or the power to direct its management and policies by vote, contract, or
86+
otherwise. Control can be direct or indirect.
87+
88+
**your licenses** are all the licenses granted to you for the software under
89+
these terms.
90+
91+
**use** means anything you do with the software requiring one of your licenses.
92+
93+
**trademark** means trademarks, service marks, and similar rights.

NOTICE.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
esql-js (A set of ts tools to parse, build and transform ES|QL queries programatically).
2+
Copyright 2026 Elasticsearch B.V.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,4 @@ console.log(text);
165165
```
166166

167167
## Licence
168-
TBD
168+
Licensed under [Elastic License 2.0](./LICENCE.txt).

eslint.config.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
// ESLint flat config for TypeScript.
21
import { defineConfig, globalIgnores } from 'eslint/config';
32
import eslint from '@eslint/js';
43
import tseslint from 'typescript-eslint';
54
import eslintConfigPrettier from 'eslint-config-prettier';
5+
import { requireLicenseHeader } from './lint-licence-rule.js';
66

77
export default defineConfig([
8-
globalIgnores(['lib/', 'node_modules/', 'src/parser/antlr/']),
8+
globalIgnores(['lib/', 'node_modules/', 'src/parser/antlr/', '*.js', '*.mjs']),
99
eslint.configs.recommended,
1010
...tseslint.configs.recommended,
1111
{
12+
plugins: {
13+
'local-rules': {
14+
rules: {
15+
'require-license-header': requireLicenseHeader,
16+
},
17+
},
18+
},
1219
rules: {
20+
'local-rules/require-license-header': 'error',
21+
1322
// TypeScript handles this natively; ESLint's no-undef doesn't understand TS types
1423
'no-undef': 'off',
1524

lint-licence-rule.js

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import babelEslint from '@babel/eslint-parser';
2+
3+
const licenseHeader = `/*
4+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
5+
* or more contributor license agreements. Licensed under the Elastic License
6+
* 2.0; you may not use this file except in compliance with the Elastic License
7+
* 2.0.
8+
*/`;
9+
10+
export const requireLicenseHeader = {
11+
meta: {
12+
fixable: 'code',
13+
schema: [
14+
{
15+
type: 'object',
16+
properties: {
17+
license: {
18+
type: 'string',
19+
},
20+
},
21+
additionalProperties: false,
22+
},
23+
],
24+
},
25+
create: (context) => {
26+
return {
27+
Program(program) {
28+
const license = init(context, program, function () {
29+
const parsed = babelEslint.parse(licenseHeader, { requireConfigFile: false });
30+
assert(!parsed.body.length, '"license" option must only include a single comment');
31+
assert(
32+
parsed.comments.length === 1,
33+
'"license" option must only include a single comment'
34+
);
35+
36+
return {
37+
source: licenseHeader,
38+
nodeValue: normalizeWhitespace(parsed.comments[0].value),
39+
};
40+
});
41+
42+
if (!license) {
43+
return;
44+
}
45+
46+
const sourceCode = context.sourceCode;
47+
const comment = sourceCode
48+
.getAllComments()
49+
.find((node) => normalizeWhitespace(node.value) === license.nodeValue);
50+
51+
// no license comment
52+
if (!comment) {
53+
context.report({
54+
message: 'File must start with a license header',
55+
loc: {
56+
start: { line: 1, column: 0 },
57+
end: { line: 1, column: sourceCode.lines[0].length - 1 },
58+
},
59+
fix(fixer) {
60+
if (isHashbang(sourceCode.lines[0])) {
61+
return undefined;
62+
}
63+
64+
return fixer.replaceTextRange([0, 0], licenseHeader + '\n\n');
65+
},
66+
});
67+
return;
68+
}
69+
70+
// ensure there is nothing before the comment
71+
const sourceBeforeNode = sourceCode
72+
.getText()
73+
.slice(0, sourceCode.getIndexFromLoc(comment.loc.start));
74+
if (sourceBeforeNode.length && !isHashbang(sourceBeforeNode)) {
75+
context.report({
76+
node: comment,
77+
message: 'License header must be at the very beginning of the file',
78+
fix(fixer) {
79+
// replace leading whitespace if possible
80+
if (sourceBeforeNode.trim() === '') {
81+
return fixer.replaceTextRange([0, sourceBeforeNode.length], '');
82+
}
83+
84+
// inject content at top and remove node from current location
85+
// if removing whitespace is not possible
86+
return [
87+
fixer.remove(comment),
88+
fixer.replaceTextRange([0, 0], license.source + '\n\n'),
89+
];
90+
},
91+
});
92+
}
93+
},
94+
};
95+
},
96+
};
97+
98+
function isHashbang(text) {
99+
return text.trim().startsWith('#!') && !text.trim().includes('\n');
100+
}
101+
102+
function assert(truth, message) {
103+
if (truth) {
104+
return;
105+
}
106+
107+
const error = new Error(message);
108+
error.failedAssertion = true;
109+
throw error;
110+
}
111+
112+
function normalizeWhitespace(string) {
113+
return string.replace(/\s+/g, ' ');
114+
}
115+
116+
function init(context, program, initStep) {
117+
try {
118+
return initStep();
119+
} catch (error) {
120+
if (error.failedAssertion) {
121+
context.report({
122+
node: program,
123+
message: error.message,
124+
});
125+
} else {
126+
throw error;
127+
}
128+
}
129+
}

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
}
1515
},
1616
"files": [
17+
"NOTICE.txt",
18+
"LICENSE.txt",
1719
"lib"
1820
],
1921
"scripts": {
@@ -38,9 +40,10 @@
3840
},
3941
"repository": "https://github.com/elastic/esql-js.git",
4042
"private": true,
41-
"license": "To be defined",
43+
"license": "SEE LICENSE IN LICENSE.txt",
4244
"sideEffects": false,
4345
"devDependencies": {
46+
"@babel/eslint-parser": "7.28.6",
4447
"@eslint/js": "10.0.1",
4548
"@semantic-release/changelog": "6.0.3",
4649
"@semantic-release/commit-analyzer": "13.0.1",

src/__tests__/fixtures.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
/*
22
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3-
* or more contributor license agreements. Licensed under the "Elastic License
4-
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5-
* Public License v 1"; you may not use this file except in compliance with, at
6-
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7-
* License v3.0 only", or the "Server Side Public License, v 1".
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
86
*/
97

108
export const smallest = `FROM a`;

src/ast/builder/builder.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
/*
22
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3-
* or more contributor license agreements. Licensed under the "Elastic License
4-
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5-
* Public License v 1"; you may not use this file except in compliance with, at
6-
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7-
* License v3.0 only", or the "Server Side Public License, v 1".
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
86
*/
97

108
import { Builder } from '.';

src/ast/builder/builder.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
/*
22
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3-
* or more contributor license agreements. Licensed under the "Elastic License
4-
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5-
* Public License v 1"; you may not use this file except in compliance with, at
6-
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7-
* License v3.0 only", or the "Server Side Public License, v 1".
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
86
*/
97

108
/* eslint-disable @typescript-eslint/no-namespace */

src/ast/builder/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
/*
22
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3-
* or more contributor license agreements. Licensed under the "Elastic License
4-
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5-
* Public License v 1"; you may not use this file except in compliance with, at
6-
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7-
* License v3.0 only", or the "Server Side Public License, v 1".
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
86
*/
97

108
export type * from './types';

0 commit comments

Comments
 (0)