Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions src/results/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,27 @@ import {
} from './tests';

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

beforeAll(async () => {
client = await getClient();
function setup() {
beforeAll(async () => {
client = await getClient();

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

afterAll(async () => {
await client.deleteDatabase(databaseName);
});
await createDatabaseIfNotExists(client, databaseName);
});

afterAll(async () => {
await client.deleteDatabase(databaseName);
});
}

describe('Rel to JS standard types', () => {
setup();

standardTypeTests.forEach(test => {
const testFn = test.skip ? it.skip : test.only ? it.only : it;

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

describe('Rel to JS specialization', () => {
setup();

specializationTests.forEach(test => {
const testFn = test.skip ? it.skip : test.only ? it.only : it;

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

describe('Rel to JS value types', () => {
setup();

valueTypeTests.forEach(test => {
const testFn = test.skip ? it.skip : test.only ? it.only : it;

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

describe('Rel to JS value types misc', () => {
setup();

miscValueTypeTests.forEach(test => {
const testFn = test.skip ? it.skip : test.only ? it.only : it;

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

describe('Rel to JS value types specialization', () => {
setup();

valueTypeSpecializationTests.forEach(test => {
const testFn = test.skip ? it.skip : test.only ? it.only : it;

Expand Down
3 changes: 3 additions & 0 deletions src/results/resultUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ export function convertValue<T extends RelTypedValue>(
case 'UInt16':
case 'UInt32':
case 'UInt64':
case 'AutoNumber':
return value;
case 'UInt128':
return uint128ToBigInt(Array.from(value));
Expand Down Expand Up @@ -327,6 +328,7 @@ export function getDisplayValue(
case 'UInt128':
case 'FilePos':
case 'Hash':
case 'AutoNumber':
return val.value.toString();
case 'Missing':
return 'missing';
Expand Down Expand Up @@ -479,6 +481,7 @@ function mapValueType(typeDef: Omit<ValueTypeValue, 'value'>): RelTypeDef {
case 'FilePos':
case 'Missing':
case 'Hash':
case 'AutoNumber':
return {
type: standardValueType,
};
Expand Down
94 changes: 94 additions & 0 deletions src/results/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,20 @@ export const standardTypeTests: Test[] = [
],
displayValues: ['123456789101112313/9123456789101112313'],
},
{
name: 'AutoNumber',
query: `
def num = auto_number["a"]
def output(x) = num(_, x)
`,
typeDefs: [
{
type: 'AutoNumber',
},
],
values: [1n],
displayValues: ['1'],
},
];

export const specializationTests: Test[] = [
Expand Down Expand Up @@ -1373,6 +1387,25 @@ export const specializationTests: Test[] = [
],
displayValues: ['123456789101112313/9123456789101112313'],
},
{
name: 'AutoNumber',
query: `
def num = auto_number["a"]
def v(x) = num(_, x)
def output = #(v)
`,
typeDefs: [
{
type: 'Constant',
value: {
type: 'AutoNumber',
value: 1n,
},
},
],
values: [1n],
displayValues: ['1'],
},
];

export const valueTypeTests: Test[] = [
Expand Down Expand Up @@ -2497,6 +2530,34 @@ export const valueTypeTests: Test[] = [
],
displayValues: ['(:MyType, 1, 123456789101112313/9123456789101112313)'],
},
{
name: 'AutoNumber',
query: `
def num = auto_number["a"]
def anum(x) = num(_, x)
value type MyType = Int, AutoNumber
def output = ^MyType[1, anum]
`,
typeDefs: [
{
type: 'ValueType',
typeDefs: [
{
type: 'Constant',
value: { type: 'String', value: ':MyType' },
},
{
type: 'Int64',
},
{
type: 'AutoNumber',
},
],
},
],
values: [[':MyType', 1n, 1n]],
displayValues: ['(:MyType, 1, 1)'],
},
];

export const miscValueTypeTests: Test[] = [
Expand Down Expand Up @@ -4012,4 +4073,37 @@ export const valueTypeSpecializationTests: Test[] = [
],
displayValues: ['(:MyType, 123456789101112313/9123456789101112313, 1)'],
},
{
name: 'AutoNumber',
query: `
def num = auto_number["a"]
def anum(x) = num(_, x)
value type MyType = AutoNumber, Int
def v = ^MyType[anum, 1]
def output = #(v)
`,
typeDefs: [
{
type: 'Constant',
value: {
type: 'ValueType',
typeDefs: [
{
type: 'Constant',
value: { type: 'String', value: ':MyType' },
},
{
type: 'AutoNumber',
},
{
type: 'Int64',
},
],
value: [':MyType', 1n, 1n],
},
},
],
values: [[':MyType', 1n, 1n]],
displayValues: ['(:MyType, 1, 1)'],
},
];
9 changes: 8 additions & 1 deletion src/results/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export type RelBaseTypedValue =
| Rational16Value
| Rational32Value
| Rational64Value
| Rational128Value;
| Rational128Value
| AutoNumber;

export type RelTypedValue = RelBaseTypedValue | ValueTypeValue | UnknownType;

Expand Down Expand Up @@ -104,6 +105,7 @@ export type RelTypeDef =
| Omit<Rational32Value, 'value'>
| Omit<Rational64Value, 'value'>
| Omit<Rational128Value, 'value'>
| Omit<AutoNumber, 'value'>
| ConstantValue
| Omit<ValueTypeValue, 'value'>
| Omit<UnknownType, 'value'>;
Expand Down Expand Up @@ -338,6 +340,11 @@ export type Rational128Value = {
};
};

export type AutoNumber = {
type: 'AutoNumber';
value: bigint;
};

// TODO: should be removed with JSON based metadata implementation?
export type UnknownType = {
type: 'Unknown';
Expand Down