@seedprotocol/sdk 0.4.4 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -348
- package/dist/{ArweaveClient-DkNLWiSZ.js → ArweaveClient-CgWK-JgT.js} +8 -8
- package/dist/{ArweaveClient-DkNLWiSZ.js.map → ArweaveClient-CgWK-JgT.js.map} +1 -1
- package/dist/{ArweaveClient-CczHvccG.js → ArweaveClient-WcG8CZAE.js} +8 -8
- package/dist/{ArweaveClient-CczHvccG.js.map → ArweaveClient-WcG8CZAE.js.map} +1 -1
- package/dist/{Db-DJvjXVlp.js → Db-DjFdIdR9.js} +9 -9
- package/dist/{Db-DJvjXVlp.js.map → Db-DjFdIdR9.js.map} +1 -1
- package/dist/{Db-BzQR2KX9.js → Db-DjofXdeU.js} +9 -9
- package/dist/{Db-BzQR2KX9.js.map → Db-DjofXdeU.js.map} +1 -1
- package/dist/{EasClient-CHQYmjj2.js → EasClient-Aojewp6P.js} +8 -8
- package/dist/{EasClient-CodrIgW-.js.map → EasClient-Aojewp6P.js.map} +1 -1
- package/dist/{EasClient-CodrIgW-.js → EasClient-BVFXp2O6.js} +8 -8
- package/dist/{EasClient-CHQYmjj2.js.map → EasClient-BVFXp2O6.js.map} +1 -1
- package/dist/{FileManager-BbvkZJCH.js → FileManager-C9zr4AJe.js} +8 -8
- package/dist/{FileManager-BbvkZJCH.js.map → FileManager-C9zr4AJe.js.map} +1 -1
- package/dist/{FileManager-BIVsDnMu.js → FileManager-CxGJLw5C.js} +8 -8
- package/dist/{FileManager-BIVsDnMu.js.map → FileManager-CxGJLw5C.js.map} +1 -1
- package/dist/Item/Item.d.ts.map +1 -1
- package/dist/ItemProperty/ItemProperty.d.ts.map +1 -1
- package/dist/Model/Model.d.ts.map +1 -1
- package/dist/ModelProperty/ModelProperty.d.ts.map +1 -1
- package/dist/ModelProperty/service/actors/compareAndMarkDraft.d.ts.map +1 -1
- package/dist/ModelProperty/service/actors/saveToSchema.d.ts.map +1 -1
- package/dist/{ModelProperty-gjcA83Mq.js → ModelProperty-CGdkocQ8.js} +31 -766
- package/dist/ModelProperty-CGdkocQ8.js.map +1 -0
- package/dist/{PathResolver-kGzba-zC.js → PathResolver-CX6GHoTS.js} +8 -8
- package/dist/{PathResolver-kGzba-zC.js.map → PathResolver-CX6GHoTS.js.map} +1 -1
- package/dist/{PathResolver-9zAzPhee.js → PathResolver-z_WX47_o.js} +8 -8
- package/dist/{PathResolver-9zAzPhee.js.map → PathResolver-z_WX47_o.js.map} +1 -1
- package/dist/{QueryClient-C7ZkTT0z.js → QueryClient-ByKPdRmE.js} +8 -8
- package/dist/{QueryClient-C7ZkTT0z.js.map → QueryClient-ByKPdRmE.js.map} +1 -1
- package/dist/{QueryClient-CEtsek7Q.js → QueryClient-Cb1iJO-x.js} +8 -8
- package/dist/{QueryClient-CEtsek7Q.js.map → QueryClient-Cb1iJO-x.js.map} +1 -1
- package/dist/Schema/Schema.d.ts.map +1 -1
- package/dist/Schema/service/actors/writePropertiesToDb.d.ts.map +1 -1
- package/dist/Schema/service/addModelsMachine.d.ts.map +1 -1
- package/dist/{Schema-ClTcpgbt.js → Schema-D1eqDHyt.js} +758 -60
- package/dist/Schema-D1eqDHyt.js.map +1 -0
- package/dist/{SchemaValidationService-BfoEiHNr.js → SchemaValidationService-DyttFaV_.js} +7 -7
- package/dist/{SchemaValidationService-BfoEiHNr.js.map → SchemaValidationService-DyttFaV_.js.map} +1 -1
- package/dist/cjs/{ModelProperty-BRKRREYP.js → ModelProperty-BeJvgKMw.js} +62 -436
- package/dist/cjs/ModelProperty-BeJvgKMw.js.map +1 -0
- package/dist/cjs/{Schema-CV9hMg8m.js → Schema-CVs9J6eP.js} +426 -91
- package/dist/cjs/Schema-CVs9J6eP.js.map +1 -0
- package/dist/cjs/{SchemaValidationService-DUtQUerg.js → SchemaValidationService-CDKcVRFQ.js} +3 -3
- package/dist/cjs/{SchemaValidationService-DUtQUerg.js.map → SchemaValidationService-CDKcVRFQ.js.map} +1 -1
- package/dist/cjs/{getItem-BThT-UOt.js → getItem-B5RYPvrG.js} +3 -3
- package/dist/cjs/{getItem-BThT-UOt.js.map → getItem-B5RYPvrG.js.map} +1 -1
- package/dist/cjs/{getPublishPayload-CKZ7rVbU.js → getPublishPayload-BD1qRob1.js} +6 -6
- package/dist/cjs/getPublishPayload-BD1qRob1.js.map +1 -0
- package/dist/cjs/{getPublishUploads-CuGIvV-Q.js → getPublishUploads-CnC9aYxs.js} +4 -4
- package/dist/cjs/{getPublishUploads-CuGIvV-Q.js.map → getPublishUploads-CnC9aYxs.js.map} +1 -1
- package/dist/cjs/{getSegmentedItemProperties-BCJXJlTR.js → getSegmentedItemProperties-B_njnntx.js} +2 -2
- package/dist/cjs/{getSegmentedItemProperties-BCJXJlTR.js.map → getSegmentedItemProperties-B_njnntx.js.map} +1 -1
- package/dist/cjs/{index-C3j3m34a.js → index-BeKPbbk0.js} +11466 -11546
- package/dist/cjs/index-BeKPbbk0.js.map +1 -0
- package/dist/cjs/{index-CbTBDqTJ.js → index-Dnywap_P.js} +3 -3
- package/dist/cjs/index-Dnywap_P.js.map +1 -0
- package/dist/client/actors/platformClassesInit.d.ts.map +1 -1
- package/dist/client/actors/saveAppState.d.ts.map +1 -1
- package/dist/eas.d.ts.map +1 -1
- package/dist/{getItem-BWPo8wd0.js → getItem-BB5HBCbK.js} +8 -8
- package/dist/{getItem-BWPo8wd0.js.map → getItem-BB5HBCbK.js.map} +1 -1
- package/dist/{getPublishPayload-Caw2laZM.js → getPublishPayload-uLm0AqN_.js} +10 -10
- package/dist/getPublishPayload-uLm0AqN_.js.map +1 -0
- package/dist/{getPublishUploads-MlyBuoXh.js → getPublishUploads-Dc-HqhO8.js} +9 -9
- package/dist/{getPublishUploads-MlyBuoXh.js.map → getPublishUploads-Dc-HqhO8.js.map} +1 -1
- package/dist/{getSegmentedItemProperties-COLLdDo4.js → getSegmentedItemProperties-BrIqFNfD.js} +2 -2
- package/dist/{getSegmentedItemProperties-COLLdDo4.js.map → getSegmentedItemProperties-BrIqFNfD.js.map} +1 -1
- package/dist/helpers/schema.d.ts.map +1 -1
- package/dist/helpers/updateSchema.d.ts.map +1 -1
- package/dist/imports/json.d.ts.map +1 -1
- package/dist/{index-D2OGsG4v.js → index-2FcQHgKp.js} +2 -2
- package/dist/index-2FcQHgKp.js.map +1 -0
- package/dist/{ClientManager-DoHUt8tU.js → index-DPll6EAp.js} +11460 -11538
- package/dist/index-DPll6EAp.js.map +1 -0
- package/dist/{index-B9i_mXXp.js → index-LEY0Og1p.js} +9 -9
- package/dist/index-LEY0Og1p.js.map +1 -0
- package/dist/main.cjs +2 -2
- package/dist/main.js +13 -13
- package/dist/main.js.map +1 -1
- package/dist/node.js +15 -15
- package/dist/{property-fK7tSUDX.js → property-B15X7jLX.js} +4 -4
- package/dist/property-B15X7jLX.js.map +1 -0
- package/dist/{queries-DGOk16cd.js → queries-BPDSpiEX.js} +2 -2
- package/dist/{queries-DGOk16cd.js.map → queries-BPDSpiEX.js.map} +1 -1
- package/dist/services/write/actors/writeToDatabase.d.ts.map +1 -1
- package/package.json +6 -2
- package/dist/ClientManager-DoHUt8tU.js.map +0 -1
- package/dist/ModelProperty-gjcA83Mq.js.map +0 -1
- package/dist/Schema-ClTcpgbt.js.map +0 -1
- package/dist/cjs/ModelProperty-BRKRREYP.js.map +0 -1
- package/dist/cjs/Schema-CV9hMg8m.js.map +0 -1
- package/dist/cjs/getPublishPayload-CKZ7rVbU.js.map +0 -1
- package/dist/cjs/index-C3j3m34a.js.map +0 -1
- package/dist/cjs/index-CbTBDqTJ.js.map +0 -1
- package/dist/getPublishPayload-Caw2laZM.js.map +0 -1
- package/dist/index-B9i_mXXp.js.map +0 -1
- package/dist/index-D2OGsG4v.js.map +0 -1
- package/dist/property-fK7tSUDX.js.map +0 -1
|
@@ -1,390 +1,38 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var xstate = require('xstate');
|
|
4
|
-
var
|
|
5
|
-
require('
|
|
6
|
-
var drizzleOrm = require('drizzle-orm');
|
|
4
|
+
var Schema = require('./Schema-CVs9J6eP.js');
|
|
5
|
+
var main_cjs = require('./index-BeKPbbk0.js');
|
|
7
6
|
var debug = require('debug');
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
* @param schemaFileId - Schema file ID (required)
|
|
38
|
-
*/
|
|
39
|
-
const getSchemaFilePath = (name, version, schemaFileId) => {
|
|
40
|
-
const path = main_cjs.BaseFileManager.getPathModule();
|
|
41
|
-
const workingDir = main_cjs.BaseFileManager.getWorkingDir();
|
|
42
|
-
const sanitizedName = sanitizeSchemaName(name);
|
|
43
|
-
const filename = schemaFileId
|
|
44
|
-
? `${schemaFileId}_${sanitizedName}_v${version}.json`
|
|
45
|
-
: `${sanitizedName}_v${version}.json`;
|
|
46
|
-
return path.join(workingDir, filename);
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* Get schemaFileId from database for a schema
|
|
50
|
-
* @param schemaName - Schema name
|
|
51
|
-
* @returns Schema file ID
|
|
52
|
-
* @throws Error if schema not found or missing schemaFileId
|
|
53
|
-
*/
|
|
54
|
-
async function getSchemaFileId(schemaName) {
|
|
55
|
-
const { BaseDb } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.BaseDb$1; });
|
|
56
|
-
const db = BaseDb.getAppDb();
|
|
57
|
-
const { schemas } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.SchemaSchema; });
|
|
58
|
-
const { eq, desc } = await import('drizzle-orm');
|
|
59
|
-
const dbSchema = await db
|
|
60
|
-
.select()
|
|
61
|
-
.from(schemas)
|
|
62
|
-
.where(eq(schemas.name, schemaName))
|
|
63
|
-
.orderBy(desc(schemas.version))
|
|
64
|
-
.limit(1);
|
|
65
|
-
if (dbSchema.length === 0 || !dbSchema[0].schemaFileId) {
|
|
66
|
-
throw new Error(`Schema ${schemaName} not found in database or missing schemaFileId`);
|
|
67
|
-
}
|
|
68
|
-
return dbSchema[0].schemaFileId;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Write the full schema to a new version file (e.g. when new models were added).
|
|
72
|
-
* Used when _editedProperties contains 'schema:models' and there are no property-level updates.
|
|
73
|
-
* @param schemaName - Schema name
|
|
74
|
-
* @param schema - Full schema object (e.g. from _buildModelsFromInstances)
|
|
75
|
-
* @returns The file path of the new schema version
|
|
76
|
-
*/
|
|
77
|
-
async function writeFullSchemaNewVersion(schemaName, schema) {
|
|
78
|
-
const latestVersion = await main_cjs.getLatestSchemaVersion(schemaName);
|
|
79
|
-
const newVersion = latestVersion + 1;
|
|
80
|
-
const schemaWithNewVersion = {
|
|
81
|
-
...schema,
|
|
82
|
-
version: newVersion,
|
|
83
|
-
metadata: {
|
|
84
|
-
...schema.metadata,
|
|
85
|
-
updatedAt: new Date().toISOString(),
|
|
86
|
-
},
|
|
87
|
-
migrations: [
|
|
88
|
-
...(schema.migrations || []),
|
|
89
|
-
{
|
|
90
|
-
version: newVersion,
|
|
91
|
-
timestamp: new Date().toISOString(),
|
|
92
|
-
description: 'New schema version (e.g. new models added)',
|
|
93
|
-
changes: [{ type: 'full_schema_write' }],
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
};
|
|
97
|
-
const newFilePath = getSchemaFilePath(schemaName, newVersion, schema.id ?? (await getSchemaFileId(schemaName)));
|
|
98
|
-
const newContent = JSON.stringify(schemaWithNewVersion, null, 2);
|
|
99
|
-
await main_cjs.BaseFileManager.saveFile(newFilePath, newContent);
|
|
100
|
-
await main_cjs.BaseFileManager.waitForFileWithContent(newFilePath);
|
|
101
|
-
logger$4(`Created new schema version ${newVersion} for ${schemaName} at ${newFilePath}`);
|
|
102
|
-
return newFilePath;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Get model name from modelId
|
|
106
|
-
* @param modelId - The model ID to look up
|
|
107
|
-
* @returns The model name, or undefined if not found
|
|
108
|
-
*/
|
|
109
|
-
async function getModelNameFromId(modelId) {
|
|
110
|
-
if (!modelId) {
|
|
111
|
-
return undefined;
|
|
112
|
-
}
|
|
113
|
-
const db = main_cjs.BaseDb.getAppDb();
|
|
114
|
-
if (!db) {
|
|
115
|
-
throw new Error('Database not found');
|
|
116
|
-
}
|
|
117
|
-
const modelRecords = await db
|
|
118
|
-
.select()
|
|
119
|
-
.from(main_cjs.models)
|
|
120
|
-
.where(drizzleOrm.eq(main_cjs.models.id, modelId))
|
|
121
|
-
.limit(1);
|
|
122
|
-
if (modelRecords.length === 0) {
|
|
123
|
-
return undefined;
|
|
124
|
-
}
|
|
125
|
-
return modelRecords[0].name;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Convert a TProperty/ModelPropertyMachineContext to SchemaPropertyUpdate format
|
|
129
|
-
* This function converts the internal property representation to the schema file format
|
|
130
|
-
* @param property - The TProperty instance to convert
|
|
131
|
-
* @param modelName - The name of the model this property belongs to
|
|
132
|
-
* @param propertyName - The name of the property
|
|
133
|
-
* @returns A SchemaPropertyUpdate object ready to be passed to updateModelProperties
|
|
134
|
-
*/
|
|
135
|
-
async function convertPropertyToSchemaUpdate(property, modelName, propertyName) {
|
|
136
|
-
const updates = {};
|
|
137
|
-
// Convert dataType to type
|
|
138
|
-
if (property.dataType) {
|
|
139
|
-
updates.type = property.dataType;
|
|
140
|
-
}
|
|
141
|
-
// Handle Relation type
|
|
142
|
-
if (property.dataType === main_cjs.ModelPropertyDataTypes.Relation) {
|
|
143
|
-
if (property.ref) {
|
|
144
|
-
updates.model = property.ref;
|
|
145
|
-
}
|
|
146
|
-
else if (property.refModelId) {
|
|
147
|
-
// If ref is not set but refModelId is, get the model name from the database
|
|
148
|
-
const refModelName = await getModelNameFromId(property.refModelId);
|
|
149
|
-
if (refModelName) {
|
|
150
|
-
updates.model = refModelName;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
// Handle List type
|
|
155
|
-
if (property.dataType === main_cjs.ModelPropertyDataTypes.List) {
|
|
156
|
-
if (property.refValueType) {
|
|
157
|
-
updates.items = {
|
|
158
|
-
type: property.refValueType,
|
|
159
|
-
};
|
|
160
|
-
if (property.ref) {
|
|
161
|
-
updates.items.model = property.ref;
|
|
162
|
-
}
|
|
163
|
-
else if (property.refModelId) {
|
|
164
|
-
// If ref is not set but refModelId is, get the model name from the database
|
|
165
|
-
const refModelName = await getModelNameFromId(property.refModelId);
|
|
166
|
-
if (refModelName) {
|
|
167
|
-
updates.items.model = refModelName;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
// Handle storage configuration (for Text properties with storage)
|
|
173
|
-
if (property.storageType || property.localStorageDir || property.filenameSuffix) {
|
|
174
|
-
const storageType = property.storageType || 'ItemStorage'; // Default to ItemStorage if not specified
|
|
175
|
-
updates.storage = {
|
|
176
|
-
type: storageType,
|
|
177
|
-
};
|
|
178
|
-
if (property.localStorageDir) {
|
|
179
|
-
updates.storage.path = property.localStorageDir;
|
|
180
|
-
}
|
|
181
|
-
if (property.filenameSuffix) {
|
|
182
|
-
updates.storage.extension = property.filenameSuffix;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return {
|
|
186
|
-
modelName,
|
|
187
|
-
propertyName,
|
|
188
|
-
updates,
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Update model properties in a schema and create a new version
|
|
193
|
-
* @param schemaName - The name of the schema to update
|
|
194
|
-
* @param propertyUpdates - Array of property updates to apply
|
|
195
|
-
* @param modelUpdates - Optional array of model renames
|
|
196
|
-
* @returns The file path of the new schema version
|
|
197
|
-
* @throws Error if schema not found or updates are invalid
|
|
198
|
-
*/
|
|
199
|
-
async function updateModelProperties(schemaName, propertyUpdates, modelUpdates) {
|
|
200
|
-
// Get the latest version of the schema
|
|
201
|
-
const latestVersion = await main_cjs.getLatestSchemaVersion(schemaName);
|
|
202
|
-
if (latestVersion === 0) {
|
|
203
|
-
throw new Error(`Schema ${schemaName} not found`);
|
|
204
|
-
}
|
|
205
|
-
// Get schemaFileId from database
|
|
206
|
-
const schemaFileId = await getSchemaFileId(schemaName);
|
|
207
|
-
// Load the latest schema file
|
|
208
|
-
const latestFilePath = getSchemaFilePath(schemaName, latestVersion, schemaFileId);
|
|
209
|
-
const content = await main_cjs.BaseFileManager.readFileAsString(latestFilePath);
|
|
210
|
-
const schemaFile = JSON.parse(content);
|
|
211
|
-
if (!schemaFile.$schema) {
|
|
212
|
-
throw new Error(`Schema file ${latestFilePath} is not a complete schema file`);
|
|
213
|
-
}
|
|
214
|
-
// Create a copy of the schema for the new version
|
|
215
|
-
// Preserve schema ID and all model/property IDs
|
|
216
|
-
const newVersion = latestVersion + 1;
|
|
217
|
-
const updatedSchema = {
|
|
218
|
-
...schemaFile,
|
|
219
|
-
version: newVersion,
|
|
220
|
-
// Preserve schema ID from previous version
|
|
221
|
-
id: schemaFile.id,
|
|
222
|
-
metadata: {
|
|
223
|
-
...schemaFile.metadata,
|
|
224
|
-
updatedAt: new Date().toISOString(),
|
|
225
|
-
},
|
|
226
|
-
// Deep copy models to preserve IDs
|
|
227
|
-
models: Object.fromEntries(Object.entries(schemaFile.models).map(([modelName, model]) => [
|
|
228
|
-
modelName,
|
|
229
|
-
{
|
|
230
|
-
...model,
|
|
231
|
-
// Preserve model ID
|
|
232
|
-
id: model.id,
|
|
233
|
-
// Deep copy properties to preserve IDs
|
|
234
|
-
properties: Object.fromEntries(Object.entries(model.properties).map(([propName, prop]) => [
|
|
235
|
-
propName,
|
|
236
|
-
{
|
|
237
|
-
...prop,
|
|
238
|
-
// Preserve property ID
|
|
239
|
-
id: prop.id,
|
|
240
|
-
},
|
|
241
|
-
])),
|
|
242
|
-
},
|
|
243
|
-
])),
|
|
244
|
-
migrations: [
|
|
245
|
-
...schemaFile.migrations,
|
|
246
|
-
{
|
|
247
|
-
version: newVersion,
|
|
248
|
-
timestamp: new Date().toISOString(),
|
|
249
|
-
description: `Updated model properties: ${propertyUpdates.map(u => `${u.modelName}.${u.propertyName}`).join(', ')}`,
|
|
250
|
-
changes: propertyUpdates.map(update => ({
|
|
251
|
-
type: 'property_update',
|
|
252
|
-
modelName: update.modelName,
|
|
253
|
-
propertyName: update.propertyName,
|
|
254
|
-
updates: update.updates,
|
|
255
|
-
})),
|
|
256
|
-
},
|
|
257
|
-
],
|
|
258
|
-
};
|
|
259
|
-
// Apply property updates
|
|
260
|
-
for (const update of propertyUpdates) {
|
|
261
|
-
const model = updatedSchema.models[update.modelName];
|
|
262
|
-
if (!model) {
|
|
263
|
-
throw new Error(`Model ${update.modelName} not found in schema ${schemaName}`);
|
|
264
|
-
}
|
|
265
|
-
if (!model.properties[update.propertyName]) {
|
|
266
|
-
throw new Error(`Property ${update.propertyName} not found in model ${update.modelName} of schema ${schemaName}`);
|
|
267
|
-
}
|
|
268
|
-
// Update the property with new values
|
|
269
|
-
const property = model.properties[update.propertyName];
|
|
270
|
-
Object.assign(property, update.updates);
|
|
271
|
-
}
|
|
272
|
-
// Write the new schema version to file using ID-based naming (preferred)
|
|
273
|
-
const newFilePath = getSchemaFilePath(schemaName, newVersion, updatedSchema.id ?? undefined);
|
|
274
|
-
const newContent = JSON.stringify(updatedSchema, null, 2);
|
|
275
|
-
await main_cjs.BaseFileManager.saveFile(newFilePath, newContent);
|
|
276
|
-
// Wait for the file to be available with content (important for browser/OPFS where writes may not be immediately readable)
|
|
277
|
-
await main_cjs.BaseFileManager.waitForFileWithContent(newFilePath);
|
|
278
|
-
logger$4(`Created new schema version ${newVersion} for ${schemaName} at ${newFilePath}`);
|
|
279
|
-
// Load the new schema file to process models and add them to the database
|
|
280
|
-
// Extract model renames from migrations to pass to database update
|
|
281
|
-
const modelRenames = new Map();
|
|
282
|
-
const latestMigration = updatedSchema.migrations[updatedSchema.migrations.length - 1];
|
|
283
|
-
for (const change of latestMigration.changes) {
|
|
284
|
-
if (change.type === 'model_rename') {
|
|
285
|
-
modelRenames.set(change.oldName, change.newName);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
// Load schema with model renames handled
|
|
289
|
-
await loadSchemaWithRenames(newFilePath, modelRenames);
|
|
290
|
-
return newFilePath;
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Load a schema file and handle model renames in the database
|
|
294
|
-
* This is a helper function that processes model renames before loading
|
|
295
|
-
*/
|
|
296
|
-
async function loadSchemaWithRenames(schemaFilePath, modelRenames) {
|
|
297
|
-
const content = await main_cjs.BaseFileManager.readFileAsString(schemaFilePath);
|
|
298
|
-
const schemaFile = JSON.parse(content);
|
|
299
|
-
if (!schemaFile.$schema) {
|
|
300
|
-
throw new Error(`File ${schemaFilePath} is not a complete schema file (missing $schema field).`);
|
|
301
|
-
}
|
|
302
|
-
const schemaName = schemaFile.metadata?.name;
|
|
303
|
-
const version = schemaFile.version;
|
|
304
|
-
if (!schemaName) {
|
|
305
|
-
throw new Error('Schema name is required in metadata.name');
|
|
306
|
-
}
|
|
307
|
-
// Convert to JsonImportSchema format for processing
|
|
308
|
-
// Remove id fields for JsonImportSchema format (they're not part of the import format)
|
|
309
|
-
const importData = {
|
|
310
|
-
name: schemaName,
|
|
311
|
-
models: Object.fromEntries(Object.entries(schemaFile.models).map(([modelName, model]) => [
|
|
312
|
-
modelName,
|
|
313
|
-
{
|
|
314
|
-
description: model.description,
|
|
315
|
-
properties: Object.fromEntries(Object.entries(model.properties).map(([propName, prop]) => [
|
|
316
|
-
propName,
|
|
317
|
-
{
|
|
318
|
-
type: prop.type || 'string', // Ensure type is present
|
|
319
|
-
...prop,
|
|
320
|
-
// Remove id field for import format (not part of JsonImportSchema)
|
|
321
|
-
},
|
|
322
|
-
])),
|
|
323
|
-
indexes: model.indexes,
|
|
324
|
-
},
|
|
325
|
-
])),
|
|
326
|
-
};
|
|
327
|
-
// Generate schema ID if missing
|
|
328
|
-
if (!schemaFile.id) {
|
|
329
|
-
const { generateId } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.index; });
|
|
330
|
-
schemaFile.id = generateId();
|
|
331
|
-
logger$4('Generated schema ID for schema:', schemaFile.id);
|
|
332
|
-
}
|
|
333
|
-
// Extract schemaFileIds from JSON file and generate missing ones BEFORE creating models
|
|
334
|
-
// This ensures Model instances are created with correct IDs
|
|
335
|
-
const modelFileIds = new Map();
|
|
336
|
-
const propertyFileIds = new Map();
|
|
337
|
-
const { generateId } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.index; });
|
|
338
|
-
for (const [modelName, model] of Object.entries(schemaFile.models)) {
|
|
339
|
-
// Generate model ID if missing
|
|
340
|
-
if (!model.id) {
|
|
341
|
-
model.id = generateId();
|
|
342
|
-
logger$4(`Generated model ID for ${modelName}:`, model.id);
|
|
343
|
-
}
|
|
344
|
-
modelFileIds.set(modelName, model.id);
|
|
345
|
-
const propIds = new Map();
|
|
346
|
-
for (const [propName, prop] of Object.entries(model.properties)) {
|
|
347
|
-
// Generate property ID if missing
|
|
348
|
-
if (!prop.id) {
|
|
349
|
-
prop.id = generateId();
|
|
350
|
-
logger$4(`Generated property ID for ${modelName}.${propName}:`, prop.id);
|
|
351
|
-
}
|
|
352
|
-
propIds.set(propName, prop.id);
|
|
353
|
-
}
|
|
354
|
-
if (propIds.size > 0) {
|
|
355
|
-
propertyFileIds.set(modelName, propIds);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
// Convert JSON models to Model classes, passing modelFileIds and propertyFileIds so Model instances use correct IDs
|
|
359
|
-
const modelDefinitions = await main_cjs.createModelsFromJson(importData, modelFileIds, propertyFileIds);
|
|
360
|
-
// Convert schema file metadata to schema input for database
|
|
361
|
-
const schemaInput = {
|
|
362
|
-
name: schemaName,
|
|
363
|
-
version,
|
|
364
|
-
schemaFileId: schemaFile.id || null,
|
|
365
|
-
schemaData: null,
|
|
366
|
-
isDraft: false,
|
|
367
|
-
isEdited: false,
|
|
368
|
-
createdAt: new Date(schemaFile.metadata.createdAt).getTime(),
|
|
369
|
-
updatedAt: new Date(schemaFile.metadata.updatedAt).getTime(),
|
|
370
|
-
};
|
|
371
|
-
// Use dynamic import to break circular dependency
|
|
372
|
-
const { addSchemaToDb, addModelsToDb } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.db; });
|
|
373
|
-
// Add schema to database with schemaFileId
|
|
374
|
-
const schemaRecord = await addSchemaToDb(schemaInput, schemaFile.id);
|
|
375
|
-
// Add models to database with model renames handled and schemaFileIds
|
|
376
|
-
await addModelsToDb(modelDefinitions, schemaRecord, modelRenames, {
|
|
377
|
-
schemaFileId: schemaFile.id,
|
|
378
|
-
modelFileIds,
|
|
379
|
-
propertyFileIds,
|
|
380
|
-
});
|
|
381
|
-
// Models are now Model instances, no registration needed
|
|
382
|
-
// They should be created via Model.create() and are accessible via Model static methods
|
|
383
|
-
for (const [modelName] of Object.entries(modelDefinitions)) {
|
|
384
|
-
logger$4('loadSchemaWithRenames - model available:', modelName);
|
|
385
|
-
}
|
|
386
|
-
return schemaFilePath;
|
|
387
|
-
}
|
|
7
|
+
var drizzleOrm = require('drizzle-orm');
|
|
8
|
+
require('./SchemaValidationService-CDKcVRFQ.js');
|
|
9
|
+
require('@sinclair/typebox/value');
|
|
10
|
+
require('reflect-metadata');
|
|
11
|
+
require('pluralize');
|
|
12
|
+
require('@sinclair/typebox');
|
|
13
|
+
require('immer');
|
|
14
|
+
require('drizzle-orm/sqlite-core');
|
|
15
|
+
require('nanoid');
|
|
16
|
+
require('nanoid-dictionary');
|
|
17
|
+
require('ethers');
|
|
18
|
+
require('rxjs');
|
|
19
|
+
require('lodash-es');
|
|
20
|
+
require('drizzle-orm/casing');
|
|
21
|
+
require('eventemitter3');
|
|
22
|
+
require('arweave');
|
|
23
|
+
require('fs/promises');
|
|
24
|
+
require('fs');
|
|
25
|
+
require('path');
|
|
26
|
+
require('@libsql/client');
|
|
27
|
+
require('drizzle-orm/libsql');
|
|
28
|
+
require('drizzle-kit/api');
|
|
29
|
+
require('js-yaml');
|
|
30
|
+
require('ts-import');
|
|
31
|
+
require('glob');
|
|
32
|
+
require('rimraf');
|
|
33
|
+
require('child_process');
|
|
34
|
+
require('url');
|
|
35
|
+
require('graphql-request');
|
|
388
36
|
|
|
389
37
|
const logger$3 = debug('seedSdk:modelProperty:actors:saveToSchema');
|
|
390
38
|
/**
|
|
@@ -394,11 +42,11 @@ const logger$3 = debug('seedSdk:modelProperty:actors:saveToSchema');
|
|
|
394
42
|
*/
|
|
395
43
|
async function getSchemaNameFromModel(modelName) {
|
|
396
44
|
// Get the latest schema files and find which one contains this model
|
|
397
|
-
const { listLatestSchemaFiles } = await Promise.resolve().then(function () { return require('./index-
|
|
45
|
+
const { listLatestSchemaFiles } = await Promise.resolve().then(function () { return require('./index-BeKPbbk0.js'); }).then(function (n) { return n.schema$1; });
|
|
398
46
|
const latestSchemas = await listLatestSchemaFiles();
|
|
399
47
|
for (const schema of latestSchemas) {
|
|
400
48
|
try {
|
|
401
|
-
const { BaseFileManager } = await Promise.resolve().then(function () { return require('./index-
|
|
49
|
+
const { BaseFileManager } = await Promise.resolve().then(function () { return require('./index-BeKPbbk0.js'); }).then(function (n) { return n.BaseFileManager$1; });
|
|
402
50
|
const content = await BaseFileManager.readFileAsString(schema.filePath);
|
|
403
51
|
const schemaFile = JSON.parse(content);
|
|
404
52
|
if (schemaFile.models && schemaFile.models[modelName]) {
|
|
@@ -415,7 +63,7 @@ async function getSchemaNameFromModel(modelName) {
|
|
|
415
63
|
const saveToSchema = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
416
64
|
const _saveToSchema = async () => {
|
|
417
65
|
// Use dynamic import to break circular dependency
|
|
418
|
-
const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-
|
|
66
|
+
const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-CDKcVRFQ.js'); });
|
|
419
67
|
const validationService = new SchemaValidationService();
|
|
420
68
|
// Validate property structure before saving
|
|
421
69
|
const validationResult = validationService.validatePropertyStructure(context);
|
|
@@ -438,15 +86,14 @@ const saveToSchema = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
|
438
86
|
throw new Error(`Schema not found for model: ${context.modelName}`);
|
|
439
87
|
}
|
|
440
88
|
// Convert property context to SchemaPropertyUpdate
|
|
441
|
-
const propertyUpdate = await convertPropertyToSchemaUpdate(context, context.modelName, context.name);
|
|
89
|
+
const propertyUpdate = await Schema.convertPropertyToSchemaUpdate(context, context.modelName, context.name);
|
|
442
90
|
// Update the schema with the property changes
|
|
443
|
-
await updateModelProperties(schemaName, [propertyUpdate]);
|
|
91
|
+
await Schema.updateModelProperties(schemaName, [propertyUpdate]);
|
|
444
92
|
// Clear isEdited flag in database after saving to schema file
|
|
445
93
|
try {
|
|
446
|
-
const {
|
|
447
|
-
const { properties: propertiesTable, models: modelsTable } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.schema; });
|
|
94
|
+
const { properties: propertiesTable, models: modelsTable } = await Promise.resolve().then(function () { return require('./index-BeKPbbk0.js'); }).then(function (n) { return n.schema; });
|
|
448
95
|
const { eq, and } = await import('drizzle-orm');
|
|
449
|
-
const db = BaseDb.getAppDb();
|
|
96
|
+
const db = main_cjs.BaseDb.getAppDb();
|
|
450
97
|
if (db && context.modelName && context.name) {
|
|
451
98
|
// Find model by name
|
|
452
99
|
const modelRecords = await db
|
|
@@ -488,12 +135,6 @@ const saveToSchema = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
|
488
135
|
};
|
|
489
136
|
});
|
|
490
137
|
|
|
491
|
-
var saveToSchema$1 = /*#__PURE__*/Object.freeze({
|
|
492
|
-
__proto__: null,
|
|
493
|
-
getSchemaNameFromModel: getSchemaNameFromModel,
|
|
494
|
-
saveToSchema: saveToSchema
|
|
495
|
-
});
|
|
496
|
-
|
|
497
138
|
const logger$2 = debug('seedSdk:modelProperty:actors:compareAndMarkDraft');
|
|
498
139
|
const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
499
140
|
const _compareAndMarkDraft = async () => {
|
|
@@ -506,7 +147,7 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
506
147
|
const schemaFileIdForResolve = fullContext._propertyFileId || (typeof fullContext.id === 'string' ? fullContext.id : undefined);
|
|
507
148
|
if (schemaFileIdForResolve && (fullContext.modelName === undefined || fullContext.dataType === undefined)) {
|
|
508
149
|
try {
|
|
509
|
-
const { getPropertyModelNameAndDataType, getModelNameByModelId } = await Promise.resolve().then(function () { return require('./index-
|
|
150
|
+
const { getPropertyModelNameAndDataType, getModelNameByModelId } = await Promise.resolve().then(function () { return require('./index-BeKPbbk0.js'); }).then(function (n) { return n.db; });
|
|
510
151
|
let fromDb;
|
|
511
152
|
for (let attempt = 0; attempt < 6; attempt++) {
|
|
512
153
|
fromDb = await getPropertyModelNameAndDataType(schemaFileIdForResolve);
|
|
@@ -550,7 +191,7 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
550
191
|
if (fullContext.modelName && fullContext.name && schemaFileId) {
|
|
551
192
|
logger$2(`[compareAndMarkDraft] _originalValues not set, but saving to database anyway for property ${context.modelName}:${context.name} (schemaFileId: ${schemaFileId})`);
|
|
552
193
|
try {
|
|
553
|
-
const { savePropertyToDb } = await Promise.resolve().then(function () { return require('./index-
|
|
194
|
+
const { savePropertyToDb } = await Promise.resolve().then(function () { return require('./index-BeKPbbk0.js'); }).then(function (n) { return n.db; });
|
|
554
195
|
// Ensure _propertyFileId is set for savePropertyToDb to find the property
|
|
555
196
|
const contextWithFileId = {
|
|
556
197
|
...fullContext,
|
|
@@ -609,7 +250,7 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
609
250
|
logger$2(`Property ${fullContext.modelName}:${fullContext.name} has changes, marking as edited`);
|
|
610
251
|
logger$2(`[compareAndMarkDraft] Context when saving: id=${fullContext.id}, _propertyFileId=${fullContext._propertyFileId}, name=${fullContext.name}, _originalValues.name=${fullContext._originalValues?.name}`);
|
|
611
252
|
// Use dynamic import to break circular dependency
|
|
612
|
-
const { savePropertyToDb } = await Promise.resolve().then(function () { return require('./index-
|
|
253
|
+
const { savePropertyToDb } = await Promise.resolve().then(function () { return require('./index-BeKPbbk0.js'); }).then(function (n) { return n.db; });
|
|
613
254
|
// Save to database (but not JSON file) - always save to DB when there are changes
|
|
614
255
|
try {
|
|
615
256
|
await savePropertyToDb(fullContext);
|
|
@@ -622,7 +263,7 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
622
263
|
// Mark schema as draft if schema name is available
|
|
623
264
|
if (fullContext._schemaName) {
|
|
624
265
|
// Get the Schema instance and mark it as draft
|
|
625
|
-
const { Schema } = await Promise.resolve().then(function () { return require('./Schema-
|
|
266
|
+
const { Schema } = await Promise.resolve().then(function () { return require('./Schema-CVs9J6eP.js'); }).then(function (n) { return n.Schema$1; });
|
|
626
267
|
const schema = Schema.create(fullContext._schemaName, {
|
|
627
268
|
waitForReady: false,
|
|
628
269
|
});
|
|
@@ -638,10 +279,9 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
638
279
|
logger$2(`Property ${fullContext.modelName}:${fullContext.name} has no changes`);
|
|
639
280
|
// Clear isEdited flag in database
|
|
640
281
|
try {
|
|
641
|
-
const {
|
|
642
|
-
const { properties: propertiesTable, models: modelsTable } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.schema; });
|
|
282
|
+
const { properties: propertiesTable, models: modelsTable } = await Promise.resolve().then(function () { return require('./index-BeKPbbk0.js'); }).then(function (n) { return n.schema; });
|
|
643
283
|
const { eq, and } = await import('drizzle-orm');
|
|
644
|
-
const db = BaseDb.getAppDb();
|
|
284
|
+
const db = main_cjs.BaseDb.getAppDb();
|
|
645
285
|
if (db && fullContext.modelName && fullContext.name) {
|
|
646
286
|
// Find model by name
|
|
647
287
|
const modelRecords = await db
|
|
@@ -701,7 +341,7 @@ const validateProperty = xstate.fromCallback(({ sendBack, input: { context } })
|
|
|
701
341
|
// Brief wait so trackPendingWrite from ModelProperty.create() has time to run (it's in setTimeout(0))
|
|
702
342
|
await new Promise((r) => setTimeout(r, 60));
|
|
703
343
|
try {
|
|
704
|
-
const { getPropertyModelNameAndDataType, getModelNameByModelId } = await Promise.resolve().then(function () { return require('./index-
|
|
344
|
+
const { getPropertyModelNameAndDataType, getModelNameByModelId } = await Promise.resolve().then(function () { return require('./index-BeKPbbk0.js'); }).then(function (n) { return n.db; });
|
|
705
345
|
// Try pending write first (property row may not exist yet)
|
|
706
346
|
if (fullContext.modelName === undefined && schemaFileId) {
|
|
707
347
|
const mod = await Promise.resolve().then(function () { return ModelProperty$1; });
|
|
@@ -759,9 +399,9 @@ const validateProperty = xstate.fromCallback(({ sendBack, input: { context } })
|
|
|
759
399
|
_originalValues: fullContext._originalValues
|
|
760
400
|
});
|
|
761
401
|
// Use dynamic imports to break circular dependencies
|
|
762
|
-
const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-
|
|
402
|
+
const { SchemaValidationService } = await Promise.resolve().then(function () { return require('./SchemaValidationService-CDKcVRFQ.js'); });
|
|
763
403
|
const validationService = new SchemaValidationService();
|
|
764
|
-
const { Schema } = await Promise.resolve().then(function () { return require('./Schema-
|
|
404
|
+
const { Schema } = await Promise.resolve().then(function () { return require('./Schema-CVs9J6eP.js'); }).then(function (n) { return n.Schema$1; });
|
|
765
405
|
// Validate property structure
|
|
766
406
|
console.log('[validateProperty] Validating property structure...');
|
|
767
407
|
const structureResult = validationService.validatePropertyStructure(fullContext);
|
|
@@ -1359,7 +999,6 @@ class ModelProperty {
|
|
|
1359
999
|
return fallbackIsEdited;
|
|
1360
1000
|
}
|
|
1361
1001
|
try {
|
|
1362
|
-
const { eq, and } = await import('drizzle-orm');
|
|
1363
1002
|
const db = main_cjs.BaseDb.getAppDb();
|
|
1364
1003
|
if (!db) {
|
|
1365
1004
|
return fallbackIsEdited;
|
|
@@ -1368,7 +1007,7 @@ class ModelProperty {
|
|
|
1368
1007
|
const modelRecords = await db
|
|
1369
1008
|
.select({ id: main_cjs.models.id })
|
|
1370
1009
|
.from(main_cjs.models)
|
|
1371
|
-
.where(eq(main_cjs.models.name, property.modelName))
|
|
1010
|
+
.where(drizzleOrm.eq(main_cjs.models.name, property.modelName))
|
|
1372
1011
|
.limit(1);
|
|
1373
1012
|
if (modelRecords.length === 0) {
|
|
1374
1013
|
return fallbackIsEdited;
|
|
@@ -1377,7 +1016,7 @@ class ModelProperty {
|
|
|
1377
1016
|
const propertyRecords = await db
|
|
1378
1017
|
.select({ isEdited: main_cjs.properties.isEdited })
|
|
1379
1018
|
.from(main_cjs.properties)
|
|
1380
|
-
.where(and(eq(main_cjs.properties.name, property.name), eq(main_cjs.properties.modelId, modelRecords[0].id)))
|
|
1019
|
+
.where(drizzleOrm.and(drizzleOrm.eq(main_cjs.properties.name, property.name), drizzleOrm.eq(main_cjs.properties.modelId, modelRecords[0].id)))
|
|
1381
1020
|
.limit(1);
|
|
1382
1021
|
if (propertyRecords.length > 0) {
|
|
1383
1022
|
return propertyRecords[0].isEdited ?? false;
|
|
@@ -1398,7 +1037,6 @@ class ModelProperty {
|
|
|
1398
1037
|
return undefined;
|
|
1399
1038
|
}
|
|
1400
1039
|
try {
|
|
1401
|
-
const { eq } = await import('drizzle-orm');
|
|
1402
1040
|
const db = main_cjs.BaseDb.getAppDb();
|
|
1403
1041
|
if (!db) {
|
|
1404
1042
|
return undefined;
|
|
@@ -1406,7 +1044,7 @@ class ModelProperty {
|
|
|
1406
1044
|
const refModelRecords = await db
|
|
1407
1045
|
.select()
|
|
1408
1046
|
.from(main_cjs.models)
|
|
1409
|
-
.where(eq(main_cjs.models.name, refModelName))
|
|
1047
|
+
.where(drizzleOrm.eq(main_cjs.models.name, refModelName))
|
|
1410
1048
|
.limit(1);
|
|
1411
1049
|
if (refModelRecords.length > 0 && refModelRecords[0].id) {
|
|
1412
1050
|
return refModelRecords[0].id;
|
|
@@ -1427,13 +1065,11 @@ class ModelProperty {
|
|
|
1427
1065
|
return undefined;
|
|
1428
1066
|
}
|
|
1429
1067
|
try {
|
|
1430
|
-
const
|
|
1431
|
-
const { modelPropertiesToObject } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.model; });
|
|
1432
|
-
const model = await Model.getByNameAsync(property.modelName);
|
|
1068
|
+
const model = await main_cjs.Model.getByNameAsync(property.modelName);
|
|
1433
1069
|
if (!model || !model.properties || model.properties.length === 0) {
|
|
1434
1070
|
return undefined;
|
|
1435
1071
|
}
|
|
1436
|
-
const schema = modelPropertiesToObject(model.properties);
|
|
1072
|
+
const schema = main_cjs.modelPropertiesToObject(model.properties);
|
|
1437
1073
|
// Get the schema file value for this property
|
|
1438
1074
|
const schemaFileValue = schema[property.name];
|
|
1439
1075
|
if (!schemaFileValue) {
|
|
@@ -1477,7 +1113,6 @@ class ModelProperty {
|
|
|
1477
1113
|
// Try to get schema name from database first (more reliable)
|
|
1478
1114
|
if (this.modelId) {
|
|
1479
1115
|
try {
|
|
1480
|
-
const { eq } = await import('drizzle-orm');
|
|
1481
1116
|
const db = main_cjs.BaseDb.getAppDb();
|
|
1482
1117
|
if (db) {
|
|
1483
1118
|
const modelSchemaRecords = await db
|
|
@@ -1485,9 +1120,9 @@ class ModelProperty {
|
|
|
1485
1120
|
schemaName: main_cjs.schemas.name,
|
|
1486
1121
|
})
|
|
1487
1122
|
.from(main_cjs.modelSchemas)
|
|
1488
|
-
.innerJoin(main_cjs.schemas, eq(main_cjs.modelSchemas.schemaId, main_cjs.schemas.id))
|
|
1489
|
-
.innerJoin(main_cjs.models, eq(main_cjs.modelSchemas.modelId, main_cjs.models.id))
|
|
1490
|
-
.where(eq(main_cjs.models.id, this.modelId))
|
|
1123
|
+
.innerJoin(main_cjs.schemas, drizzleOrm.eq(main_cjs.modelSchemas.schemaId, main_cjs.schemas.id))
|
|
1124
|
+
.innerJoin(main_cjs.models, drizzleOrm.eq(main_cjs.modelSchemas.modelId, main_cjs.models.id))
|
|
1125
|
+
.where(drizzleOrm.eq(main_cjs.models.id, this.modelId))
|
|
1491
1126
|
.limit(1);
|
|
1492
1127
|
if (modelSchemaRecords.length > 0) {
|
|
1493
1128
|
schemaName = modelSchemaRecords[0].schemaName;
|
|
@@ -1500,7 +1135,6 @@ class ModelProperty {
|
|
|
1500
1135
|
}
|
|
1501
1136
|
// Fall back to schema file lookup if database didn't work
|
|
1502
1137
|
if (!schemaName) {
|
|
1503
|
-
const { getSchemaNameFromModel } = await Promise.resolve().then(function () { return saveToSchema$1; });
|
|
1504
1138
|
schemaName = await getSchemaNameFromModel(modelName);
|
|
1505
1139
|
}
|
|
1506
1140
|
if (schemaName) {
|
|
@@ -1681,8 +1315,7 @@ class ModelProperty {
|
|
|
1681
1315
|
else if (typeof propertyWithId.modelId === 'string') {
|
|
1682
1316
|
// modelId is a string (modelFileId), need to convert to database ID
|
|
1683
1317
|
try {
|
|
1684
|
-
|
|
1685
|
-
resolvedModelId = await getModelIdByFileId(propertyWithId.modelId);
|
|
1318
|
+
resolvedModelId = await main_cjs.getModelIdByFileId(propertyWithId.modelId);
|
|
1686
1319
|
logger(`Converted modelFileId "${propertyWithId.modelId}" to database modelId: ${resolvedModelId}`);
|
|
1687
1320
|
}
|
|
1688
1321
|
catch (error) {
|
|
@@ -1694,10 +1327,9 @@ class ModelProperty {
|
|
|
1694
1327
|
// If we still don't have a modelId, try to resolve it from modelName
|
|
1695
1328
|
if (!resolvedModelId && propertyWithId.modelName) {
|
|
1696
1329
|
try {
|
|
1697
|
-
const { getModelId } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.db; });
|
|
1698
1330
|
// Get schemaName from context if available
|
|
1699
1331
|
const schemaName = snapshot.context._schemaName;
|
|
1700
|
-
resolvedModelId = await getModelId(propertyWithId.modelName, schemaName);
|
|
1332
|
+
resolvedModelId = await main_cjs.getModelId(propertyWithId.modelName, schemaName);
|
|
1701
1333
|
logger(`Resolved modelId for model "${propertyWithId.modelName}": ${resolvedModelId}`);
|
|
1702
1334
|
}
|
|
1703
1335
|
catch (error) {
|
|
@@ -1803,7 +1435,6 @@ class ModelProperty {
|
|
|
1803
1435
|
return cachedInstance;
|
|
1804
1436
|
}
|
|
1805
1437
|
// Query database to get property data from ID
|
|
1806
|
-
const { eq } = await import('drizzle-orm');
|
|
1807
1438
|
const db = main_cjs.BaseDb.getAppDb();
|
|
1808
1439
|
console.log('db', !!db);
|
|
1809
1440
|
if (!db) {
|
|
@@ -1818,7 +1449,7 @@ class ModelProperty {
|
|
|
1818
1449
|
const propertyRecords = await db
|
|
1819
1450
|
.select()
|
|
1820
1451
|
.from(main_cjs.properties)
|
|
1821
|
-
.where(eq(main_cjs.properties.schemaFileId, propertyFileId))
|
|
1452
|
+
.where(drizzleOrm.eq(main_cjs.properties.schemaFileId, propertyFileId))
|
|
1822
1453
|
.limit(1);
|
|
1823
1454
|
console.log('propertyRecords', propertyRecords);
|
|
1824
1455
|
if (propertyRecords.length === 0) {
|
|
@@ -1829,7 +1460,7 @@ class ModelProperty {
|
|
|
1829
1460
|
const modelRecords = await db
|
|
1830
1461
|
.select({ name: main_cjs.models.name })
|
|
1831
1462
|
.from(main_cjs.models)
|
|
1832
|
-
.where(eq(main_cjs.models.id, propertyRecord.modelId))
|
|
1463
|
+
.where(drizzleOrm.eq(main_cjs.models.id, propertyRecord.modelId))
|
|
1833
1464
|
.limit(1);
|
|
1834
1465
|
if (modelRecords.length === 0) {
|
|
1835
1466
|
return undefined;
|
|
@@ -1854,7 +1485,7 @@ class ModelProperty {
|
|
|
1854
1485
|
const refModelRecords = await db
|
|
1855
1486
|
.select({ name: main_cjs.models.name })
|
|
1856
1487
|
.from(main_cjs.models)
|
|
1857
|
-
.where(eq(main_cjs.models.id, propertyRecord.refModelId))
|
|
1488
|
+
.where(drizzleOrm.eq(main_cjs.models.id, propertyRecord.refModelId))
|
|
1858
1489
|
.limit(1);
|
|
1859
1490
|
if (refModelRecords.length > 0) {
|
|
1860
1491
|
propertyData.refModelName = refModelRecords[0].name;
|
|
@@ -2106,8 +1737,7 @@ class ModelProperty {
|
|
|
2106
1737
|
}
|
|
2107
1738
|
}
|
|
2108
1739
|
if (schemaName) {
|
|
2109
|
-
const
|
|
2110
|
-
const schema = Schema.create(schemaName, { waitForReady: false });
|
|
1740
|
+
const schema = Schema.Schema.create(schemaName, { waitForReady: false });
|
|
2111
1741
|
const snapshot = schema.getService().getSnapshot();
|
|
2112
1742
|
const schemaContext = snapshot.context;
|
|
2113
1743
|
if (schemaContext.models?.[modelName]?.properties?.[propertyName]) {
|
|
@@ -2133,8 +1763,4 @@ var ModelProperty$1 = /*#__PURE__*/Object.freeze({
|
|
|
2133
1763
|
});
|
|
2134
1764
|
|
|
2135
1765
|
exports.ModelProperty = ModelProperty;
|
|
2136
|
-
|
|
2137
|
-
exports.convertPropertyToSchemaUpdate = convertPropertyToSchemaUpdate;
|
|
2138
|
-
exports.updateModelProperties = updateModelProperties;
|
|
2139
|
-
exports.writeFullSchemaNewVersion = writeFullSchemaNewVersion;
|
|
2140
|
-
//# sourceMappingURL=ModelProperty-BRKRREYP.js.map
|
|
1766
|
+
//# sourceMappingURL=ModelProperty-BeJvgKMw.js.map
|