JS Codegen: Do not export typeForT (#1197)

Issue #1081
This commit is contained in:
Erik Arvidsson
2016-04-11 10:34:23 -07:00
parent 7f06df15e3
commit 5c705d42c2
19 changed files with 379 additions and 224 deletions

View File

@@ -42,11 +42,6 @@ func assertOutput(inPath, lang, goldenPath string, t *testing.T) {
var buf bytes.Buffer
pkg := pkg.ParseNomDL("gen", inFile, filepath.Dir(inPath), emptyDS)
written := map[string]bool{}
_, file := filepath.Split(inPath)
if file == "struct_with_list.noms" {
// List<Uint8> is provided twice in the noms files to ensure it is only written once. Therefore we emulate that it was already written for struct_with_list.noms.
written["ListOfUint8"] = true
}
gen := newCodeGen(&buf, getBareFileName(inPath), lang, written, depsMap{}, pkg)
gen.WritePackage()
@@ -69,6 +64,10 @@ func TestGeneratedFiles(t *testing.T) {
// We are not writing deps in this test so lookup by ref does not work.
continue
}
if file == "struct_with_list.noms" || file == "struct_with_dup_list.noms" {
// These two files race to write ListOfUint8
continue
}
assertOutput(n, "go", filepath.Join("test", "gen", file+".go"), t)
assertOutput(n, "js", filepath.Join("test", "gen", file+".js"), t)
}

View File

@@ -1,10 +1,10 @@
{{if .HasTypes}}
const _pkg = new {{importJS "Package"}}([{{range $i, $t := .Types}}
{{toTypeValueJS $t true 3}},{{end}}
{{toTypeValueJS $t true 2}},{{end}}
], [{{range $deps := .Dependencies}}
{{importJS "Ref"}}.parse('{{$deps}}'),{{end}}
]);
{{importJS "registerPackage"}}(_pkg);{{range $i, $t := .Types}}
export const typeFor{{userType $t}} = {{importJS "makeType"}}(_pkg.ref, {{$i}});
const {{userType $t}}$typeDef = _pkg.types[{{$i}}];{{end}}
const {{userType $t}}$type = {{importJS "makeType"}}(_pkg.ref, {{$i}});
const {{userType $t}}$typeDef = {{toTypeValueJS $t false 1}};{{end}}
{{end}}

View File

@@ -11,4 +11,4 @@ interface {{.Name}}$Interface extends {{importJsType "Struct"}} {
set{{title .Name}}(value: {{userTypeJS .T}}): {{$name}}$Interface;{{end}}
}
export const {{.Name}}: Class<{{.Name}}$Interface> = {{importJS "createStructClass"}}(typeFor{{userType .Type}}, {{userType .Type}}$typeDef);
export const {{.Name}}: Class<{{.Name}}$Interface> = {{importJS "createStructClass"}}({{userType .Type}}$type, {{userType .Type}}$typeDef);

View File

@@ -19,20 +19,27 @@ import type {
const _pkg = new _Package([
_makeEnumType('Handedness', 'right', 'left', 'switch'),
_makeStructType('EnumStruct',
[
new _Field('hand', _makeType(new _Ref(), 0), false),
],
[
[
new _Field('hand', _makeType(new _Ref(), 0), false),
],
[
]
),
]
),
], [
]);
_registerPackage(_pkg);
export const typeForHandedness = _makeType(_pkg.ref, 0);
const Handedness$typeDef = _pkg.types[0];
export const typeForEnumStruct = _makeType(_pkg.ref, 1);
const EnumStruct$typeDef = _pkg.types[1];
const Handedness$type = _makeType(_pkg.ref, 0);
const Handedness$typeDef = _makeEnumType('Handedness', 'right', 'left', 'switch');
const EnumStruct$type = _makeType(_pkg.ref, 1);
const EnumStruct$typeDef = _makeStructType('EnumStruct',
[
new _Field('hand', _makeType(_pkg.ref, 0), false),
],
[
]
);
export type Handedness =
@@ -50,4 +57,4 @@ interface EnumStruct$Interface extends _Struct {
setHand(value: Handedness): EnumStruct$Interface;
}
export const EnumStruct: Class<EnumStruct$Interface> = _createStructClass(typeForEnumStruct, EnumStruct$typeDef);
export const EnumStruct: Class<EnumStruct$Interface> = _createStructClass(EnumStruct$type, EnumStruct$typeDef);

View File

@@ -28,18 +28,25 @@ import type {
const _pkg = new _Package([
_makeStructType('StructWithRef',
[
new _Field('r', _makeCompoundType(_Kind.Ref, _makeCompoundType(_Kind.Set, _float32Type)), false),
],
[
[
new _Field('r', _makeCompoundType(_Kind.Ref, _makeCompoundType(_Kind.Set, _float32Type)), false),
],
[
]
),
]
),
], [
]);
_registerPackage(_pkg);
export const typeForStructWithRef = _makeType(_pkg.ref, 0);
const StructWithRef$typeDef = _pkg.types[0];
const StructWithRef$type = _makeType(_pkg.ref, 0);
const StructWithRef$typeDef = _makeStructType('StructWithRef',
[
new _Field('r', _makeCompoundType(_Kind.Ref, _makeCompoundType(_Kind.Set, _float32Type)), false),
],
[
]
);
type StructWithRef$Data = {
@@ -52,7 +59,7 @@ interface StructWithRef$Interface extends _Struct {
setR(value: _RefValue<_NomsSet<_float32>>): StructWithRef$Interface;
}
export const StructWithRef: Class<StructWithRef$Interface> = _createStructClass(typeForStructWithRef, StructWithRef$typeDef);
export const StructWithRef: Class<StructWithRef$Interface> = _createStructClass(StructWithRef$type, StructWithRef$typeDef);
export function newListOfRefOfFloat32(values: Array<_RefValue<_float32>>): Promise<_NomsList<_RefValue<_float32>>> {
return _newList(values, _makeListType(_makeCompoundType(_Kind.Ref, _float32Type)));

View File

@@ -19,22 +19,30 @@ import type {
const _pkg = new _Package([
_makeStructType('S',
[
new _Field('s', _stringType, false),
new _Field('b', _boolType, false),
],
[
[
new _Field('s', _stringType, false),
new _Field('b', _boolType, false),
],
[
]
),
]
),
_makeEnumType('E', 'e1', 'e2', 'e3'),
], [
]);
_registerPackage(_pkg);
export const typeForS = _makeType(_pkg.ref, 0);
const S$typeDef = _pkg.types[0];
export const typeForE = _makeType(_pkg.ref, 1);
const E$typeDef = _pkg.types[1];
const S$type = _makeType(_pkg.ref, 0);
const S$typeDef = _makeStructType('S',
[
new _Field('s', _stringType, false),
new _Field('b', _boolType, false),
],
[
]
);
const E$type = _makeType(_pkg.ref, 1);
const E$typeDef = _makeEnumType('E', 'e1', 'e2', 'e3');
type S$Data = {
@@ -50,7 +58,7 @@ interface S$Interface extends _Struct {
setB(value: boolean): S$Interface;
}
export const S: Class<S$Interface> = _createStructClass(typeForS, S$typeDef);
export const S: Class<S$Interface> = _createStructClass(S$type, S$typeDef);
export type E =
0 | // e1

View File

@@ -23,18 +23,25 @@ import type {
const _pkg = new _Package([
_makeStructType('A',
[
new _Field('A', _makeCompoundType(_Kind.List, _makeCompoundType(_Kind.List, _blobType)), false),
],
[
[
new _Field('A', _makeCompoundType(_Kind.List, _makeCompoundType(_Kind.List, _blobType)), false),
],
[
]
),
]
),
], [
]);
_registerPackage(_pkg);
export const typeForA = _makeType(_pkg.ref, 0);
const A$typeDef = _pkg.types[0];
const A$type = _makeType(_pkg.ref, 0);
const A$typeDef = _makeStructType('A',
[
new _Field('A', _makeCompoundType(_Kind.List, _makeCompoundType(_Kind.List, _blobType)), false),
],
[
]
);
type A$Data = {
@@ -47,7 +54,7 @@ interface A$Interface extends _Struct {
setA(value: _NomsList<_NomsList<_Blob>>): A$Interface;
}
export const A: Class<A$Interface> = _createStructClass(typeForA, A$typeDef);
export const A: Class<A$Interface> = _createStructClass(A$type, A$typeDef);
export function newListOfListOfBlob(values: Array<_NomsList<_Blob>>): Promise<_NomsList<_NomsList<_Blob>>> {
return _newList(values, _makeListType(_makeCompoundType(_Kind.List, _blobType)));

View File

@@ -19,30 +19,45 @@ import * as _sha1_1c216c6 from './sha1_1c216c6.js';
const _pkg = new _Package([
_makeStructType('D',
[
new _Field('structField', _makeType(_Ref.parse('sha1-1c216c6f1d6989e4ede5f78b7689214948dabeef'), 0), false),
new _Field('enumField', _makeType(_Ref.parse('sha1-1c216c6f1d6989e4ede5f78b7689214948dabeef'), 1), false),
],
[
[
new _Field('structField', _makeType(_Ref.parse('sha1-1c216c6f1d6989e4ede5f78b7689214948dabeef'), 0), false),
new _Field('enumField', _makeType(_Ref.parse('sha1-1c216c6f1d6989e4ede5f78b7689214948dabeef'), 1), false),
],
[
]
),
]
),
_makeStructType('DUser',
[
new _Field('Dfield', _makeType(new _Ref(), 0), false),
],
[
[
new _Field('Dfield', _makeType(new _Ref(), 0), false),
],
[
]
),
]
),
], [
_Ref.parse('sha1-1c216c6f1d6989e4ede5f78b7689214948dabeef'),
]);
_registerPackage(_pkg);
export const typeForD = _makeType(_pkg.ref, 0);
const D$typeDef = _pkg.types[0];
export const typeForDUser = _makeType(_pkg.ref, 1);
const DUser$typeDef = _pkg.types[1];
const D$type = _makeType(_pkg.ref, 0);
const D$typeDef = _makeStructType('D',
[
new _Field('structField', _makeType(_Ref.parse('sha1-1c216c6f1d6989e4ede5f78b7689214948dabeef'), 0), false),
new _Field('enumField', _makeType(_Ref.parse('sha1-1c216c6f1d6989e4ede5f78b7689214948dabeef'), 1), false),
],
[
]
);
const DUser$type = _makeType(_pkg.ref, 1);
const DUser$typeDef = _makeStructType('DUser',
[
new _Field('Dfield', _makeType(_pkg.ref, 0), false),
],
[
]
);
type D$Data = {
@@ -58,7 +73,7 @@ interface D$Interface extends _Struct {
setEnumField(value: _sha1_1c216c6.E): D$Interface;
}
export const D: Class<D$Interface> = _createStructClass(typeForD, D$typeDef);
export const D: Class<D$Interface> = _createStructClass(D$type, D$typeDef);
type DUser$Data = {
Dfield: D;
@@ -70,4 +85,4 @@ interface DUser$Interface extends _Struct {
setDfield(value: D): DUser$Interface;
}
export const DUser: Class<DUser$Interface> = _createStructClass(typeForDUser, DUser$typeDef);
export const DUser: Class<DUser$Interface> = _createStructClass(DUser$type, DUser$typeDef);

View File

@@ -21,19 +21,27 @@ import type {
const _pkg = new _Package([
_makeStructType('Struct',
[
new _Field('s', _stringType, false),
new _Field('b', _boolType, false),
],
[
[
new _Field('s', _stringType, false),
new _Field('b', _boolType, false),
],
[
]
),
]
),
], [
]);
_registerPackage(_pkg);
export const typeForStruct = _makeType(_pkg.ref, 0);
const Struct$typeDef = _pkg.types[0];
const Struct$type = _makeType(_pkg.ref, 0);
const Struct$typeDef = _makeStructType('Struct',
[
new _Field('s', _stringType, false),
new _Field('b', _boolType, false),
],
[
]
);
type Struct$Data = {
@@ -49,7 +57,7 @@ interface Struct$Interface extends _Struct {
setB(value: boolean): Struct$Interface;
}
export const Struct: Class<Struct$Interface> = _createStructClass(typeForStruct, Struct$typeDef);
export const Struct: Class<Struct$Interface> = _createStructClass(Struct$type, Struct$typeDef);
export function newListOfStruct(values: Array<Struct>): Promise<_NomsList<Struct>> {
return _newList(values, _makeListType(_makeType(_pkg.ref, 0)));

View File

@@ -18,19 +18,27 @@ import type {
const _pkg = new _Package([
_makeStructType('OptionalStruct',
[
new _Field('s', _stringType, true),
new _Field('b', _boolType, true),
],
[
[
new _Field('s', _stringType, true),
new _Field('b', _boolType, true),
],
[
]
),
]
),
], [
]);
_registerPackage(_pkg);
export const typeForOptionalStruct = _makeType(_pkg.ref, 0);
const OptionalStruct$typeDef = _pkg.types[0];
const OptionalStruct$type = _makeType(_pkg.ref, 0);
const OptionalStruct$typeDef = _makeStructType('OptionalStruct',
[
new _Field('s', _stringType, true),
new _Field('b', _boolType, true),
],
[
]
);
type OptionalStruct$Data = {
@@ -46,4 +54,4 @@ interface OptionalStruct$Interface extends _Struct {
setB(value: ?boolean): OptionalStruct$Interface;
}
export const OptionalStruct: Class<OptionalStruct$Interface> = _createStructClass(typeForOptionalStruct, OptionalStruct$typeDef);
export const OptionalStruct: Class<OptionalStruct$Interface> = _createStructClass(OptionalStruct$type, OptionalStruct$typeDef);

View File

@@ -42,31 +42,51 @@ import type {
const _pkg = new _Package([
_makeStructType('StructPrimitives',
[
new _Field('uint64', _uint64Type, false),
new _Field('uint32', _uint32Type, false),
new _Field('uint16', _uint16Type, false),
new _Field('uint8', _uint8Type, false),
new _Field('int64', _int64Type, false),
new _Field('int32', _int32Type, false),
new _Field('int16', _int16Type, false),
new _Field('int8', _int8Type, false),
new _Field('float64', _float64Type, false),
new _Field('float32', _float32Type, false),
new _Field('bool', _boolType, false),
new _Field('string', _stringType, false),
new _Field('blob', _blobType, false),
new _Field('value', _valueType, false),
],
[
[
new _Field('uint64', _uint64Type, false),
new _Field('uint32', _uint32Type, false),
new _Field('uint16', _uint16Type, false),
new _Field('uint8', _uint8Type, false),
new _Field('int64', _int64Type, false),
new _Field('int32', _int32Type, false),
new _Field('int16', _int16Type, false),
new _Field('int8', _int8Type, false),
new _Field('float64', _float64Type, false),
new _Field('float32', _float32Type, false),
new _Field('bool', _boolType, false),
new _Field('string', _stringType, false),
new _Field('blob', _blobType, false),
new _Field('value', _valueType, false),
],
[
]
),
]
),
], [
]);
_registerPackage(_pkg);
export const typeForStructPrimitives = _makeType(_pkg.ref, 0);
const StructPrimitives$typeDef = _pkg.types[0];
const StructPrimitives$type = _makeType(_pkg.ref, 0);
const StructPrimitives$typeDef = _makeStructType('StructPrimitives',
[
new _Field('uint64', _uint64Type, false),
new _Field('uint32', _uint32Type, false),
new _Field('uint16', _uint16Type, false),
new _Field('uint8', _uint8Type, false),
new _Field('int64', _int64Type, false),
new _Field('int32', _int32Type, false),
new _Field('int16', _int16Type, false),
new _Field('int8', _int8Type, false),
new _Field('float64', _float64Type, false),
new _Field('float32', _float32Type, false),
new _Field('bool', _boolType, false),
new _Field('string', _stringType, false),
new _Field('blob', _blobType, false),
new _Field('value', _valueType, false),
],
[
]
);
type StructPrimitives$Data = {
@@ -118,4 +138,4 @@ interface StructPrimitives$Interface extends _Struct {
setValue(value: _Value): StructPrimitives$Interface;
}
export const StructPrimitives: Class<StructPrimitives$Interface> = _createStructClass(typeForStructPrimitives, StructPrimitives$typeDef);
export const StructPrimitives: Class<StructPrimitives$Interface> = _createStructClass(StructPrimitives$type, StructPrimitives$typeDef);

View File

@@ -22,18 +22,25 @@ import type {
const _pkg = new _Package([
_makeStructType('Tree',
[
new _Field('children', _makeCompoundType(_Kind.List, _makeType(new _Ref(), 0)), false),
],
[
[
new _Field('children', _makeCompoundType(_Kind.List, _makeType(new _Ref(), 0)), false),
],
[
]
),
]
),
], [
]);
_registerPackage(_pkg);
export const typeForTree = _makeType(_pkg.ref, 0);
const Tree$typeDef = _pkg.types[0];
const Tree$type = _makeType(_pkg.ref, 0);
const Tree$typeDef = _makeStructType('Tree',
[
new _Field('children', _makeCompoundType(_Kind.List, _makeType(_pkg.ref, 0)), false),
],
[
]
);
type Tree$Data = {
@@ -46,7 +53,7 @@ interface Tree$Interface extends _Struct {
setChildren(value: _NomsList<Tree>): Tree$Interface;
}
export const Tree: Class<Tree$Interface> = _createStructClass(typeForTree, Tree$typeDef);
export const Tree: Class<Tree$Interface> = _createStructClass(Tree$type, Tree$typeDef);
export function newListOfTree(values: Array<Tree>): Promise<_NomsList<Tree>> {
return _newList(values, _makeListType(_makeType(_pkg.ref, 0)));

View File

@@ -8,10 +8,8 @@ import {
Package as _Package,
createStructClass as _createStructClass,
makeCompoundType as _makeCompoundType,
makeListType as _makeListType,
makeStructType as _makeStructType,
makeType as _makeType,
newList as _newList,
registerPackage as _registerPackage,
uint8Type as _uint8Type,
} from '@attic/noms';
@@ -23,18 +21,25 @@ import type {
const _pkg = new _Package([
_makeStructType('StructWithDupList',
[
new _Field('l', _makeCompoundType(_Kind.List, _uint8Type), false),
],
[
[
new _Field('l', _makeCompoundType(_Kind.List, _uint8Type), false),
],
[
]
),
]
),
], [
]);
_registerPackage(_pkg);
export const typeForStructWithDupList = _makeType(_pkg.ref, 0);
const StructWithDupList$typeDef = _pkg.types[0];
const StructWithDupList$type = _makeType(_pkg.ref, 0);
const StructWithDupList$typeDef = _makeStructType('StructWithDupList',
[
new _Field('l', _makeCompoundType(_Kind.List, _uint8Type), false),
],
[
]
);
type StructWithDupList$Data = {
@@ -47,8 +52,4 @@ interface StructWithDupList$Interface extends _Struct {
setL(value: _NomsList<_uint8>): StructWithDupList$Interface;
}
export const StructWithDupList: Class<StructWithDupList$Interface> = _createStructClass(typeForStructWithDupList, StructWithDupList$typeDef);
export function newListOfUint8(values: Array<_uint8>): Promise<_NomsList<_uint8>> {
return _newList(values, _makeListType(_uint8Type));
}
export const StructWithDupList: Class<StructWithDupList$Interface> = _createStructClass(StructWithDupList$type, StructWithDupList$typeDef);

View File

@@ -24,22 +24,30 @@ import * as dep from './sha1_eda4273.js';
const _pkg = new _Package([
_makeEnumType('LocalE', 'LocalE1', 'Ignored'),
_makeStructType('ImportUser',
[
new _Field('importedStruct', _makeType(_Ref.parse('sha1-eda4273cba9d5d4a1bccf41bcaec64743863cde0'), 0), false),
new _Field('enum', _makeType(new _Ref(), 0), false),
],
[
[
new _Field('importedStruct', _makeType(_Ref.parse('sha1-eda4273cba9d5d4a1bccf41bcaec64743863cde0'), 0), false),
new _Field('enum', _makeType(new _Ref(), 0), false),
],
[
]
),
]
),
], [
_Ref.parse('sha1-eda4273cba9d5d4a1bccf41bcaec64743863cde0'),
]);
_registerPackage(_pkg);
export const typeForLocalE = _makeType(_pkg.ref, 0);
const LocalE$typeDef = _pkg.types[0];
export const typeForImportUser = _makeType(_pkg.ref, 1);
const ImportUser$typeDef = _pkg.types[1];
const LocalE$type = _makeType(_pkg.ref, 0);
const LocalE$typeDef = _makeEnumType('LocalE', 'LocalE1', 'Ignored');
const ImportUser$type = _makeType(_pkg.ref, 1);
const ImportUser$typeDef = _makeStructType('ImportUser',
[
new _Field('importedStruct', _makeType(_Ref.parse('sha1-eda4273cba9d5d4a1bccf41bcaec64743863cde0'), 0), false),
new _Field('enum', _makeType(_pkg.ref, 0), false),
],
[
]
);
export type LocalE =
@@ -59,7 +67,7 @@ interface ImportUser$Interface extends _Struct {
setEnum(value: LocalE): ImportUser$Interface;
}
export const ImportUser: Class<ImportUser$Interface> = _createStructClass(typeForImportUser, ImportUser$typeDef);
export const ImportUser: Class<ImportUser$Interface> = _createStructClass(ImportUser$type, ImportUser$typeDef);
export function newListOfD(values: Array<dep.D>): Promise<_NomsList<dep.D>> {
return _newList(values, _makeListType(_makeType(_Ref.parse('sha1-eda4273cba9d5d4a1bccf41bcaec64743863cde0'), 0)));

View File

@@ -10,8 +10,10 @@ import {
createStructClass as _createStructClass,
int64Type as _int64Type,
makeCompoundType as _makeCompoundType,
makeListType as _makeListType,
makeStructType as _makeStructType,
makeType as _makeType,
newList as _newList,
registerPackage as _registerPackage,
stringType as _stringType,
uint8Type as _uint8Type,
@@ -25,21 +27,31 @@ import type {
const _pkg = new _Package([
_makeStructType('StructWithList',
[
new _Field('l', _makeCompoundType(_Kind.List, _uint8Type), false),
new _Field('b', _boolType, false),
new _Field('s', _stringType, false),
new _Field('i', _int64Type, false),
],
[
[
new _Field('l', _makeCompoundType(_Kind.List, _uint8Type), false),
new _Field('b', _boolType, false),
new _Field('s', _stringType, false),
new _Field('i', _int64Type, false),
],
[
]
),
]
),
], [
]);
_registerPackage(_pkg);
export const typeForStructWithList = _makeType(_pkg.ref, 0);
const StructWithList$typeDef = _pkg.types[0];
const StructWithList$type = _makeType(_pkg.ref, 0);
const StructWithList$typeDef = _makeStructType('StructWithList',
[
new _Field('l', _makeCompoundType(_Kind.List, _uint8Type), false),
new _Field('b', _boolType, false),
new _Field('s', _stringType, false),
new _Field('i', _int64Type, false),
],
[
]
);
type StructWithList$Data = {
@@ -61,4 +73,8 @@ interface StructWithList$Interface extends _Struct {
setI(value: _int64): StructWithList$Interface;
}
export const StructWithList: Class<StructWithList$Interface> = _createStructClass(typeForStructWithList, StructWithList$typeDef);
export const StructWithList: Class<StructWithList$Interface> = _createStructClass(StructWithList$type, StructWithList$typeDef);
export function newListOfUint8(values: Array<_uint8>): Promise<_NomsList<_uint8>> {
return _newList(values, _makeListType(_uint8Type));
}

View File

@@ -32,22 +32,33 @@ import type {
const _pkg = new _Package([
_makeStructType('StructWithUnionField',
[
new _Field('a', _float32Type, false),
],
[
new _Field('b', _float64Type, false),
new _Field('c', _stringType, false),
new _Field('d', _blobType, false),
new _Field('e', _valueType, false),
new _Field('f', _makeCompoundType(_Kind.Set, _uint8Type), false),
]
),
[
new _Field('a', _float32Type, false),
],
[
new _Field('b', _float64Type, false),
new _Field('c', _stringType, false),
new _Field('d', _blobType, false),
new _Field('e', _valueType, false),
new _Field('f', _makeCompoundType(_Kind.Set, _uint8Type), false),
]
),
], [
]);
_registerPackage(_pkg);
export const typeForStructWithUnionField = _makeType(_pkg.ref, 0);
const StructWithUnionField$typeDef = _pkg.types[0];
const StructWithUnionField$type = _makeType(_pkg.ref, 0);
const StructWithUnionField$typeDef = _makeStructType('StructWithUnionField',
[
new _Field('a', _float32Type, false),
],
[
new _Field('b', _float64Type, false),
new _Field('c', _stringType, false),
new _Field('d', _blobType, false),
new _Field('e', _valueType, false),
new _Field('f', _makeCompoundType(_Kind.Set, _uint8Type), false),
]
);
type StructWithUnionField$Data = {
@@ -70,7 +81,7 @@ interface StructWithUnionField$Interface extends _Struct {
setF(value: _NomsSet<_uint8>): StructWithUnionField$Interface;
}
export const StructWithUnionField: Class<StructWithUnionField$Interface> = _createStructClass(typeForStructWithUnionField, StructWithUnionField$typeDef);
export const StructWithUnionField: Class<StructWithUnionField$Interface> = _createStructClass(StructWithUnionField$type, StructWithUnionField$typeDef);
export function newSetOfUint8(values: Array<_uint8>): Promise<_NomsSet<_uint8>> {
return _newSet(values, _makeSetType(_uint8Type));

View File

@@ -20,41 +20,65 @@ import type {
const _pkg = new _Package([
_makeStructType('StructWithUnions',
[
new _Field('a', _makeType(new _Ref(), 1), false),
new _Field('d', _makeType(new _Ref(), 2), false),
],
[
[
new _Field('a', _makeType(new _Ref(), 1), false),
new _Field('d', _makeType(new _Ref(), 2), false),
],
[
]
),
]
),
_makeStructType('',
[
[
],
[
new _Field('b', _float64Type, false),
new _Field('c', _stringType, false),
]
),
],
[
new _Field('b', _float64Type, false),
new _Field('c', _stringType, false),
]
),
_makeStructType('',
[
[
],
[
new _Field('e', _float64Type, false),
new _Field('f', _stringType, false),
]
),
],
[
new _Field('e', _float64Type, false),
new _Field('f', _stringType, false),
]
),
], [
]);
_registerPackage(_pkg);
export const typeForStructWithUnions = _makeType(_pkg.ref, 0);
const StructWithUnions$typeDef = _pkg.types[0];
export const typeFor__unionOfBOfFloat64AndCOfString = _makeType(_pkg.ref, 1);
const __unionOfBOfFloat64AndCOfString$typeDef = _pkg.types[1];
export const typeFor__unionOfEOfFloat64AndFOfString = _makeType(_pkg.ref, 2);
const __unionOfEOfFloat64AndFOfString$typeDef = _pkg.types[2];
const StructWithUnions$type = _makeType(_pkg.ref, 0);
const StructWithUnions$typeDef = _makeStructType('StructWithUnions',
[
new _Field('a', _makeType(_pkg.ref, 1), false),
new _Field('d', _makeType(_pkg.ref, 2), false),
],
[
]
);
const __unionOfBOfFloat64AndCOfString$type = _makeType(_pkg.ref, 1);
const __unionOfBOfFloat64AndCOfString$typeDef = _makeStructType('',
[
],
[
new _Field('b', _float64Type, false),
new _Field('c', _stringType, false),
]
);
const __unionOfEOfFloat64AndFOfString$type = _makeType(_pkg.ref, 2);
const __unionOfEOfFloat64AndFOfString$typeDef = _makeStructType('',
[
],
[
new _Field('e', _float64Type, false),
new _Field('f', _stringType, false),
]
);
type StructWithUnions$Data = {
@@ -70,7 +94,7 @@ interface StructWithUnions$Interface extends _Struct {
setD(value: __unionOfEOfFloat64AndFOfString): StructWithUnions$Interface;
}
export const StructWithUnions: Class<StructWithUnions$Interface> = _createStructClass(typeForStructWithUnions, StructWithUnions$typeDef);
export const StructWithUnions: Class<StructWithUnions$Interface> = _createStructClass(StructWithUnions$type, StructWithUnions$typeDef);
type __unionOfBOfFloat64AndCOfString$Data = {
};
@@ -83,7 +107,7 @@ interface __unionOfBOfFloat64AndCOfString$Interface extends _Struct {
setC(value: string): __unionOfBOfFloat64AndCOfString$Interface;
}
export const __unionOfBOfFloat64AndCOfString: Class<__unionOfBOfFloat64AndCOfString$Interface> = _createStructClass(typeFor__unionOfBOfFloat64AndCOfString, __unionOfBOfFloat64AndCOfString$typeDef);
export const __unionOfBOfFloat64AndCOfString: Class<__unionOfBOfFloat64AndCOfString$Interface> = _createStructClass(__unionOfBOfFloat64AndCOfString$type, __unionOfBOfFloat64AndCOfString$typeDef);
type __unionOfEOfFloat64AndFOfString$Data = {
};
@@ -96,4 +120,4 @@ interface __unionOfEOfFloat64AndFOfString$Interface extends _Struct {
setF(value: string): __unionOfEOfFloat64AndFOfString$Interface;
}
export const __unionOfEOfFloat64AndFOfString: Class<__unionOfEOfFloat64AndFOfString$Interface> = _createStructClass(typeFor__unionOfEOfFloat64AndFOfString, __unionOfEOfFloat64AndFOfString$typeDef);
export const __unionOfEOfFloat64AndFOfString: Class<__unionOfEOfFloat64AndFOfString$Interface> = _createStructClass(__unionOfEOfFloat64AndFOfString$type, __unionOfEOfFloat64AndFOfString$typeDef);

View File

@@ -2,22 +2,23 @@
import {assert} from 'chai';
import {suite, test} from 'mocha';
import {Tree, typeForTree, newListOfTree} from './gen/struct_recursive.noms.js';
import {Tree, newListOfTree} from './gen/struct_recursive.noms.js';
import {newList, makeListType} from '@attic/noms';
suite('struct_recursive.noms', () => {
test('constructor', async () => {
const listOfTreeType = makeListType(typeForTree);
const t: Tree = new Tree({children: await newList([
new Tree({children: await newList([], listOfTreeType)}),
new Tree({children: await newList([], listOfTreeType)}),
], listOfTreeType)});
assert.equal(t.children.length, 2);
const t2: Tree = new Tree({children: await newListOfTree([
const t: Tree = new Tree({children: await newListOfTree([
new Tree({children: await newListOfTree([])}),
new Tree({children: await newListOfTree([])}),
])});
assert.equal(t.children.length, 2);
const listOfTreeType = makeListType(t.type);
const t2: Tree = new Tree({children: await newList([
new Tree({children: await newList([], listOfTreeType)}),
new Tree({children: await newList([], listOfTreeType)}),
], listOfTreeType)});
assert.isTrue(t.equals(t2));
});
});

View File

@@ -19,22 +19,30 @@ import type {
const _pkg = new _Package([
_makeStructType('S',
[
new _Field('s', _stringType, false),
new _Field('b', _boolType, false),
],
[
[
new _Field('s', _stringType, false),
new _Field('b', _boolType, false),
],
[
]
),
]
),
_makeEnumType('E', 'e1', 'e2', 'e3'),
], [
]);
_registerPackage(_pkg);
export const typeForS = _makeType(_pkg.ref, 0);
const S$typeDef = _pkg.types[0];
export const typeForE = _makeType(_pkg.ref, 1);
const E$typeDef = _pkg.types[1];
const S$type = _makeType(_pkg.ref, 0);
const S$typeDef = _makeStructType('S',
[
new _Field('s', _stringType, false),
new _Field('b', _boolType, false),
],
[
]
);
const E$type = _makeType(_pkg.ref, 1);
const E$typeDef = _makeEnumType('E', 'e1', 'e2', 'e3');
type S$Data = {
@@ -50,7 +58,7 @@ interface S$Interface extends _Struct {
setB(value: boolean): S$Interface;
}
export const S: Class<S$Interface> = _createStructClass(typeForS, S$typeDef);
export const S: Class<S$Interface> = _createStructClass(S$type, S$typeDef);
export type E =
0 | // e1