@seedprotocol/sdk 0.4.4 → 0.4.6
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-Caio37h1.js} +8 -8
- package/dist/ArweaveClient-Caio37h1.js.map +1 -0
- package/dist/{ArweaveClient-CczHvccG.js → ArweaveClient-DLKAaS3K.js} +8 -8
- package/dist/ArweaveClient-DLKAaS3K.js.map +1 -0
- package/dist/{Db-DJvjXVlp.js → Db-C9fppVRl.js} +9 -9
- package/dist/Db-C9fppVRl.js.map +1 -0
- package/dist/{Db-BzQR2KX9.js → Db-DJAG-5Di.js} +13 -11
- package/dist/Db-DJAG-5Di.js.map +1 -0
- package/dist/{EasClient-CHQYmjj2.js → EasClient-DQGAIj-b.js} +8 -8
- package/dist/EasClient-DQGAIj-b.js.map +1 -0
- package/dist/{EasClient-CodrIgW-.js → EasClient-T7Nx9185.js} +8 -8
- package/dist/EasClient-T7Nx9185.js.map +1 -0
- package/dist/{FileManager-BbvkZJCH.js → FileManager-BohtoKYo.js} +10 -9
- package/dist/FileManager-BohtoKYo.js.map +1 -0
- package/dist/{FileManager-BIVsDnMu.js → FileManager-d64CkqXy.js} +8 -8
- package/dist/FileManager-d64CkqXy.js.map +1 -0
- package/dist/Item/Item.d.ts.map +1 -1
- package/dist/Item/service/actors/fetchDataFromEas.d.ts.map +1 -1
- package/dist/Item/service/actors/loadOrCreateItem.d.ts.map +1 -1
- package/dist/Item/service/actors/runPublish.d.ts.map +1 -1
- package/dist/ItemProperty/ItemProperty.d.ts.map +1 -1
- package/dist/ItemProperty/service/actors/hydrateFromDb.d.ts.map +1 -1
- package/dist/ItemProperty/service/actors/resolveRelatedValue.d.ts.map +1 -1
- package/dist/ItemProperty/service/actors/saveValueToDb/analyzeInput.d.ts.map +1 -1
- package/dist/ItemProperty/service/actors/saveValueToDb/saveRelation.d.ts.map +1 -1
- package/dist/Model/Model.d.ts.map +1 -1
- package/dist/Model/service/actors/createModelProperties.d.ts.map +1 -1
- package/dist/Model/service/actors/loadOrCreateModel.d.ts.map +1 -1
- package/dist/Model/service/actors/validateModel.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/service/actors/validateProperty.d.ts.map +1 -1
- package/dist/{ModelProperty-gjcA83Mq.js → ModelProperty-Cpd9xiIM.js} +67 -768
- package/dist/ModelProperty-Cpd9xiIM.js.map +1 -0
- package/dist/{PathResolver-kGzba-zC.js → PathResolver-CLZUWoX2.js} +8 -8
- package/dist/PathResolver-CLZUWoX2.js.map +1 -0
- package/dist/{PathResolver-9zAzPhee.js → PathResolver-D6M0rzKV.js} +8 -8
- package/dist/PathResolver-D6M0rzKV.js.map +1 -0
- package/dist/{QueryClient-C7ZkTT0z.js → QueryClient-BUoz2Vb0.js} +8 -8
- package/dist/QueryClient-BUoz2Vb0.js.map +1 -0
- package/dist/{QueryClient-CEtsek7Q.js → QueryClient-COQ_Rs4-.js} +8 -8
- package/dist/QueryClient-COQ_Rs4-.js.map +1 -0
- package/dist/Schema/Schema.d.ts.map +1 -1
- package/dist/Schema/service/actors/createModelInstances.d.ts.map +1 -1
- package/dist/Schema/service/actors/loadOrCreateSchema.d.ts.map +1 -1
- package/dist/Schema/service/actors/verifyModelInstancesInCache.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-BZKBy5Tx.js} +799 -62
- package/dist/Schema-BZKBy5Tx.js.map +1 -0
- package/dist/{SchemaValidationService-BfoEiHNr.js → SchemaValidationService-F8No7BHp.js} +7 -7
- package/dist/SchemaValidationService-F8No7BHp.js.map +1 -0
- package/dist/browser/helpers/FileManager.d.ts.map +1 -1
- package/dist/browser/react/itemProperty.d.ts.map +1 -1
- package/dist/cjs/{ModelProperty-BRKRREYP.js → ModelProperty-B4pV91tc.js} +78 -438
- package/dist/cjs/ModelProperty-B4pV91tc.js.map +1 -0
- package/dist/cjs/{Schema-CV9hMg8m.js → Schema-TErl3J36.js} +437 -93
- package/dist/cjs/Schema-TErl3J36.js.map +1 -0
- package/dist/cjs/{SchemaValidationService-DUtQUerg.js → SchemaValidationService-p5BbJV9T.js} +3 -3
- package/dist/cjs/{SchemaValidationService-DUtQUerg.js.map → SchemaValidationService-p5BbJV9T.js.map} +1 -1
- package/dist/cjs/{getItem-BThT-UOt.js → getItem-BrnLfC12.js} +3 -3
- package/dist/cjs/{getItem-BThT-UOt.js.map → getItem-BrnLfC12.js.map} +1 -1
- package/dist/cjs/{getPublishPayload-CKZ7rVbU.js → getPublishPayload-BcjCN_bD.js} +8 -6
- package/dist/cjs/getPublishPayload-BcjCN_bD.js.map +1 -0
- package/dist/cjs/{getPublishUploads-CuGIvV-Q.js → getPublishUploads-5_oXzwol.js} +4 -4
- package/dist/cjs/{getPublishUploads-CuGIvV-Q.js.map → getPublishUploads-5_oXzwol.js.map} +1 -1
- package/dist/cjs/{getSegmentedItemProperties-BCJXJlTR.js → getSegmentedItemProperties-WFdizUDv.js} +2 -2
- package/dist/cjs/{getSegmentedItemProperties-BCJXJlTR.js.map → getSegmentedItemProperties-WFdizUDv.js.map} +1 -1
- package/dist/cjs/{index-CbTBDqTJ.js → index-BrmvhXsG.js} +3 -3
- package/dist/cjs/index-BrmvhXsG.js.map +1 -0
- package/dist/cjs/{index-C3j3m34a.js → index-CXI4VF1H.js} +12351 -12189
- package/dist/cjs/index-CXI4VF1H.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/db/read/getModelSchemas.d.ts.map +1 -1
- package/dist/db/read/getPublishPayload.d.ts.map +1 -1
- package/dist/db/write/createNewItem.d.ts.map +1 -1
- package/dist/eas.d.ts.map +1 -1
- package/dist/events/files/download.d.ts.map +1 -1
- package/dist/events/item/syncDbWithEas.d.ts.map +1 -1
- package/dist/{getItem-BWPo8wd0.js → getItem-DaQVdeae.js} +8 -8
- package/dist/getItem-DaQVdeae.js.map +1 -0
- package/dist/{getPublishPayload-Caw2laZM.js → getPublishPayload-CWiLI1yd.js} +12 -10
- package/dist/getPublishPayload-CWiLI1yd.js.map +1 -0
- package/dist/{getPublishUploads-MlyBuoXh.js → getPublishUploads-DhvcKD_9.js} +9 -9
- package/dist/getPublishUploads-DhvcKD_9.js.map +1 -0
- package/dist/{getSegmentedItemProperties-COLLdDo4.js → getSegmentedItemProperties-Cp4kcWIF.js} +2 -2
- package/dist/getSegmentedItemProperties-Cp4kcWIF.js.map +1 -0
- package/dist/helpers/db.d.ts.map +1 -1
- package/dist/helpers/property.d.ts.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-DBy53qbb.js} +2 -2
- package/dist/index-DBy53qbb.js.map +1 -0
- package/dist/{ClientManager-DoHUt8tU.js → index-Dk73a7JE.js} +11781 -11613
- package/dist/index-Dk73a7JE.js.map +1 -0
- package/dist/{index-B9i_mXXp.js → index-LfXKx_PE.js} +9 -9
- package/dist/index-LfXKx_PE.js.map +1 -0
- package/dist/main.cjs +2 -2
- package/dist/main.js +16 -13
- package/dist/main.js.map +1 -1
- package/dist/node/db/Db.d.ts.map +1 -1
- package/dist/node.js +15 -15
- package/dist/node.js.map +1 -1
- package/dist/{property-fK7tSUDX.js → property-1o2MvYTm.js} +10 -4
- package/dist/property-1o2MvYTm.js.map +1 -0
- package/dist/{queries-DGOk16cd.js → queries-DA4G0iEN.js} +2 -2
- package/dist/queries-DA4G0iEN.js.map +1 -0
- package/dist/services/publish/actors/preparePublishRequestData.d.ts.map +1 -1
- package/dist/services/publish/actors/upload.d.ts.map +1 -1
- package/dist/services/write/actors/validateEntity.d.ts.map +1 -1
- package/dist/services/write/actors/writeToDatabase.d.ts.map +1 -1
- package/dist/vite.js.map +1 -1
- package/package.json +8 -4
- package/dist/ArweaveClient-CczHvccG.js.map +0 -1
- package/dist/ArweaveClient-DkNLWiSZ.js.map +0 -1
- package/dist/ClientManager-DoHUt8tU.js.map +0 -1
- package/dist/Db-BzQR2KX9.js.map +0 -1
- package/dist/Db-DJvjXVlp.js.map +0 -1
- package/dist/EasClient-CHQYmjj2.js.map +0 -1
- package/dist/EasClient-CodrIgW-.js.map +0 -1
- package/dist/FileManager-BIVsDnMu.js.map +0 -1
- package/dist/FileManager-BbvkZJCH.js.map +0 -1
- package/dist/ModelProperty-gjcA83Mq.js.map +0 -1
- package/dist/PathResolver-9zAzPhee.js.map +0 -1
- package/dist/PathResolver-kGzba-zC.js.map +0 -1
- package/dist/QueryClient-C7ZkTT0z.js.map +0 -1
- package/dist/QueryClient-CEtsek7Q.js.map +0 -1
- package/dist/Schema-ClTcpgbt.js.map +0 -1
- package/dist/SchemaValidationService-BfoEiHNr.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/getItem-BWPo8wd0.js.map +0 -1
- package/dist/getPublishPayload-Caw2laZM.js.map +0 -1
- package/dist/getPublishUploads-MlyBuoXh.js.map +0 -1
- package/dist/getSegmentedItemProperties-COLLdDo4.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
- package/dist/queries-DGOk16cd.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-TErl3J36.js');
|
|
5
|
+
var main_cjs = require('./index-CXI4VF1H.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-p5BbJV9T.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,13 @@ 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
|
|
45
|
+
const schemaHelpersMod = await Promise.resolve().then(function () { return require('./index-CXI4VF1H.js'); }).then(function (n) { return n.schema$1; });
|
|
46
|
+
const { listLatestSchemaFiles } = schemaHelpersMod;
|
|
398
47
|
const latestSchemas = await listLatestSchemaFiles();
|
|
399
48
|
for (const schema of latestSchemas) {
|
|
400
49
|
try {
|
|
401
|
-
const
|
|
50
|
+
const fileManagerMod = await Promise.resolve().then(function () { return require('./index-CXI4VF1H.js'); }).then(function (n) { return n.BaseFileManager$1; });
|
|
51
|
+
const { BaseFileManager } = fileManagerMod;
|
|
402
52
|
const content = await BaseFileManager.readFileAsString(schema.filePath);
|
|
403
53
|
const schemaFile = JSON.parse(content);
|
|
404
54
|
if (schemaFile.models && schemaFile.models[modelName]) {
|
|
@@ -415,7 +65,8 @@ async function getSchemaNameFromModel(modelName) {
|
|
|
415
65
|
const saveToSchema = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
416
66
|
const _saveToSchema = async () => {
|
|
417
67
|
// Use dynamic import to break circular dependency
|
|
418
|
-
const
|
|
68
|
+
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-p5BbJV9T.js'); });
|
|
69
|
+
const { SchemaValidationService } = validationServiceMod;
|
|
419
70
|
const validationService = new SchemaValidationService();
|
|
420
71
|
// Validate property structure before saving
|
|
421
72
|
const validationResult = validationService.validatePropertyStructure(context);
|
|
@@ -438,15 +89,16 @@ const saveToSchema = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
|
438
89
|
throw new Error(`Schema not found for model: ${context.modelName}`);
|
|
439
90
|
}
|
|
440
91
|
// Convert property context to SchemaPropertyUpdate
|
|
441
|
-
const propertyUpdate = await convertPropertyToSchemaUpdate(context, context.modelName, context.name);
|
|
92
|
+
const propertyUpdate = await Schema.convertPropertyToSchemaUpdate(context, context.modelName, context.name);
|
|
442
93
|
// Update the schema with the property changes
|
|
443
|
-
await updateModelProperties(schemaName, [propertyUpdate]);
|
|
94
|
+
await Schema.updateModelProperties(schemaName, [propertyUpdate]);
|
|
444
95
|
// Clear isEdited flag in database after saving to schema file
|
|
445
96
|
try {
|
|
446
|
-
const
|
|
447
|
-
const { properties: propertiesTable, models: modelsTable } =
|
|
448
|
-
const
|
|
449
|
-
const
|
|
97
|
+
const seedSchemaMod = await Promise.resolve().then(function () { return require('./index-CXI4VF1H.js'); }).then(function (n) { return n.schema; });
|
|
98
|
+
const { properties: propertiesTable, models: modelsTable } = seedSchemaMod;
|
|
99
|
+
const drizzleMod = await import('drizzle-orm');
|
|
100
|
+
const { eq, and } = drizzleMod;
|
|
101
|
+
const db = main_cjs.BaseDb.getAppDb();
|
|
450
102
|
if (db && context.modelName && context.name) {
|
|
451
103
|
// Find model by name
|
|
452
104
|
const modelRecords = await db
|
|
@@ -488,12 +140,6 @@ const saveToSchema = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
|
488
140
|
};
|
|
489
141
|
});
|
|
490
142
|
|
|
491
|
-
var saveToSchema$1 = /*#__PURE__*/Object.freeze({
|
|
492
|
-
__proto__: null,
|
|
493
|
-
getSchemaNameFromModel: getSchemaNameFromModel,
|
|
494
|
-
saveToSchema: saveToSchema
|
|
495
|
-
});
|
|
496
|
-
|
|
497
143
|
const logger$2 = debug('seedSdk:modelProperty:actors:compareAndMarkDraft');
|
|
498
144
|
const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context } }) => {
|
|
499
145
|
const _compareAndMarkDraft = async () => {
|
|
@@ -506,7 +152,8 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
506
152
|
const schemaFileIdForResolve = fullContext._propertyFileId || (typeof fullContext.id === 'string' ? fullContext.id : undefined);
|
|
507
153
|
if (schemaFileIdForResolve && (fullContext.modelName === undefined || fullContext.dataType === undefined)) {
|
|
508
154
|
try {
|
|
509
|
-
const
|
|
155
|
+
const dbMod = await Promise.resolve().then(function () { return require('./index-CXI4VF1H.js'); }).then(function (n) { return n.db; });
|
|
156
|
+
const { getPropertyModelNameAndDataType, getModelNameByModelId } = dbMod;
|
|
510
157
|
let fromDb;
|
|
511
158
|
for (let attempt = 0; attempt < 6; attempt++) {
|
|
512
159
|
fromDb = await getPropertyModelNameAndDataType(schemaFileIdForResolve);
|
|
@@ -550,7 +197,8 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
550
197
|
if (fullContext.modelName && fullContext.name && schemaFileId) {
|
|
551
198
|
logger$2(`[compareAndMarkDraft] _originalValues not set, but saving to database anyway for property ${context.modelName}:${context.name} (schemaFileId: ${schemaFileId})`);
|
|
552
199
|
try {
|
|
553
|
-
const
|
|
200
|
+
const dbMod = await Promise.resolve().then(function () { return require('./index-CXI4VF1H.js'); }).then(function (n) { return n.db; });
|
|
201
|
+
const { savePropertyToDb } = dbMod;
|
|
554
202
|
// Ensure _propertyFileId is set for savePropertyToDb to find the property
|
|
555
203
|
const contextWithFileId = {
|
|
556
204
|
...fullContext,
|
|
@@ -609,7 +257,8 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
609
257
|
logger$2(`Property ${fullContext.modelName}:${fullContext.name} has changes, marking as edited`);
|
|
610
258
|
logger$2(`[compareAndMarkDraft] Context when saving: id=${fullContext.id}, _propertyFileId=${fullContext._propertyFileId}, name=${fullContext.name}, _originalValues.name=${fullContext._originalValues?.name}`);
|
|
611
259
|
// Use dynamic import to break circular dependency
|
|
612
|
-
const
|
|
260
|
+
const dbMod = await Promise.resolve().then(function () { return require('./index-CXI4VF1H.js'); }).then(function (n) { return n.db; });
|
|
261
|
+
const { savePropertyToDb } = dbMod;
|
|
613
262
|
// Save to database (but not JSON file) - always save to DB when there are changes
|
|
614
263
|
try {
|
|
615
264
|
await savePropertyToDb(fullContext);
|
|
@@ -622,7 +271,8 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
622
271
|
// Mark schema as draft if schema name is available
|
|
623
272
|
if (fullContext._schemaName) {
|
|
624
273
|
// Get the Schema instance and mark it as draft
|
|
625
|
-
const
|
|
274
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-TErl3J36.js'); }).then(function (n) { return n.Schema$1; });
|
|
275
|
+
const { Schema } = schemaMod;
|
|
626
276
|
const schema = Schema.create(fullContext._schemaName, {
|
|
627
277
|
waitForReady: false,
|
|
628
278
|
});
|
|
@@ -638,10 +288,11 @@ const compareAndMarkDraft = xstate.fromCallback(({ sendBack, input: { context }
|
|
|
638
288
|
logger$2(`Property ${fullContext.modelName}:${fullContext.name} has no changes`);
|
|
639
289
|
// Clear isEdited flag in database
|
|
640
290
|
try {
|
|
641
|
-
const
|
|
642
|
-
const { properties: propertiesTable, models: modelsTable } =
|
|
643
|
-
const
|
|
644
|
-
const
|
|
291
|
+
const seedSchemaMod = await Promise.resolve().then(function () { return require('./index-CXI4VF1H.js'); }).then(function (n) { return n.schema; });
|
|
292
|
+
const { properties: propertiesTable, models: modelsTable } = seedSchemaMod;
|
|
293
|
+
const drizzleMod = await import('drizzle-orm');
|
|
294
|
+
const { eq, and } = drizzleMod;
|
|
295
|
+
const db = main_cjs.BaseDb.getAppDb();
|
|
645
296
|
if (db && fullContext.modelName && fullContext.name) {
|
|
646
297
|
// Find model by name
|
|
647
298
|
const modelRecords = await db
|
|
@@ -701,7 +352,8 @@ const validateProperty = xstate.fromCallback(({ sendBack, input: { context } })
|
|
|
701
352
|
// Brief wait so trackPendingWrite from ModelProperty.create() has time to run (it's in setTimeout(0))
|
|
702
353
|
await new Promise((r) => setTimeout(r, 60));
|
|
703
354
|
try {
|
|
704
|
-
const
|
|
355
|
+
const dbMod = await Promise.resolve().then(function () { return require('./index-CXI4VF1H.js'); }).then(function (n) { return n.db; });
|
|
356
|
+
const { getPropertyModelNameAndDataType, getModelNameByModelId } = dbMod;
|
|
705
357
|
// Try pending write first (property row may not exist yet)
|
|
706
358
|
if (fullContext.modelName === undefined && schemaFileId) {
|
|
707
359
|
const mod = await Promise.resolve().then(function () { return ModelProperty$1; });
|
|
@@ -759,9 +411,11 @@ const validateProperty = xstate.fromCallback(({ sendBack, input: { context } })
|
|
|
759
411
|
_originalValues: fullContext._originalValues
|
|
760
412
|
});
|
|
761
413
|
// Use dynamic imports to break circular dependencies
|
|
762
|
-
const
|
|
414
|
+
const validationServiceMod = await Promise.resolve().then(function () { return require('./SchemaValidationService-p5BbJV9T.js'); });
|
|
415
|
+
const { SchemaValidationService } = validationServiceMod;
|
|
763
416
|
const validationService = new SchemaValidationService();
|
|
764
|
-
const
|
|
417
|
+
const schemaMod = await Promise.resolve().then(function () { return require('./Schema-TErl3J36.js'); }).then(function (n) { return n.Schema$1; });
|
|
418
|
+
const { Schema } = schemaMod;
|
|
765
419
|
// Validate property structure
|
|
766
420
|
console.log('[validateProperty] Validating property structure...');
|
|
767
421
|
const structureResult = validationService.validatePropertyStructure(fullContext);
|
|
@@ -1359,7 +1013,6 @@ class ModelProperty {
|
|
|
1359
1013
|
return fallbackIsEdited;
|
|
1360
1014
|
}
|
|
1361
1015
|
try {
|
|
1362
|
-
const { eq, and } = await import('drizzle-orm');
|
|
1363
1016
|
const db = main_cjs.BaseDb.getAppDb();
|
|
1364
1017
|
if (!db) {
|
|
1365
1018
|
return fallbackIsEdited;
|
|
@@ -1368,7 +1021,7 @@ class ModelProperty {
|
|
|
1368
1021
|
const modelRecords = await db
|
|
1369
1022
|
.select({ id: main_cjs.models.id })
|
|
1370
1023
|
.from(main_cjs.models)
|
|
1371
|
-
.where(eq(main_cjs.models.name, property.modelName))
|
|
1024
|
+
.where(drizzleOrm.eq(main_cjs.models.name, property.modelName))
|
|
1372
1025
|
.limit(1);
|
|
1373
1026
|
if (modelRecords.length === 0) {
|
|
1374
1027
|
return fallbackIsEdited;
|
|
@@ -1377,7 +1030,7 @@ class ModelProperty {
|
|
|
1377
1030
|
const propertyRecords = await db
|
|
1378
1031
|
.select({ isEdited: main_cjs.properties.isEdited })
|
|
1379
1032
|
.from(main_cjs.properties)
|
|
1380
|
-
.where(and(eq(main_cjs.properties.name, property.name), eq(main_cjs.properties.modelId, modelRecords[0].id)))
|
|
1033
|
+
.where(drizzleOrm.and(drizzleOrm.eq(main_cjs.properties.name, property.name), drizzleOrm.eq(main_cjs.properties.modelId, modelRecords[0].id)))
|
|
1381
1034
|
.limit(1);
|
|
1382
1035
|
if (propertyRecords.length > 0) {
|
|
1383
1036
|
return propertyRecords[0].isEdited ?? false;
|
|
@@ -1398,7 +1051,6 @@ class ModelProperty {
|
|
|
1398
1051
|
return undefined;
|
|
1399
1052
|
}
|
|
1400
1053
|
try {
|
|
1401
|
-
const { eq } = await import('drizzle-orm');
|
|
1402
1054
|
const db = main_cjs.BaseDb.getAppDb();
|
|
1403
1055
|
if (!db) {
|
|
1404
1056
|
return undefined;
|
|
@@ -1406,7 +1058,7 @@ class ModelProperty {
|
|
|
1406
1058
|
const refModelRecords = await db
|
|
1407
1059
|
.select()
|
|
1408
1060
|
.from(main_cjs.models)
|
|
1409
|
-
.where(eq(main_cjs.models.name, refModelName))
|
|
1061
|
+
.where(drizzleOrm.eq(main_cjs.models.name, refModelName))
|
|
1410
1062
|
.limit(1);
|
|
1411
1063
|
if (refModelRecords.length > 0 && refModelRecords[0].id) {
|
|
1412
1064
|
return refModelRecords[0].id;
|
|
@@ -1427,13 +1079,11 @@ class ModelProperty {
|
|
|
1427
1079
|
return undefined;
|
|
1428
1080
|
}
|
|
1429
1081
|
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);
|
|
1082
|
+
const model = await main_cjs.Model.getByNameAsync(property.modelName);
|
|
1433
1083
|
if (!model || !model.properties || model.properties.length === 0) {
|
|
1434
1084
|
return undefined;
|
|
1435
1085
|
}
|
|
1436
|
-
const schema = modelPropertiesToObject(model.properties);
|
|
1086
|
+
const schema = main_cjs.modelPropertiesToObject(model.properties);
|
|
1437
1087
|
// Get the schema file value for this property
|
|
1438
1088
|
const schemaFileValue = schema[property.name];
|
|
1439
1089
|
if (!schemaFileValue) {
|
|
@@ -1477,7 +1127,6 @@ class ModelProperty {
|
|
|
1477
1127
|
// Try to get schema name from database first (more reliable)
|
|
1478
1128
|
if (this.modelId) {
|
|
1479
1129
|
try {
|
|
1480
|
-
const { eq } = await import('drizzle-orm');
|
|
1481
1130
|
const db = main_cjs.BaseDb.getAppDb();
|
|
1482
1131
|
if (db) {
|
|
1483
1132
|
const modelSchemaRecords = await db
|
|
@@ -1485,9 +1134,9 @@ class ModelProperty {
|
|
|
1485
1134
|
schemaName: main_cjs.schemas.name,
|
|
1486
1135
|
})
|
|
1487
1136
|
.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))
|
|
1137
|
+
.innerJoin(main_cjs.schemas, drizzleOrm.eq(main_cjs.modelSchemas.schemaId, main_cjs.schemas.id))
|
|
1138
|
+
.innerJoin(main_cjs.models, drizzleOrm.eq(main_cjs.modelSchemas.modelId, main_cjs.models.id))
|
|
1139
|
+
.where(drizzleOrm.eq(main_cjs.models.id, this.modelId))
|
|
1491
1140
|
.limit(1);
|
|
1492
1141
|
if (modelSchemaRecords.length > 0) {
|
|
1493
1142
|
schemaName = modelSchemaRecords[0].schemaName;
|
|
@@ -1500,7 +1149,6 @@ class ModelProperty {
|
|
|
1500
1149
|
}
|
|
1501
1150
|
// Fall back to schema file lookup if database didn't work
|
|
1502
1151
|
if (!schemaName) {
|
|
1503
|
-
const { getSchemaNameFromModel } = await Promise.resolve().then(function () { return saveToSchema$1; });
|
|
1504
1152
|
schemaName = await getSchemaNameFromModel(modelName);
|
|
1505
1153
|
}
|
|
1506
1154
|
if (schemaName) {
|
|
@@ -1681,8 +1329,7 @@ class ModelProperty {
|
|
|
1681
1329
|
else if (typeof propertyWithId.modelId === 'string') {
|
|
1682
1330
|
// modelId is a string (modelFileId), need to convert to database ID
|
|
1683
1331
|
try {
|
|
1684
|
-
|
|
1685
|
-
resolvedModelId = await getModelIdByFileId(propertyWithId.modelId);
|
|
1332
|
+
resolvedModelId = await main_cjs.getModelIdByFileId(propertyWithId.modelId);
|
|
1686
1333
|
logger(`Converted modelFileId "${propertyWithId.modelId}" to database modelId: ${resolvedModelId}`);
|
|
1687
1334
|
}
|
|
1688
1335
|
catch (error) {
|
|
@@ -1694,10 +1341,9 @@ class ModelProperty {
|
|
|
1694
1341
|
// If we still don't have a modelId, try to resolve it from modelName
|
|
1695
1342
|
if (!resolvedModelId && propertyWithId.modelName) {
|
|
1696
1343
|
try {
|
|
1697
|
-
const { getModelId } = await Promise.resolve().then(function () { return require('./index-C3j3m34a.js'); }).then(function (n) { return n.db; });
|
|
1698
1344
|
// Get schemaName from context if available
|
|
1699
1345
|
const schemaName = snapshot.context._schemaName;
|
|
1700
|
-
resolvedModelId = await getModelId(propertyWithId.modelName, schemaName);
|
|
1346
|
+
resolvedModelId = await main_cjs.getModelId(propertyWithId.modelName, schemaName);
|
|
1701
1347
|
logger(`Resolved modelId for model "${propertyWithId.modelName}": ${resolvedModelId}`);
|
|
1702
1348
|
}
|
|
1703
1349
|
catch (error) {
|
|
@@ -1803,7 +1449,6 @@ class ModelProperty {
|
|
|
1803
1449
|
return cachedInstance;
|
|
1804
1450
|
}
|
|
1805
1451
|
// Query database to get property data from ID
|
|
1806
|
-
const { eq } = await import('drizzle-orm');
|
|
1807
1452
|
const db = main_cjs.BaseDb.getAppDb();
|
|
1808
1453
|
console.log('db', !!db);
|
|
1809
1454
|
if (!db) {
|
|
@@ -1818,7 +1463,7 @@ class ModelProperty {
|
|
|
1818
1463
|
const propertyRecords = await db
|
|
1819
1464
|
.select()
|
|
1820
1465
|
.from(main_cjs.properties)
|
|
1821
|
-
.where(eq(main_cjs.properties.schemaFileId, propertyFileId))
|
|
1466
|
+
.where(drizzleOrm.eq(main_cjs.properties.schemaFileId, propertyFileId))
|
|
1822
1467
|
.limit(1);
|
|
1823
1468
|
console.log('propertyRecords', propertyRecords);
|
|
1824
1469
|
if (propertyRecords.length === 0) {
|
|
@@ -1829,7 +1474,7 @@ class ModelProperty {
|
|
|
1829
1474
|
const modelRecords = await db
|
|
1830
1475
|
.select({ name: main_cjs.models.name })
|
|
1831
1476
|
.from(main_cjs.models)
|
|
1832
|
-
.where(eq(main_cjs.models.id, propertyRecord.modelId))
|
|
1477
|
+
.where(drizzleOrm.eq(main_cjs.models.id, propertyRecord.modelId))
|
|
1833
1478
|
.limit(1);
|
|
1834
1479
|
if (modelRecords.length === 0) {
|
|
1835
1480
|
return undefined;
|
|
@@ -1854,7 +1499,7 @@ class ModelProperty {
|
|
|
1854
1499
|
const refModelRecords = await db
|
|
1855
1500
|
.select({ name: main_cjs.models.name })
|
|
1856
1501
|
.from(main_cjs.models)
|
|
1857
|
-
.where(eq(main_cjs.models.id, propertyRecord.refModelId))
|
|
1502
|
+
.where(drizzleOrm.eq(main_cjs.models.id, propertyRecord.refModelId))
|
|
1858
1503
|
.limit(1);
|
|
1859
1504
|
if (refModelRecords.length > 0) {
|
|
1860
1505
|
propertyData.refModelName = refModelRecords[0].name;
|
|
@@ -2106,8 +1751,7 @@ class ModelProperty {
|
|
|
2106
1751
|
}
|
|
2107
1752
|
}
|
|
2108
1753
|
if (schemaName) {
|
|
2109
|
-
const
|
|
2110
|
-
const schema = Schema.create(schemaName, { waitForReady: false });
|
|
1754
|
+
const schema = Schema.Schema.create(schemaName, { waitForReady: false });
|
|
2111
1755
|
const snapshot = schema.getService().getSnapshot();
|
|
2112
1756
|
const schemaContext = snapshot.context;
|
|
2113
1757
|
if (schemaContext.models?.[modelName]?.properties?.[propertyName]) {
|
|
@@ -2133,8 +1777,4 @@ var ModelProperty$1 = /*#__PURE__*/Object.freeze({
|
|
|
2133
1777
|
});
|
|
2134
1778
|
|
|
2135
1779
|
exports.ModelProperty = ModelProperty;
|
|
2136
|
-
|
|
2137
|
-
exports.convertPropertyToSchemaUpdate = convertPropertyToSchemaUpdate;
|
|
2138
|
-
exports.updateModelProperties = updateModelProperties;
|
|
2139
|
-
exports.writeFullSchemaNewVersion = writeFullSchemaNewVersion;
|
|
2140
|
-
//# sourceMappingURL=ModelProperty-BRKRREYP.js.map
|
|
1780
|
+
//# sourceMappingURL=ModelProperty-B4pV91tc.js.map
|