Skip to content

Commit 0271783

Browse files
author
Denis Gursky
committed
added autonumber support
1 parent 7c730eb commit 0271783

File tree

4 files changed

+131
-9
lines changed

4 files changed

+131
-9
lines changed

src/results/integration.test.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,27 @@ import {
3131
} from './tests';
3232

3333
describe('Integration', () => {
34-
const databaseName = `js-sdk-tests-${Date.now()}`;
3534
const engineName = getEngineName();
35+
let databaseName: string;
3636
let client: Client;
3737

38-
beforeAll(async () => {
39-
client = await getClient();
38+
function setup() {
39+
beforeAll(async () => {
40+
client = await getClient();
4041

41-
await createDatabaseIfNotExists(client, databaseName);
42-
});
42+
databaseName = `js-sdk-tests-${Date.now()}`;
4343

44-
afterAll(async () => {
45-
await client.deleteDatabase(databaseName);
46-
});
44+
await createDatabaseIfNotExists(client, databaseName);
45+
});
46+
47+
afterAll(async () => {
48+
await client.deleteDatabase(databaseName);
49+
});
50+
}
4751

4852
describe('Rel to JS standard types', () => {
53+
setup();
54+
4955
standardTypeTests.forEach(test => {
5056
const testFn = test.skip ? it.skip : test.only ? it.only : it;
5157

@@ -66,6 +72,8 @@ describe('Integration', () => {
6672
});
6773

6874
describe('Rel to JS specialization', () => {
75+
setup();
76+
6977
specializationTests.forEach(test => {
7078
const testFn = test.skip ? it.skip : test.only ? it.only : it;
7179

@@ -86,6 +94,8 @@ describe('Integration', () => {
8694
});
8795

8896
describe('Rel to JS value types', () => {
97+
setup();
98+
8999
valueTypeTests.forEach(test => {
90100
const testFn = test.skip ? it.skip : test.only ? it.only : it;
91101

@@ -106,6 +116,8 @@ describe('Integration', () => {
106116
});
107117

108118
describe('Rel to JS value types misc', () => {
119+
setup();
120+
109121
miscValueTypeTests.forEach(test => {
110122
const testFn = test.skip ? it.skip : test.only ? it.only : it;
111123

@@ -126,6 +138,8 @@ describe('Integration', () => {
126138
});
127139

128140
describe('Rel to JS value types specialization', () => {
141+
setup();
142+
129143
valueTypeSpecializationTests.forEach(test => {
130144
const testFn = test.skip ? it.skip : test.only ? it.only : it;
131145

src/results/resultUtils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ export function convertValue<T extends RelTypedValue>(
205205
case 'UInt16':
206206
case 'UInt32':
207207
case 'UInt64':
208+
case 'AutoNumber':
208209
return value;
209210
case 'UInt128':
210211
return uint128ToBigInt(Array.from(value));
@@ -327,6 +328,7 @@ export function getDisplayValue(
327328
case 'UInt128':
328329
case 'FilePos':
329330
case 'Hash':
331+
case 'AutoNumber':
330332
return val.value.toString();
331333
case 'Missing':
332334
return 'missing';
@@ -540,7 +542,12 @@ function mapValueType(typeDef: Omit<ValueTypeValue, 'value'>): RelTypeDef {
540542
return { type: 'Rational128' };
541543
}
542544
}
545+
break;
543546
}
547+
case 'AutoNumber':
548+
return {
549+
type: standardValueType,
550+
};
544551
}
545552

546553
return typeDef;

src/results/tests.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,20 @@ export const standardTypeTests: Test[] = [
576576
],
577577
displayValues: ['123456789101112313/9123456789101112313'],
578578
},
579+
{
580+
name: 'AutoNumber',
581+
query: `
582+
def num = auto_number["a"]
583+
def output(x) = num(_, x)
584+
`,
585+
typeDefs: [
586+
{
587+
type: 'AutoNumber',
588+
},
589+
],
590+
values: [1n],
591+
displayValues: ['1'],
592+
},
579593
];
580594

581595
export const specializationTests: Test[] = [
@@ -1373,6 +1387,25 @@ export const specializationTests: Test[] = [
13731387
],
13741388
displayValues: ['123456789101112313/9123456789101112313'],
13751389
},
1390+
{
1391+
name: 'AutoNumber',
1392+
query: `
1393+
def num = auto_number["a"]
1394+
def v(x) = num(_, x)
1395+
def output = #(v)
1396+
`,
1397+
typeDefs: [
1398+
{
1399+
type: 'Constant',
1400+
value: {
1401+
type: 'AutoNumber',
1402+
value: 1n,
1403+
},
1404+
},
1405+
],
1406+
values: [1n],
1407+
displayValues: ['1'],
1408+
},
13761409
];
13771410

13781411
export const valueTypeTests: Test[] = [
@@ -2497,6 +2530,34 @@ export const valueTypeTests: Test[] = [
24972530
],
24982531
displayValues: ['(:MyType, 1, 123456789101112313/9123456789101112313)'],
24992532
},
2533+
{
2534+
name: 'AutoNumber',
2535+
query: `
2536+
def num = auto_number["a"]
2537+
def anum(x) = num(_, x)
2538+
value type MyType = Int, AutoNumber
2539+
def output = ^MyType[1, anum]
2540+
`,
2541+
typeDefs: [
2542+
{
2543+
type: 'ValueType',
2544+
typeDefs: [
2545+
{
2546+
type: 'Constant',
2547+
value: { type: 'String', value: ':MyType' },
2548+
},
2549+
{
2550+
type: 'Int64',
2551+
},
2552+
{
2553+
type: 'AutoNumber',
2554+
},
2555+
],
2556+
},
2557+
],
2558+
values: [[':MyType', 1n, 1n]],
2559+
displayValues: ['(:MyType, 1, 1)'],
2560+
},
25002561
];
25012562

25022563
export const miscValueTypeTests: Test[] = [
@@ -4012,4 +4073,37 @@ export const valueTypeSpecializationTests: Test[] = [
40124073
],
40134074
displayValues: ['(:MyType, 123456789101112313/9123456789101112313, 1)'],
40144075
},
4076+
{
4077+
name: 'AutoNumber',
4078+
query: `
4079+
def num = auto_number["a"]
4080+
def anum(x) = num(_, x)
4081+
value type MyType = AutoNumber, Int
4082+
def v = ^MyType[anum, 1]
4083+
def output = #(v)
4084+
`,
4085+
typeDefs: [
4086+
{
4087+
type: 'Constant',
4088+
value: {
4089+
type: 'ValueType',
4090+
typeDefs: [
4091+
{
4092+
type: 'Constant',
4093+
value: { type: 'String', value: ':MyType' },
4094+
},
4095+
{
4096+
type: 'AutoNumber',
4097+
},
4098+
{
4099+
type: 'Int64',
4100+
},
4101+
],
4102+
value: [':MyType', 1n, 1n],
4103+
},
4104+
},
4105+
],
4106+
values: [[':MyType', 1n, 1n]],
4107+
displayValues: ['(:MyType, 1, 1)'],
4108+
},
40154109
];

src/results/types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ export type RelBaseTypedValue =
5959
| Rational16Value
6060
| Rational32Value
6161
| Rational64Value
62-
| Rational128Value;
62+
| Rational128Value
63+
| AutoNumber;
6364

6465
export type RelTypedValue = RelBaseTypedValue | ValueTypeValue | UnknownType;
6566

@@ -104,6 +105,7 @@ export type RelTypeDef =
104105
| Omit<Rational32Value, 'value'>
105106
| Omit<Rational64Value, 'value'>
106107
| Omit<Rational128Value, 'value'>
108+
| Omit<AutoNumber, 'value'>
107109
| ConstantValue
108110
| Omit<ValueTypeValue, 'value'>
109111
| Omit<UnknownType, 'value'>;
@@ -338,6 +340,11 @@ export type Rational128Value = {
338340
};
339341
};
340342

343+
export type AutoNumber = {
344+
type: 'AutoNumber';
345+
value: bigint;
346+
};
347+
341348
// TODO: should be removed with JSON based metadata implementation?
342349
export type UnknownType = {
343350
type: 'Unknown';

0 commit comments

Comments
 (0)