@balena/abstract-sql-compiler 11.0.0-build-11-x-b2280608fff69d9959999c79db6245c4ad561bbc-1 → 11.0.0-build-11-x-7511b8ebe5a9461f20add0ed97d0670ed3b5a479-1
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.
- package/package.json +5 -2
- package/.github/workflows/flowzone.yml +0 -21
- package/.husky/pre-commit +0 -2
- package/.versionbot/CHANGELOG.yml +0 -10729
- package/CHANGELOG.md +0 -3515
- package/repo.yml +0 -12
- package/src/abstract-sql-compiler.ts +0 -1138
- package/src/abstract-sql-optimizer.ts +0 -1632
- package/src/abstract-sql-rules-to-sql.ts +0 -1730
- package/src/abstract-sql-schema-optimizer.ts +0 -172
- package/src/referenced-fields.ts +0 -600
- package/test/abstract-sql/aggregate-json.ts +0 -49
- package/test/abstract-sql/aggregate.ts +0 -161
- package/test/abstract-sql/and-or-boolean-optimisations.ts +0 -115
- package/test/abstract-sql/case-when-else.ts +0 -48
- package/test/abstract-sql/cast.ts +0 -25
- package/test/abstract-sql/coalesce.ts +0 -24
- package/test/abstract-sql/comparisons.ts +0 -360
- package/test/abstract-sql/dates.ts +0 -512
- package/test/abstract-sql/duration.ts +0 -56
- package/test/abstract-sql/empty-query-optimisations.ts +0 -54
- package/test/abstract-sql/functions-wrapper.ts +0 -70
- package/test/abstract-sql/get-referenced-fields.ts +0 -674
- package/test/abstract-sql/get-rule-referenced-fields.ts +0 -345
- package/test/abstract-sql/insert-query.ts +0 -22
- package/test/abstract-sql/is-distinct.ts +0 -102
- package/test/abstract-sql/joins.ts +0 -84
- package/test/abstract-sql/json.ts +0 -58
- package/test/abstract-sql/math.ts +0 -467
- package/test/abstract-sql/nested-in-optimisations.ts +0 -200
- package/test/abstract-sql/not-not-optimisations.ts +0 -15
- package/test/abstract-sql/schema-checks.ts +0 -168
- package/test/abstract-sql/schema-informative-reference.ts +0 -420
- package/test/abstract-sql/schema-rule-optimization.ts +0 -120
- package/test/abstract-sql/schema-rule-to-check.ts +0 -393
- package/test/abstract-sql/schema-views.ts +0 -73
- package/test/abstract-sql/test.ts +0 -192
- package/test/abstract-sql/text.ts +0 -168
- package/test/model.sbvr +0 -60
- package/test/odata/expand.ts +0 -674
- package/test/odata/fields.ts +0 -59
- package/test/odata/filterby.ts +0 -1517
- package/test/odata/orderby.ts +0 -96
- package/test/odata/paging.ts +0 -48
- package/test/odata/resource-parsing.ts +0 -568
- package/test/odata/select.ts +0 -119
- package/test/odata/stress.ts +0 -93
- package/test/odata/test.ts +0 -297
- package/test/sbvr/pilots.ts +0 -1097
- package/test/sbvr/reference-type.ts +0 -211
- package/test/sbvr/test.ts +0 -101
- package/tsconfig.build.json +0 -6
- package/tsconfig.json +0 -25
@@ -1,211 +0,0 @@
|
|
1
|
-
import fs from 'node:fs';
|
2
|
-
import { getTestHelpers } from './test.js';
|
3
|
-
|
4
|
-
const typeVocab = fs.readFileSync(
|
5
|
-
new URL(import.meta.resolve('@balena/sbvr-types/Type.sbvr')),
|
6
|
-
'utf8',
|
7
|
-
);
|
8
|
-
|
9
|
-
const modifiedAtTrigger = (tableName: string) => `\
|
10
|
-
DO
|
11
|
-
$$
|
12
|
-
BEGIN
|
13
|
-
IF NOT EXISTS(
|
14
|
-
SELECT 1
|
15
|
-
FROM "information_schema"."triggers"
|
16
|
-
WHERE "event_object_table" = '${tableName}'
|
17
|
-
AND "trigger_name" = '${tableName}_trigger_update_modified_at'
|
18
|
-
) THEN
|
19
|
-
CREATE TRIGGER "${tableName}_trigger_update_modified_at"
|
20
|
-
BEFORE UPDATE ON "${tableName}"
|
21
|
-
FOR EACH ROW
|
22
|
-
EXECUTE PROCEDURE "trigger_update_modified_at"();
|
23
|
-
END IF;
|
24
|
-
END;
|
25
|
-
$$;`;
|
26
|
-
|
27
|
-
describe('reference type', function () {
|
28
|
-
let test: ReturnType<typeof getTestHelpers>;
|
29
|
-
beforeEach(() => {
|
30
|
-
test = getTestHelpers(typeVocab);
|
31
|
-
});
|
32
|
-
|
33
|
-
it('informative - no foreignKey for reference field', () => {
|
34
|
-
test(
|
35
|
-
`\
|
36
|
-
|
37
|
-
Term: term
|
38
|
-
Term: term history
|
39
|
-
Fact Type: term history references term
|
40
|
-
Necessity: each term history references exactly one term
|
41
|
-
Reference Type: informative
|
42
|
-
`,
|
43
|
-
[
|
44
|
-
`\
|
45
|
-
DO $$
|
46
|
-
BEGIN
|
47
|
-
CREATE FUNCTION "trigger_update_modified_at"()
|
48
|
-
RETURNS TRIGGER AS $fn$
|
49
|
-
BEGIN
|
50
|
-
NEW."modified at" = NOW();
|
51
|
-
RETURN NEW;
|
52
|
-
END;
|
53
|
-
$fn$ LANGUAGE plpgsql;
|
54
|
-
EXCEPTION WHEN duplicate_function THEN
|
55
|
-
NULL;
|
56
|
-
END;
|
57
|
-
$$;`,
|
58
|
-
|
59
|
-
`\
|
60
|
-
CREATE TABLE IF NOT EXISTS "term" (
|
61
|
-
"created at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
62
|
-
, "modified at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
63
|
-
, "id" SERIAL NOT NULL PRIMARY KEY
|
64
|
-
);`,
|
65
|
-
modifiedAtTrigger('term'),
|
66
|
-
`\
|
67
|
-
CREATE TABLE IF NOT EXISTS "term history" (
|
68
|
-
"created at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
69
|
-
, "modified at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
70
|
-
, "id" SERIAL NOT NULL PRIMARY KEY
|
71
|
-
, "references-term" INTEGER NOT NULL
|
72
|
-
);`,
|
73
|
-
modifiedAtTrigger('term history'),
|
74
|
-
],
|
75
|
-
);
|
76
|
-
});
|
77
|
-
|
78
|
-
it('informative - no foreignKey for reference field - order of Reference Type and Rule is irrelevant ', function () {
|
79
|
-
test(
|
80
|
-
`\
|
81
|
-
|
82
|
-
Term: term
|
83
|
-
Term: term history
|
84
|
-
Fact Type: term history references term
|
85
|
-
Reference Type: informative
|
86
|
-
Necessity: each term history references exactly one term
|
87
|
-
`,
|
88
|
-
[
|
89
|
-
`\
|
90
|
-
DO $$
|
91
|
-
BEGIN
|
92
|
-
CREATE FUNCTION "trigger_update_modified_at"()
|
93
|
-
RETURNS TRIGGER AS $fn$
|
94
|
-
BEGIN
|
95
|
-
NEW."modified at" = NOW();
|
96
|
-
RETURN NEW;
|
97
|
-
END;
|
98
|
-
$fn$ LANGUAGE plpgsql;
|
99
|
-
EXCEPTION WHEN duplicate_function THEN
|
100
|
-
NULL;
|
101
|
-
END;
|
102
|
-
$$;`,
|
103
|
-
|
104
|
-
`\
|
105
|
-
CREATE TABLE IF NOT EXISTS "term" (
|
106
|
-
"created at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
107
|
-
, "modified at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
108
|
-
, "id" SERIAL NOT NULL PRIMARY KEY
|
109
|
-
);`,
|
110
|
-
modifiedAtTrigger('term'),
|
111
|
-
`\
|
112
|
-
CREATE TABLE IF NOT EXISTS "term history" (
|
113
|
-
"created at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
114
|
-
, "modified at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
115
|
-
, "id" SERIAL NOT NULL PRIMARY KEY
|
116
|
-
, "references-term" INTEGER NOT NULL
|
117
|
-
);`,
|
118
|
-
modifiedAtTrigger('term history'),
|
119
|
-
],
|
120
|
-
);
|
121
|
-
});
|
122
|
-
|
123
|
-
it('strict - foreignKey for reference field', function () {
|
124
|
-
test(
|
125
|
-
`\
|
126
|
-
Term: term
|
127
|
-
Term: term history
|
128
|
-
Fact Type: term history references term
|
129
|
-
Necessity: each term history references exactly one term
|
130
|
-
Reference Type: strict
|
131
|
-
`,
|
132
|
-
[
|
133
|
-
`\
|
134
|
-
DO $$
|
135
|
-
BEGIN
|
136
|
-
CREATE FUNCTION "trigger_update_modified_at"()
|
137
|
-
RETURNS TRIGGER AS $fn$
|
138
|
-
BEGIN
|
139
|
-
NEW."modified at" = NOW();
|
140
|
-
RETURN NEW;
|
141
|
-
END;
|
142
|
-
$fn$ LANGUAGE plpgsql;
|
143
|
-
EXCEPTION WHEN duplicate_function THEN
|
144
|
-
NULL;
|
145
|
-
END;
|
146
|
-
$$;`,
|
147
|
-
|
148
|
-
`\
|
149
|
-
CREATE TABLE IF NOT EXISTS "term" (
|
150
|
-
"created at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
151
|
-
, "modified at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
152
|
-
, "id" SERIAL NOT NULL PRIMARY KEY
|
153
|
-
);`,
|
154
|
-
modifiedAtTrigger('term'),
|
155
|
-
`\
|
156
|
-
CREATE TABLE IF NOT EXISTS "term history" (
|
157
|
-
"created at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
158
|
-
, "modified at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
159
|
-
, "id" SERIAL NOT NULL PRIMARY KEY
|
160
|
-
, "references-term" INTEGER NOT NULL
|
161
|
-
, FOREIGN KEY ("references-term") REFERENCES "term" ("id")
|
162
|
-
);`,
|
163
|
-
modifiedAtTrigger('term history'),
|
164
|
-
],
|
165
|
-
);
|
166
|
-
});
|
167
|
-
|
168
|
-
it('default (strict) - foreignKey for reference field', function () {
|
169
|
-
test(
|
170
|
-
`\
|
171
|
-
Term: term
|
172
|
-
Term: term history
|
173
|
-
Fact Type: term history references term
|
174
|
-
Necessity: each term history references exactly one term
|
175
|
-
`,
|
176
|
-
[
|
177
|
-
`\
|
178
|
-
DO $$
|
179
|
-
BEGIN
|
180
|
-
CREATE FUNCTION "trigger_update_modified_at"()
|
181
|
-
RETURNS TRIGGER AS $fn$
|
182
|
-
BEGIN
|
183
|
-
NEW."modified at" = NOW();
|
184
|
-
RETURN NEW;
|
185
|
-
END;
|
186
|
-
$fn$ LANGUAGE plpgsql;
|
187
|
-
EXCEPTION WHEN duplicate_function THEN
|
188
|
-
NULL;
|
189
|
-
END;
|
190
|
-
$$;`,
|
191
|
-
|
192
|
-
`\
|
193
|
-
CREATE TABLE IF NOT EXISTS "term" (
|
194
|
-
"created at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
195
|
-
, "modified at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
196
|
-
, "id" SERIAL NOT NULL PRIMARY KEY
|
197
|
-
);`,
|
198
|
-
modifiedAtTrigger('term'),
|
199
|
-
`\
|
200
|
-
CREATE TABLE IF NOT EXISTS "term history" (
|
201
|
-
"created at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
202
|
-
, "modified at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
203
|
-
, "id" SERIAL NOT NULL PRIMARY KEY
|
204
|
-
, "references-term" INTEGER NOT NULL
|
205
|
-
, FOREIGN KEY ("references-term") REFERENCES "term" ("id")
|
206
|
-
);`,
|
207
|
-
modifiedAtTrigger('term history'),
|
208
|
-
],
|
209
|
-
);
|
210
|
-
});
|
211
|
-
});
|
package/test/sbvr/test.ts
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
import _ from 'lodash';
|
2
|
-
import $sbvrTypes from '@balena/sbvr-types';
|
3
|
-
const { default: sbvrTypes } = $sbvrTypes;
|
4
|
-
// @ts-expect-error @balena/sbvr-parser doesn't have types
|
5
|
-
import { SBVRParser } from '@balena/sbvr-parser';
|
6
|
-
// @ts-expect-error @balena/lf-to-abstract-sql doesn't have types
|
7
|
-
import LF2AbstractSQL from '@balena/lf-to-abstract-sql';
|
8
|
-
|
9
|
-
import { expect } from 'chai';
|
10
|
-
import * as AbstractSQLCompiler from '../../out/abstract-sql-compiler.js';
|
11
|
-
|
12
|
-
export function getTestHelpers(builtInVocab: string | boolean = false) {
|
13
|
-
const sbvrParser = SBVRParser.createInstance();
|
14
|
-
sbvrParser.enableReusingMemoizations(sbvrParser._sideEffectingRules);
|
15
|
-
|
16
|
-
const LF2AbstractSQLTranslator = LF2AbstractSQL.createTranslator(sbvrTypes);
|
17
|
-
|
18
|
-
if (builtInVocab) {
|
19
|
-
sbvrParser.AddBuiltInVocab(builtInVocab);
|
20
|
-
}
|
21
|
-
|
22
|
-
let seSoFar = '';
|
23
|
-
|
24
|
-
const runExpectation = (
|
25
|
-
it: Mocha.TestFunction,
|
26
|
-
input: string,
|
27
|
-
expectation: (result: AbstractSQLCompiler.SqlModel | Error) => void,
|
28
|
-
) => {
|
29
|
-
it(input, function () {
|
30
|
-
let result;
|
31
|
-
try {
|
32
|
-
sbvrParser.reset();
|
33
|
-
const lf = sbvrParser.matchAll(seSoFar + input, 'Process');
|
34
|
-
const schema = LF2AbstractSQLTranslator(lf, 'Process');
|
35
|
-
result = AbstractSQLCompiler.postgres.compileSchema(schema);
|
36
|
-
} catch (e: any) {
|
37
|
-
expectation(e);
|
38
|
-
return;
|
39
|
-
}
|
40
|
-
expectation(result);
|
41
|
-
});
|
42
|
-
};
|
43
|
-
|
44
|
-
const runSchema = (
|
45
|
-
it: Mocha.TestFunction,
|
46
|
-
input: string,
|
47
|
-
expectation:
|
48
|
-
| ((result: AbstractSQLCompiler.SqlModel | Error) => void)
|
49
|
-
| string[],
|
50
|
-
) => {
|
51
|
-
runExpectation(it, input, function (result) {
|
52
|
-
seSoFar += input + '\n';
|
53
|
-
if (_.isFunction(expectation)) {
|
54
|
-
expectation(result);
|
55
|
-
} else if (_.isError(result)) {
|
56
|
-
throw result;
|
57
|
-
} else {
|
58
|
-
expect(result).to.have.property('createSchema');
|
59
|
-
// Individually match the statements in order to get a nicer diff if they don't match.
|
60
|
-
const len = Math.max(result.createSchema.length, expectation.length);
|
61
|
-
for (let i = 0; i < len; i++) {
|
62
|
-
expect(result.createSchema[i]).to.equal(expectation[i]);
|
63
|
-
}
|
64
|
-
expect(result.createSchema.length).to.equal(expectation.length);
|
65
|
-
}
|
66
|
-
});
|
67
|
-
};
|
68
|
-
|
69
|
-
const runRule = (
|
70
|
-
it: Mocha.TestFunction,
|
71
|
-
input: string,
|
72
|
-
expectation:
|
73
|
-
| ((result: AbstractSQLCompiler.SqlModel | Error) => void)
|
74
|
-
| string,
|
75
|
-
) => {
|
76
|
-
runExpectation(it, 'Rule: ' + input, function (result) {
|
77
|
-
if (_.isFunction(expectation)) {
|
78
|
-
expectation(result);
|
79
|
-
} else if (_.isError(result)) {
|
80
|
-
throw result;
|
81
|
-
} else {
|
82
|
-
expect(result).to.have.property('rules');
|
83
|
-
const lastRule = _.last(result.rules);
|
84
|
-
expect(lastRule)
|
85
|
-
.to.have.property('structuredEnglish')
|
86
|
-
.that.equals(input);
|
87
|
-
expect(lastRule).to.have.property('sql').that.equals(expectation);
|
88
|
-
}
|
89
|
-
});
|
90
|
-
};
|
91
|
-
|
92
|
-
const ret = runSchema.bind(null, it);
|
93
|
-
ret.skip = runSchema.bind(null, it.skip);
|
94
|
-
// eslint-disable-next-line no-only-tests/no-only-tests -- this is a false positive
|
95
|
-
ret.only = runSchema.bind(null, it.only);
|
96
|
-
ret.rule = runRule.bind(null, it);
|
97
|
-
ret.rule.skip = runRule.bind(null, it.skip);
|
98
|
-
// eslint-disable-next-line no-only-tests/no-only-tests -- this is a false positive
|
99
|
-
ret.rule.only = runRule.bind(null, it.only);
|
100
|
-
return ret;
|
101
|
-
}
|
package/tsconfig.build.json
DELETED
package/tsconfig.json
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"compilerOptions": {
|
3
|
-
"module": "Node16",
|
4
|
-
"strict": true,
|
5
|
-
"strictFunctionTypes": false,
|
6
|
-
"strictBindCallApply": false,
|
7
|
-
"noImplicitThis": false,
|
8
|
-
"noUnusedParameters": true,
|
9
|
-
"noUnusedLocals": true,
|
10
|
-
"preserveConstEnums": true,
|
11
|
-
"sourceMap": true,
|
12
|
-
"declaration": true,
|
13
|
-
"skipLibCheck": true,
|
14
|
-
"exactOptionalPropertyTypes": true,
|
15
|
-
"target": "es2023",
|
16
|
-
"outDir": "out"
|
17
|
-
},
|
18
|
-
"include": [
|
19
|
-
"src/**/*",
|
20
|
-
"test/**/*"
|
21
|
-
],
|
22
|
-
"exclude": [
|
23
|
-
"node_modules"
|
24
|
-
]
|
25
|
-
}
|