updates tests and method names to getNewModelTemplate method

This commit is contained in:
kevmodrome 2020-04-14 10:49:10 +02:00
parent fb74982055
commit b8a652e2ca
14 changed files with 77 additions and 77 deletions

View File

@ -115,7 +115,7 @@ export const newModel = (store, useRoot) => () => {
? shadowHierarchy ? shadowHierarchy
: getNode(shadowHierarchy, state.currentNode.nodeId) : getNode(shadowHierarchy, state.currentNode.nodeId)
state.errors = [] state.errors = []
state.currentNode = templateApi(shadowHierarchy).getNewRecordTemplate( state.currentNode = templateApi(shadowHierarchy).getNewModelTemplate(
parent, parent,
"", "",
true true

View File

@ -165,7 +165,7 @@ export const getNewRootLevel = () =>
nodeId: 0, nodeId: 0,
}) })
const _getNewRecordTemplate = (parent, name, createDefaultIndex, isSingle) => { const _getNewModelTemplate = (parent, name, createDefaultIndex, isSingle) => {
const nodeId = getNodeId(parent) const nodeId = getNodeId(parent)
const node = constructNode(parent, { const node = constructNode(parent, {
name, name,
@ -189,14 +189,14 @@ const _getNewRecordTemplate = (parent, name, createDefaultIndex, isSingle) => {
return node return node
} }
export const getNewRecordTemplate = ( export const getNewModelTemplate = (
parent, parent,
name = "", name = "",
createDefaultIndex = true createDefaultIndex = true
) => _getNewRecordTemplate(parent, name, createDefaultIndex, false) ) => _getNewModelTemplate(parent, name, createDefaultIndex, false)
export const getNewSingleRecordTemplate = parent => export const getNewSingleRecordTemplate = parent =>
_getNewRecordTemplate(parent, "", false, true) _getNewModelTemplate(parent, "", false, true)
export const getNewIndexTemplate = (parent, type = "ancestor") => export const getNewIndexTemplate = (parent, type = "ancestor") =>
constructNode(parent, { constructNode(parent, {
@ -233,7 +233,7 @@ export const getNewAggregateTemplate = set => {
export default { export default {
getNewRootLevel, getNewRootLevel,
getNewRecordTemplate, getNewModelTemplate,
getNewIndexTemplate, getNewIndexTemplate,
createNodeErrors, createNodeErrors,
constructHierarchy, constructHierarchy,

View File

@ -1,6 +1,6 @@
import { import {
getNewRootLevel, getNewRootLevel,
getNewRecordTemplate, getNewModelTemplate,
getNewIndexTemplate, getNewIndexTemplate,
createNodeErrors, createNodeErrors,
constructHierarchy, constructHierarchy,
@ -38,7 +38,7 @@ const api = app => ({
getNewRootLevel, getNewRootLevel,
constructNode, constructNode,
getNewIndexTemplate, getNewIndexTemplate,
getNewRecordTemplate, getNewModelTemplate,
getNewField, getNewField,
validateField, validateField,
addField, addField,

View File

@ -76,7 +76,7 @@ const setup = includeFish => setupApphierarchy(createApp(includeFish))
const createApp = includeFish => templateApi => { const createApp = includeFish => templateApi => {
const root = templateApi.getNewRootLevel() const root = templateApi.getNewRootLevel()
const dogRecord = templateApi.getNewRecordTemplate(root, "dog") const dogRecord = templateApi.getNewModelTemplate(root, "dog")
const addField = recordNode => (name, type, typeOptions) => { const addField = recordNode => (name, type, typeOptions) => {
const field = templateApi.getNewField(type) const field = templateApi.getNewField(type)
@ -97,7 +97,7 @@ const createApp = includeFish => templateApi => {
let fishStuff = {} let fishStuff = {}
if (includeFish) { if (includeFish) {
const fishRecord = templateApi.getNewRecordTemplate(root, "fish") const fishRecord = templateApi.getNewModelTemplate(root, "fish")
const addFishField = addField(fishRecord) const addFishField = addField(fishRecord)
addFishField("name", "string") addFishField("name", "string")
addFishField("isAlive", "bool") addFishField("isAlive", "bool")

View File

@ -133,15 +133,15 @@ const setup = ({ parentCount, childCount, grandChildCount }) =>
return field return field
} }
const parent = templateApi.getNewRecordTemplate(root, "parent") const parent = templateApi.getNewModelTemplate(root, "parent")
parent.estimatedRecordCount = parentCount || 1000 parent.estimatedRecordCount = parentCount || 1000
parent.collectionName = "parents" parent.collectionName = "parents"
addField(parent) addField(parent)
const child = templateApi.getNewRecordTemplate(parent, "child") const child = templateApi.getNewModelTemplate(parent, "child")
child.estimatedRecordCount = childCount || 1000 child.estimatedRecordCount = childCount || 1000
child.collectionName = "children" child.collectionName = "children"
addField(child) addField(child)
const grandchild = templateApi.getNewRecordTemplate(child, "grandchild") const grandchild = templateApi.getNewModelTemplate(child, "grandchild")
grandchild.estimatedRecordCount = grandChildCount || 1000 grandchild.estimatedRecordCount = grandChildCount || 1000
grandchild.collectionName = "grandchildren" grandchild.collectionName = "grandchildren"
addField(grandchild) addField(grandchild)

View File

@ -42,7 +42,7 @@ export const getMemoryStore = () => setupDatastore(memory({}))
export const getMemoryTemplateApi = store => { export const getMemoryTemplateApi = store => {
const app = { const app = {
datastore: store || getMemoryStore(), datastore: store || getMemoryStore(),
publish: () => {}, publish: () => { },
getEpochTime: async () => new Date().getTime(), getEpochTime: async () => new Date().getTime(),
user: { name: "", permissions: [permission.writeTemplates.get()] }, user: { name: "", permissions: [permission.writeTemplates.get()] },
} }
@ -78,7 +78,7 @@ export const appFromTempalteApi = async (
const fullPermissions = generateFullPermissions(app) const fullPermissions = generateFullPermissions(app)
app.user.permissions = fullPermissions app.user.permissions = fullPermissions
if (disableCleanupTransactions) setCleanupFunc(app, async () => {}) if (disableCleanupTransactions) setCleanupFunc(app, async () => { })
else setCleanupFunc(app) else setCleanupFunc(app)
return app return app
@ -138,15 +138,15 @@ export const hierarchyFactory = (...additionalFeatures) => templateApi => {
const settingsRecord = templateApi.getNewSingleRecordTemplate(root) const settingsRecord = templateApi.getNewSingleRecordTemplate(root)
settingsRecord.name = "settings" settingsRecord.name = "settings"
const customerRecord = templateApi.getNewRecordTemplate(root, "customer") const customerRecord = templateApi.getNewModelTemplate(root, "customer")
customerRecord.collectionName = "customers" customerRecord.collectionName = "customers"
findCollectionDefaultIndex(customerRecord).map = findCollectionDefaultIndex(customerRecord).map =
"return {surname:record.surname, isalive:record.isalive, partner:record.partner};" "return {surname:record.surname, isalive:record.isalive, partner:record.partner};"
const partnerRecord = templateApi.getNewRecordTemplate(root, "partner") const partnerRecord = templateApi.getNewModelTemplate(root, "partner")
partnerRecord.collectionName = "partners" partnerRecord.collectionName = "partners"
const partnerInvoiceRecord = templateApi.getNewRecordTemplate( const partnerInvoiceRecord = templateApi.getNewModelTemplate(
partnerRecord, partnerRecord,
"invoice" "invoice"
) )
@ -154,7 +154,7 @@ export const hierarchyFactory = (...additionalFeatures) => templateApi => {
findCollectionDefaultIndex(partnerInvoiceRecord).name = findCollectionDefaultIndex(partnerInvoiceRecord).name =
"partnerInvoices_index" "partnerInvoices_index"
const invoiceRecord = templateApi.getNewRecordTemplate( const invoiceRecord = templateApi.getNewModelTemplate(
customerRecord, customerRecord,
"invoice" "invoice"
) )
@ -162,7 +162,7 @@ export const hierarchyFactory = (...additionalFeatures) => templateApi => {
findCollectionDefaultIndex(invoiceRecord).map = findCollectionDefaultIndex(invoiceRecord).map =
"return {createdDate: record.createdDate, totalIncVat: record.totalIncVat};" "return {createdDate: record.createdDate, totalIncVat: record.totalIncVat};"
const chargeRecord = templateApi.getNewRecordTemplate(invoiceRecord, "charge") const chargeRecord = templateApi.getNewModelTemplate(invoiceRecord, "charge")
chargeRecord.collectionName = "charges" chargeRecord.collectionName = "charges"
const hierarchy = { const hierarchy = {

View File

@ -16,10 +16,10 @@ describe("hierarchy node creation", () => {
expect(root.nodeName()).toBe("/") expect(root.nodeName()).toBe("/")
}) })
it("> getNewRecordTemplate > should be initialise with correct members", async () => { it("> getNewModelTemplate > should be initialise with correct members", async () => {
const { templateApi } = await getMemoryTemplateApi() const { templateApi } = await getMemoryTemplateApi()
const root = templateApi.getNewRootLevel() const root = templateApi.getNewRootLevel()
const record = templateApi.getNewRecordTemplate(root) const record = templateApi.getNewModelTemplate(root)
record.name = "child" record.name = "child"
expect(record.type).toBe("record") expect(record.type).toBe("record")
expect(record.children).toEqual([]) expect(record.children).toEqual([])
@ -45,7 +45,7 @@ describe("hierarchy node creation", () => {
expect(record.isSingle).toBe(true) expect(record.isSingle).toBe(true)
}) })
it("> getNewrecordTemplate > should have static pathRegx if is singlerecord", async () => { it("> getNewModelTemplate > should have static pathRegx if is singlerecord", async () => {
const { templateApi } = await getMemoryTemplateApi() const { templateApi } = await getMemoryTemplateApi()
const root = templateApi.getNewRootLevel() const root = templateApi.getNewRootLevel()
const record = templateApi.getNewSingleRecordTemplate(root) const record = templateApi.getNewSingleRecordTemplate(root)
@ -53,59 +53,59 @@ describe("hierarchy node creation", () => {
expect(record.pathRegx()).toBe("/child") expect(record.pathRegx()).toBe("/child")
}) })
it("> getNewrecordTemplate > should add itself to parent records's children", async () => { it("> getNewModelTemplate > should add itself to parent records's children", async () => {
const { templateApi } = await getMemoryTemplateApi() const { templateApi } = await getMemoryTemplateApi()
const root = templateApi.getNewRootLevel() const root = templateApi.getNewRootLevel()
const parentRecord = templateApi.getNewRecordTemplate(root) const parentRecord = templateApi.getNewModelTemplate(root)
const record = templateApi.getNewRecordTemplate(parentRecord) const record = templateApi.getNewModelTemplate(parentRecord)
expect(parentRecord.children.length).toBe(1) expect(parentRecord.children.length).toBe(1)
expect(parentRecord.children[0]).toBe(record) expect(parentRecord.children[0]).toBe(record)
}) })
it("> getNewrecordTemplate > child should get correct nodeName ", async () => { it("> getNewModelTemplate > child should get correct nodeName ", async () => {
const { templateApi } = await getMemoryTemplateApi() const { templateApi } = await getMemoryTemplateApi()
const root = templateApi.getNewRootLevel() const root = templateApi.getNewRootLevel()
const parentRecord = templateApi.getNewRecordTemplate(root) const parentRecord = templateApi.getNewModelTemplate(root)
parentRecord.name = "parent" parentRecord.name = "parent"
const record = templateApi.getNewRecordTemplate(parentRecord) const record = templateApi.getNewModelTemplate(parentRecord)
record.name = "child" record.name = "child"
expect(record.nodeName()).toBe(`/${parentRecord.name}/${record.name}`) expect(record.nodeName()).toBe(`/${parentRecord.name}/${record.name}`)
}) })
it("> getNewrecordTemplate > should add itself to parents's default index allowedNodeIds", async () => { it("> getNewModelTemplate > should add itself to parents's default index allowedNodeIds", async () => {
const { templateApi } = await getMemoryTemplateApi() const { templateApi } = await getMemoryTemplateApi()
const root = templateApi.getNewRootLevel() const root = templateApi.getNewRootLevel()
const parentRecord = templateApi.getNewRecordTemplate(root) const parentRecord = templateApi.getNewModelTemplate(root)
const record = templateApi.getNewRecordTemplate(parentRecord) const record = templateApi.getNewModelTemplate(parentRecord)
expect(root.indexes[0].allowedRecordNodeIds).toEqual([parentRecord.nodeId]) expect(root.indexes[0].allowedRecordNodeIds).toEqual([parentRecord.nodeId])
expect(parentRecord.indexes[0].allowedRecordNodeIds).toEqual([ expect(parentRecord.indexes[0].allowedRecordNodeIds).toEqual([
record.nodeId, record.nodeId,
]) ])
}) })
it("> getNewrecordTemplate > should add itself to root's children", async () => { it("> getNewModelTemplate > should add itself to root's children", async () => {
const { templateApi } = await getMemoryTemplateApi() const { templateApi } = await getMemoryTemplateApi()
const root = templateApi.getNewRootLevel() const root = templateApi.getNewRootLevel()
const record = templateApi.getNewRecordTemplate(root) const record = templateApi.getNewModelTemplate(root)
expect(root.children.length).toBe(1) expect(root.children.length).toBe(1)
expect(root.children[0]).toBe(record) expect(root.children[0]).toBe(record)
}) })
it("> getNewrecordTemplate > should have dynamic pathRegx if parent is record", async () => { it("> getNewModelTemplate > should have dynamic pathRegx if parent is record", async () => {
const { templateApi } = await getMemoryTemplateApi() const { templateApi } = await getMemoryTemplateApi()
const root = templateApi.getNewRootLevel() const root = templateApi.getNewRootLevel()
const parent = templateApi.getNewRecordTemplate(root) const parent = templateApi.getNewModelTemplate(root)
parent.collectionName = "customers" parent.collectionName = "customers"
const record = templateApi.getNewRecordTemplate(parent) const record = templateApi.getNewModelTemplate(parent)
record.name = "child" record.name = "child"
expect(record.pathRegx().startsWith("/customers")).toBe(true) expect(record.pathRegx().startsWith("/customers")).toBe(true)
expect(record.pathRegx().includes("[")).toBe(true) expect(record.pathRegx().includes("[")).toBe(true)
}) })
it("> getNewrecordTemplate > should add default index", async () => { it("> getNewModelTemplate > should add default index", async () => {
const { templateApi } = await getMemoryTemplateApi() const { templateApi } = await getMemoryTemplateApi()
const root = templateApi.getNewRootLevel() const root = templateApi.getNewRootLevel()
const record = templateApi.getNewRecordTemplate(root, "rec") const record = templateApi.getNewModelTemplate(root, "rec")
expect(root.indexes.length).toBe(1) expect(root.indexes.length).toBe(1)
expect(root.indexes[0].name).toBe("rec_index") expect(root.indexes[0].name).toBe("rec_index")
}) })
@ -138,7 +138,7 @@ describe("hierarchy node creation", () => {
it("> getNewIndexTemplate > should add itself to record indexes", async () => { it("> getNewIndexTemplate > should add itself to record indexes", async () => {
const { templateApi } = await getMemoryTemplateApi() const { templateApi } = await getMemoryTemplateApi()
const root = templateApi.getNewRootLevel() const root = templateApi.getNewRootLevel()
const record = templateApi.getNewRecordTemplate(root) const record = templateApi.getNewModelTemplate(root)
const index = templateApi.getNewIndexTemplate(record) const index = templateApi.getNewIndexTemplate(record)
expect(record.indexes.length).toBe(1) expect(record.indexes.length).toBe(1)
expect(record.indexes[0]).toBe(index) expect(record.indexes[0]).toBe(index)
@ -150,7 +150,7 @@ describe("hierarchy node creation", () => {
expect(() => templateApi.getNewIndexTemplate()).toThrow( expect(() => templateApi.getNewIndexTemplate()).toThrow(
errors.allNonRootNodesMustHaveParent errors.allNonRootNodesMustHaveParent
) )
expect(() => templateApi.getNewRecordTemplate()).toThrow( expect(() => templateApi.getNewModelTemplate()).toThrow(
errors.allNonRootNodesMustHaveParent errors.allNonRootNodesMustHaveParent
) )
}) })
@ -158,8 +158,8 @@ describe("hierarchy node creation", () => {
it("> adding node > should just add one (bugfix)", async () => { it("> adding node > should just add one (bugfix)", async () => {
const { templateApi } = await getMemoryTemplateApi() const { templateApi } = await getMemoryTemplateApi()
const root = templateApi.getNewRootLevel() const root = templateApi.getNewRootLevel()
const parent = templateApi.getNewRecordTemplate(root) const parent = templateApi.getNewModelTemplate(root)
templateApi.getNewRecordTemplate(parent) templateApi.getNewModelTemplate(parent)
expect(root.children.length).toBe(1) expect(root.children.length).toBe(1)
expect(parent.children.length).toBe(1) expect(parent.children.length).toBe(1)
@ -174,7 +174,7 @@ describe("hierarchy node creation", () => {
it("> getNewAggregateGroupTemplate > should add itself to index aggregateGroups", async () => { it("> getNewAggregateGroupTemplate > should add itself to index aggregateGroups", async () => {
const { templateApi } = await getMemoryTemplateApi() const { templateApi } = await getMemoryTemplateApi()
const root = templateApi.getNewRootLevel() const root = templateApi.getNewRootLevel()
const record = templateApi.getNewRecordTemplate(root) const record = templateApi.getNewModelTemplate(root)
const index = templateApi.getNewIndexTemplate(record) const index = templateApi.getNewIndexTemplate(record)
const aggregateGroup = templateApi.getNewAggregateGroupTemplate(index) const aggregateGroup = templateApi.getNewAggregateGroupTemplate(index)
expect(index.aggregateGroups.length).toBe(1) expect(index.aggregateGroups.length).toBe(1)

View File

@ -13,7 +13,7 @@ describe("diffHierarchy", () => {
it("should detect root record created", async () => { it("should detect root record created", async () => {
const oldHierarchy = (await setup()).root; const oldHierarchy = (await setup()).root;
const newSetup = await setup() const newSetup = await setup()
const opportunity = newSetup.templateApi.getNewRecordTemplate(newSetup.root, "opportunity", false) const opportunity = newSetup.templateApi.getNewModelTemplate(newSetup.root, "opportunity", false)
const diff = diffHierarchy(oldHierarchy, newSetup.root) const diff = diffHierarchy(oldHierarchy, newSetup.root)
expect(diff).toEqual([{ expect(diff).toEqual([{
newNode: opportunity, newNode: opportunity,
@ -25,8 +25,8 @@ describe("diffHierarchy", () => {
it("should only detect root record, when newly created root record has children ", async () => { it("should only detect root record, when newly created root record has children ", async () => {
const oldHierarchy = (await setup()).root; const oldHierarchy = (await setup()).root;
const newSetup = await setup() const newSetup = await setup()
const opportunity = newSetup.templateApi.getNewRecordTemplate(newSetup.root, "opportunity", false) const opportunity = newSetup.templateApi.getNewModelTemplate(newSetup.root, "opportunity", false)
newSetup.templateApi.getNewRecordTemplate(opportunity, "invoice", true) newSetup.templateApi.getNewModelTemplate(opportunity, "invoice", true)
const diff = diffHierarchy(oldHierarchy, newSetup.root) const diff = diffHierarchy(oldHierarchy, newSetup.root)
expect(diff).toEqual([{ expect(diff).toEqual([{
newNode: opportunity, newNode: opportunity,
@ -38,7 +38,7 @@ describe("diffHierarchy", () => {
it("should detect child record created", async () => { it("should detect child record created", async () => {
const oldHierarchy = (await setup()).root; const oldHierarchy = (await setup()).root;
const newSetup = await setup() const newSetup = await setup()
const opportunity = newSetup.templateApi.getNewRecordTemplate(newSetup.contact, "opportunity", false) const opportunity = newSetup.templateApi.getNewModelTemplate(newSetup.contact, "opportunity", false)
const diff = diffHierarchy(oldHierarchy, newSetup.root) const diff = diffHierarchy(oldHierarchy, newSetup.root)
expect(diff).toEqual([{ expect(diff).toEqual([{
newNode: opportunity, newNode: opportunity,

View File

@ -3,7 +3,7 @@ import { getMemoryTemplateApi } from "./specHelpers"
import { fieldErrors } from "../src/templateApi/fields" import { fieldErrors } from "../src/templateApi/fields"
const getRecordTemplate = templateApi => const getRecordTemplate = templateApi =>
$(templateApi.getNewRootLevel(), [templateApi.getNewRecordTemplate]) $(templateApi.getNewRootLevel(), [templateApi.getNewModelTemplate])
const getValidField = templateApi => { const getValidField = templateApi => {
const field = templateApi.getNewField("string") const field = templateApi.getNewField("string")

View File

@ -13,7 +13,7 @@ import { findCollectionDefaultIndex } from "./specHelpers"
const createValidHierarchy = () => { const createValidHierarchy = () => {
const root = createNodes.getNewRootLevel() const root = createNodes.getNewRootLevel()
const customerRecord = createNodes.getNewRecordTemplate(root, "customer") const customerRecord = createNodes.getNewModelTemplate(root, "customer")
customerRecord.collectionName = "customers" customerRecord.collectionName = "customers"
const customersDefaultIndex = findCollectionDefaultIndex(customerRecord) const customersDefaultIndex = findCollectionDefaultIndex(customerRecord)
@ -27,7 +27,7 @@ const createValidHierarchy = () => {
allCustomersOwedFunctions.aggregatedValue = "return record.owed" allCustomersOwedFunctions.aggregatedValue = "return record.owed"
allCustomersOwedFunctions.name = "all customers owed amount" allCustomersOwedFunctions.name = "all customers owed amount"
const partnerRecord = createNodes.getNewRecordTemplate(root, "partner") const partnerRecord = createNodes.getNewModelTemplate(root, "partner")
partnerRecord.collectionName = "partners" partnerRecord.collectionName = "partners"
partnerRecord.name = "partner" partnerRecord.name = "partner"
const businessName = getNewField("string") const businessName = getNewField("string")

View File

@ -3,7 +3,7 @@ import { permission } from "../src/authApi/permissions"
const saveThreeLevelHierarchy = async () => { const saveThreeLevelHierarchy = async () => {
const { templateApi, app } = await getMemoryTemplateApi() const { templateApi, app } = await getMemoryTemplateApi()
const root = templateApi.getNewRootLevel() const root = templateApi.getNewRootLevel()
const record = templateApi.getNewRecordTemplate(root) const record = templateApi.getNewModelTemplate(root)
record.name = "customer" record.name = "customer"
const surname = templateApi.getNewField("string") const surname = templateApi.getNewField("string")
surname.name = "surname" surname.name = "surname"

View File

@ -166,7 +166,7 @@ describe("upgradeData", () => {
leadField.name = "lead" leadField.name = "lead"
leadField.type = "reference" leadField.type = "reference"
leadField.typeOptions = { leadField.typeOptions = {
reverseIndexNodeKeys: [ newIndex.nodeKey() ], reverseIndexNodeKeys: [newIndex.nodeKey()],
indexNodeKey: "/lead_index", indexNodeKey: "/lead_index",
displayValue: "name" displayValue: "name"
} }
@ -194,7 +194,7 @@ describe("upgradeData", () => {
it("should initialise a new root record", async () => { it("should initialise a new root record", async () => {
const { oldSetup, newSetup } = await configure() const { oldSetup, newSetup } = await configure()
const invoice = newSetup.templateApi.getNewRecordTemplate(newSetup.root, "invoice", true) const invoice = newSetup.templateApi.getNewModelTemplate(newSetup.root, "invoice", true)
invoice.collectionName = "invoices" invoice.collectionName = "invoices"
const nameField = newSetup.templateApi.getNewField("string") const nameField = newSetup.templateApi.getNewField("string")
@ -217,7 +217,7 @@ describe("upgradeData", () => {
it("should initialise a new child record", async () => { it("should initialise a new child record", async () => {
const { oldSetup, newSetup, records } = await configure() const { oldSetup, newSetup, records } = await configure()
const invoice = newSetup.templateApi.getNewRecordTemplate(newSetup.contact, "invoice", true) const invoice = newSetup.templateApi.getNewModelTemplate(newSetup.contact, "invoice", true)
invoice.collectionName = "invoices" invoice.collectionName = "invoices"
const nameField = newSetup.templateApi.getNewField("string") const nameField = newSetup.templateApi.getNewField("string")

View File

@ -5,7 +5,7 @@ import { initialiseData } from "../src/appInitialise/initialiseData"
export const setup = async store => { export const setup = async store => {
const { templateApi } = await getMemoryTemplateApi(store) const { templateApi } = await getMemoryTemplateApi(store)
const root = templateApi.getNewRootLevel() const root = templateApi.getNewRootLevel()
const contact = templateApi.getNewRecordTemplate(root, "contact", true) const contact = templateApi.getNewModelTemplate(root, "contact", true)
contact.collectionName = "contacts" contact.collectionName = "contacts"
const nameField = templateApi.getNewField("string") const nameField = templateApi.getNewField("string")
@ -16,9 +16,9 @@ export const setup = async store => {
templateApi.addField(contact, nameField) templateApi.addField(contact, nameField)
templateApi.addField(contact, statusField) templateApi.addField(contact, statusField)
const lead = templateApi.getNewRecordTemplate(root, "lead", true) const lead = templateApi.getNewModelTemplate(root, "lead", true)
lead.collectionName = "leads" lead.collectionName = "leads"
const deal = templateApi.getNewRecordTemplate(contact, "deal", true) const deal = templateApi.getNewModelTemplate(contact, "deal", true)
deal.collectionName = "deals" deal.collectionName = "deals"
templateApi.addField(deal, { ...nameField }) templateApi.addField(deal, { ...nameField })

View File

@ -20,7 +20,7 @@ export default async datastore => {
const clients = templateApi.getNewCollectionTemplate(root) const clients = templateApi.getNewCollectionTemplate(root)
clients.name = "clients" clients.name = "clients"
const client = templateApi.getNewRecordTemplate(clients) const client = templateApi.getNewModelTemplate(clients)
client.name = "client" client.name = "client"
addStringField(client, "FamilyName") addStringField(client, "FamilyName")
addStringField(client, "Address1") addStringField(client, "Address1")
@ -33,7 +33,7 @@ export default async datastore => {
const children = templateApi.getNewCollectionTemplate(client) const children = templateApi.getNewCollectionTemplate(client)
children.name = "children" children.name = "children"
const child = templateApi.getNewRecordTemplate(children) const child = templateApi.getNewModelTemplate(children)
child.name = "child" child.name = "child"
addStringField(child, "FirstName") addStringField(child, "FirstName")
addStringField(child, "Surname") addStringField(child, "Surname")
@ -43,7 +43,7 @@ export default async datastore => {
const contacts = templateApi.getNewCollectionTemplate(client) const contacts = templateApi.getNewCollectionTemplate(client)
contacts.name = "contacts" contacts.name = "contacts"
const contact = templateApi.getNewRecordTemplate(contacts) const contact = templateApi.getNewModelTemplate(contacts)
contact.name = "contact" contact.name = "contact"
addStringField(contact, "Name") addStringField(contact, "Name")
addStringField(contact, "relationship") addStringField(contact, "relationship")