@platform/cell.typesystem
Version:
The 'strongly typed sheets' system of the CellOS.
23 lines (22 loc) • 763 B
JavaScript
import { Uri } from '../common';
import { TypeBuilderType } from './TypeBuilderType';
export class TypeBuilderNs {
constructor(args) {
this.types = [];
this.uri = Uri.ns(args.uri);
}
type(typename, options = {}) {
const { startColumn } = options;
const uri = this.uri;
typename = (typename || '').trim();
const exists = this.types.some(item => item.typename === typename);
if (exists) {
const err = `The typename '${typename}' already exists`;
throw new Error(err);
}
const type = TypeBuilderType.create({ uri, typename, startColumn });
this.types.push(type);
return type;
}
}
TypeBuilderNs.create = (args) => new TypeBuilderNs(args);