MCPcopy Create free account
hub / github.com/dadi/api / addFromSeed

Method addFromSeed

dadi/lib/model/schemaStore.js:92–164  ·  view source on GitHub ↗
({
    fields,
    name,
    property,
    settings,
    timestamp = Date.now()
  })

Source from the content-addressed store, hash-verified

90 }
91
92 async addFromSeed({
93 fields,
94 name,
95 property,
96 settings,
97 timestamp = Date.now()
98 }) {
99 const database = await this.connection
100 const {results: existingSchemas} = await this.find({
101 name,
102 property
103 })
104 const newSchema = {
105 name,
106 fields,
107 property,
108 settings,
109 timestamp
110 }
111
112 if (existingSchemas.length > 0) {
113 const existing = existingSchemas[0]
114
115 if (existing.timestamp >= timestamp) {
116 return {
117 existing
118 }
119 }
120
121 await database.update({
122 collection: config.get('schemas.collection'),
123 query: {
124 _id: existing._id
125 },
126 update: {
127 $set: newSchema
128 }
129 })
130
131 // Reloading the model after update.
132 Model({
133 isListable: true,
134 name,
135 property,
136 schema: fields,
137 settings
138 })
139
140 return {
141 created: true,
142 existing
143 }
144 }
145
146 const insertedDocuments = await database.insert({
147 collection: config.get('schemas.collection'),
148 data: newSchema
149 })

Callers 1

index.jsFile · 0.80

Calls 3

findMethod · 0.95
ModelFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected