@seedprotocol/sdk 0.7.5 → 0.7.6-next.957.g6bb7768
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 +2 -2
- package/dist/{ClientManager-DRf4uuei.js → ClientManager-D6YA20jP.js} +207 -149
- package/dist/ClientManager-D6YA20jP.js.map +1 -0
- package/dist/{Item-DTJPMjFk.js → Item-B1MH0tXx.js} +126 -86
- package/dist/Item-B1MH0tXx.js.map +1 -0
- package/dist/{ModelProperty-Dto5C0om.js → ModelProperty-Dw6dHdu_.js} +37 -37
- package/dist/{ModelProperty-Dto5C0om.js.map → ModelProperty-Dw6dHdu_.js.map} +1 -1
- package/dist/{Schema-8DxGcORY.js → Schema-DppObO6h.js} +62 -212
- package/dist/Schema-DppObO6h.js.map +1 -0
- package/dist/{SchemaValidationService-CE92y1TT.js → SchemaValidationService-DXQ-D531.js} +6 -6
- package/dist/{SchemaValidationService-CE92y1TT.js.map → SchemaValidationService-DXQ-D531.js.map} +1 -1
- package/dist/{backfillMetadataPropertyIds-CRqp-BqX.js → backfillMetadataPropertyIds-Uhzlwg9X.js} +3 -3
- package/dist/{backfillMetadataPropertyIds-CRqp-BqX.js.map → backfillMetadataPropertyIds-Uhzlwg9X.js.map} +1 -1
- package/dist/configurePlatform-CVoh3JeR.js +81 -0
- package/dist/configurePlatform-CVoh3JeR.js.map +1 -0
- package/dist/{detachRowsBeforeDelete-BVetHtn2.js → detachRowsBeforeDelete-CtmIFpgV.js} +2 -2
- package/dist/{detachRowsBeforeDelete-BVetHtn2.js.map → detachRowsBeforeDelete-CtmIFpgV.js.map} +1 -1
- package/dist/{discardNewDraft-CEOouygG.js → discardNewDraft-oGYdB5vS.js} +5 -5
- package/dist/{discardNewDraft-CEOouygG.js.map → discardNewDraft-oGYdB5vS.js.map} +1 -1
- package/dist/dist/ClientManager-D6YA20jP.d.ts +933 -0
- package/dist/dist/ClientManager-D6YA20jP.d.ts.map +1 -0
- package/dist/dist/Item-B1MH0tXx.d.ts +898 -0
- package/dist/dist/Item-B1MH0tXx.d.ts.map +1 -0
- package/dist/dist/ModelProperty-Dw6dHdu_.d.ts +315 -0
- package/dist/dist/ModelProperty-Dw6dHdu_.d.ts.map +1 -0
- package/dist/dist/Schema-DppObO6h.d.ts +601 -0
- package/dist/dist/Schema-DppObO6h.d.ts.map +1 -0
- package/dist/dist/SchemaValidationService-DXQ-D531.d.ts +118 -0
- package/dist/dist/SchemaValidationService-DXQ-D531.d.ts.map +1 -0
- package/dist/dist/backfillMetadataPropertyIds-Uhzlwg9X.d.ts +7 -0
- package/dist/dist/backfillMetadataPropertyIds-Uhzlwg9X.d.ts.map +1 -0
- package/dist/dist/configurePlatform-CVoh3JeR.d.ts +30 -0
- package/dist/dist/configurePlatform-CVoh3JeR.d.ts.map +1 -0
- package/dist/dist/detachRowsBeforeDelete-CtmIFpgV.d.ts +13 -0
- package/dist/dist/detachRowsBeforeDelete-CtmIFpgV.d.ts.map +1 -0
- package/dist/dist/discardNewDraft-oGYdB5vS.d.ts +8 -0
- package/dist/dist/discardNewDraft-oGYdB5vS.d.ts.map +1 -0
- package/dist/dist/eas-CSm5wmry.d.ts +12 -0
- package/dist/dist/eas-CSm5wmry.d.ts.map +1 -0
- package/dist/dist/errors-3tc6XkCB.d.ts +487 -0
- package/dist/dist/errors-3tc6XkCB.d.ts.map +1 -0
- package/dist/dist/errors-Do7v6RKu.d.ts +22 -0
- package/dist/dist/errors-Do7v6RKu.d.ts.map +1 -0
- package/dist/dist/getItem-DM3a-7XE.d.ts +6 -0
- package/dist/dist/getItem-DM3a-7XE.d.ts.map +1 -0
- package/dist/dist/getPublishPayload-CJF0k5d8.d.ts +47 -0
- package/dist/dist/getPublishPayload-CJF0k5d8.d.ts.map +1 -0
- package/dist/dist/getPublishUploads-C7-fYIgX.d.ts +89 -0
- package/dist/dist/getPublishUploads-C7-fYIgX.d.ts.map +1 -0
- package/dist/dist/index--mmQ3LQu.d.ts +6 -0
- package/dist/dist/index--mmQ3LQu.d.ts.map +1 -0
- package/dist/dist/index-B7yAoYli.d.ts +2752 -0
- package/dist/dist/index-B7yAoYli.d.ts.map +1 -0
- package/dist/dist/index-CrvIcVFJ.d.ts +4475 -0
- package/dist/dist/index-CrvIcVFJ.d.ts.map +1 -0
- package/dist/dist/index.browser-BmVS-c2C.d.ts +8445 -0
- package/dist/dist/index.browser-BmVS-c2C.d.ts.map +1 -0
- package/dist/dist/index.node-BKpbCAWt.d.ts +11123 -0
- package/dist/dist/index.node-BKpbCAWt.d.ts.map +1 -0
- package/dist/dist/mimeTypes-C9r76DCH.d.ts +30 -0
- package/dist/dist/mimeTypes-C9r76DCH.d.ts.map +1 -0
- package/dist/dist/model-oHA3YhOd.d.ts +6 -0
- package/dist/dist/model-oHA3YhOd.d.ts.map +1 -0
- package/dist/dist/platform.browser.d.ts +3 -0
- package/dist/dist/platform.browser.d.ts.map +1 -0
- package/dist/dist/platform.node.d.ts +3 -0
- package/dist/dist/platform.node.d.ts.map +1 -0
- package/dist/dist/property-DQ-Owzki.d.ts +37 -0
- package/dist/dist/property-DQ-Owzki.d.ts.map +1 -0
- package/dist/dist/propertyValidationRules-BDhFjlwP.d.ts +8 -0
- package/dist/dist/propertyValidationRules-BDhFjlwP.d.ts.map +1 -0
- package/dist/dist/publishDraftGraph-CzPd9oe9.d.ts +76 -0
- package/dist/dist/publishDraftGraph-CzPd9oe9.d.ts.map +1 -0
- package/dist/dist/resetAmbiguousLegacyItemData-cXZm4NuG.d.ts +17 -0
- package/dist/dist/resetAmbiguousLegacyItemData-cXZm4NuG.d.ts.map +1 -0
- package/dist/dist/resolveModelForSyncedSeed-BgxtVCHI.d.ts +21 -0
- package/dist/dist/resolveModelForSyncedSeed-BgxtVCHI.d.ts.map +1 -0
- package/dist/dist/syncDbWithEas-Y5GysSCm.d.ts +22 -0
- package/dist/dist/syncDbWithEas-Y5GysSCm.d.ts.map +1 -0
- package/dist/dist/tabEvents-D9x26vf2.d.ts +81 -0
- package/dist/dist/tabEvents-D9x26vf2.d.ts.map +1 -0
- package/dist/dist/tolerantWebAccess-BFU2t-SC.d.ts +113 -0
- package/dist/dist/tolerantWebAccess-BFU2t-SC.d.ts.map +1 -0
- package/dist/dist/updateSeedRevokedAt-CCF8WWYS.d.ts +11 -0
- package/dist/dist/updateSeedRevokedAt-CCF8WWYS.d.ts.map +1 -0
- package/dist/drizzle.js +2 -0
- package/dist/drizzle.js.map +1 -0
- package/dist/{eas-D7jvWMnI.js → eas-CSm5wmry.js} +3 -3
- package/dist/{eas-D7jvWMnI.js.map → eas-CSm5wmry.js.map} +1 -1
- package/dist/{errors-CIrbsN_i.js → errors-3tc6XkCB.js} +81 -36
- package/dist/errors-3tc6XkCB.js.map +1 -0
- package/dist/errors-Do7v6RKu.js +34 -0
- package/dist/errors-Do7v6RKu.js.map +1 -0
- package/dist/{getItem-CxU_kT5W.js → getItem-DM3a-7XE.js} +4 -4
- package/dist/{getItem-CxU_kT5W.js.map → getItem-DM3a-7XE.js.map} +1 -1
- package/dist/{getPublishPayload-DTjOKd3y.js → getPublishPayload-CJF0k5d8.js} +31 -25
- package/dist/getPublishPayload-CJF0k5d8.js.map +1 -0
- package/dist/{getPublishUploads-CVTBo_OV.js → getPublishUploads-C7-fYIgX.js} +6 -6
- package/dist/{getPublishUploads-CVTBo_OV.js.map → getPublishUploads-C7-fYIgX.js.map} +1 -1
- package/dist/{index-CMxEil8T.js → index--mmQ3LQu.js} +8 -8
- package/dist/index--mmQ3LQu.js.map +1 -0
- package/dist/{index-DWK-LOUY.js → index-B7yAoYli.js} +2 -2
- package/dist/index-B7yAoYli.js.map +1 -0
- package/dist/{BasePathResolver-CBTXCMFL.js → index-CrvIcVFJ.js} +304 -285
- package/dist/index-CrvIcVFJ.js.map +1 -0
- package/dist/{index.browser-shRXMeB3.js → index.browser-BmVS-c2C.js} +34 -44
- package/dist/index.browser-BmVS-c2C.js.map +1 -0
- package/dist/{index.node-DAKJNYp5.js → index.node-BKpbCAWt.js} +43 -7
- package/dist/index.node-BKpbCAWt.js.map +1 -0
- package/dist/main.js +23 -24
- package/dist/main.js.map +1 -1
- package/dist/node.js +13 -10
- package/dist/node.js.map +1 -1
- package/dist/platform.browser.js +7 -7
- package/dist/platform.node.js +4 -4
- package/dist/{property-lz9yIpyA.js → property-DQ-Owzki.js} +7 -7
- package/dist/{property-lz9yIpyA.js.map → property-DQ-Owzki.js.map} +1 -1
- package/dist/{propertyValidationRules-LuIwoQoJ.js → propertyValidationRules-BDhFjlwP.js} +10 -10
- package/dist/{propertyValidationRules-LuIwoQoJ.js.map → propertyValidationRules-BDhFjlwP.js.map} +1 -1
- package/dist/{publishDraftGraph-CgSLPKvQ.js → publishDraftGraph-CzPd9oe9.js} +41 -8
- package/dist/publishDraftGraph-CzPd9oe9.js.map +1 -0
- package/dist/{resetAmbiguousLegacyItemData-CuamkAAh.js → resetAmbiguousLegacyItemData-cXZm4NuG.js} +2 -2
- package/dist/{resetAmbiguousLegacyItemData-CuamkAAh.js.map → resetAmbiguousLegacyItemData-cXZm4NuG.js.map} +1 -1
- package/dist/{resolveModelForSyncedSeed-BbSctSvz.js → resolveModelForSyncedSeed-BgxtVCHI.js} +2 -2
- package/dist/{resolveModelForSyncedSeed-BbSctSvz.js.map → resolveModelForSyncedSeed-BgxtVCHI.js.map} +1 -1
- package/dist/src/Item/Item.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/initialize.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/saveValueToDb/analyzeInput.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/saveValueToDb/rowContext.d.ts +10 -0
- package/dist/src/ItemProperty/service/actors/saveValueToDb/rowContext.d.ts.map +1 -0
- package/dist/src/ItemProperty/service/actors/saveValueToDb/saveFile.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/saveValueToDb/saveHtml.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/saveValueToDb/saveImage.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/saveValueToDb/saveItemStorage.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/propertyMachine.d.ts +20 -20
- package/dist/src/Model/Model.d.ts +8 -0
- package/dist/src/Model/Model.d.ts.map +1 -1
- package/dist/src/ModelProperty/ModelProperty.d.ts +1 -1
- package/dist/src/ModelProperty/service/modelPropertyMachine.d.ts +3 -3
- package/dist/src/Schema/service/actors/checkExistingSchema.d.ts.map +1 -1
- package/dist/src/Schema/service/actors/loadOrCreateSchema.d.ts.map +1 -1
- package/dist/src/Schema/service/actors/writeModelsToDb.d.ts.map +1 -1
- package/dist/src/browser/db/Db.d.ts.map +1 -1
- package/dist/src/browser/helpers/ArweaveClient.d.ts.map +1 -1
- package/dist/src/client/actors/addModelsToDb.d.ts.map +1 -1
- package/dist/src/client/actors/platformClassesInit.d.ts +1 -7
- package/dist/src/client/actors/platformClassesInit.d.ts.map +1 -1
- package/dist/src/client/actors/saveAppState.d.ts.map +1 -1
- package/dist/src/client/actors/saveConfig.d.ts.map +1 -1
- package/dist/src/client/seedConfigDefaults.d.ts +10 -0
- package/dist/src/client/seedConfigDefaults.d.ts.map +1 -0
- package/dist/src/db/read/getPublishPayload.d.ts.map +1 -1
- package/dist/src/db/write/updateItemPropertyValue.d.ts +6 -0
- package/dist/src/db/write/updateItemPropertyValue.d.ts.map +1 -1
- package/dist/src/drizzle/index.d.ts +7 -0
- package/dist/src/drizzle/index.d.ts.map +1 -0
- package/dist/src/events/files/download.d.ts.map +1 -1
- package/dist/src/events/item/syncDbWithEas.d.ts.map +1 -1
- package/dist/src/helpers/FileManager/errors.d.ts +11 -0
- package/dist/src/helpers/FileManager/errors.d.ts.map +1 -1
- package/dist/src/helpers/db.d.ts +14 -0
- package/dist/src/helpers/db.d.ts.map +1 -1
- package/dist/src/helpers/dotSeedPath.d.ts +7 -0
- package/dist/src/helpers/dotSeedPath.d.ts.map +1 -0
- package/dist/src/helpers/entity/entityLiveQuery.d.ts.map +1 -1
- package/dist/src/helpers/environment.d.ts +5 -0
- package/dist/src/helpers/environment.d.ts.map +1 -1
- package/dist/src/helpers/getSegmentedItemProperties.d.ts.map +1 -1
- package/dist/src/helpers/metadataPropertyNames.d.ts +10 -0
- package/dist/src/helpers/metadataPropertyNames.d.ts.map +1 -1
- package/dist/src/helpers/reconcilePropertyDraftRows.d.ts +9 -0
- package/dist/src/helpers/reconcilePropertyDraftRows.d.ts.map +1 -0
- package/dist/src/helpers/updateSchema.d.ts.map +1 -1
- package/dist/src/imports/index.d.ts +1 -1
- package/dist/src/imports/index.d.ts.map +1 -1
- package/dist/src/imports/json.d.ts +18 -5
- package/dist/src/imports/json.d.ts.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/node/helpers/resolveFilesDir.d.ts +8 -0
- package/dist/src/node/helpers/resolveFilesDir.d.ts.map +1 -0
- package/dist/src/node/webpack/index.d.ts +2 -0
- package/dist/src/node/webpack/index.d.ts.map +1 -1
- package/dist/src/platform/index.browser.d.ts +5 -0
- package/dist/src/platform/index.browser.d.ts.map +1 -1
- package/dist/src/platform/index.node.d.ts +1 -0
- package/dist/src/platform/index.node.d.ts.map +1 -1
- package/dist/src/stores/eas.d.ts +1 -1
- package/dist/src/stores/eas.d.ts.map +1 -1
- package/dist/src/types/import.d.ts +15 -0
- package/dist/src/types/import.d.ts.map +1 -1
- package/dist/src/types/index.d.ts +8 -4
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/{syncDbWithEas-CrAY9Rl2.js → syncDbWithEas-Y5GysSCm.js} +17 -13
- package/dist/syncDbWithEas-Y5GysSCm.js.map +1 -0
- package/dist/{tabEvents-BGBYV65P.js → tabEvents-D9x26vf2.js} +4 -4
- package/dist/{tabEvents-BGBYV65P.js.map → tabEvents-D9x26vf2.js.map} +1 -1
- package/dist/{tolerantWebAccess-DVHCEulL.js → tolerantWebAccess-BFU2t-SC.js} +8 -8
- package/dist/{tolerantWebAccess-DVHCEulL.js.map → tolerantWebAccess-BFU2t-SC.js.map} +1 -1
- package/dist/{updateSeedRevokedAt-Dy5J8CfQ.js → updateSeedRevokedAt-CCF8WWYS.js} +3 -3
- package/dist/{updateSeedRevokedAt-Dy5J8CfQ.js.map → updateSeedRevokedAt-CCF8WWYS.js.map} +1 -1
- package/package.json +31 -31
- package/dist/BasePathResolver-CBTXCMFL.js.map +0 -1
- package/dist/ClientManager-DRf4uuei.js.map +0 -1
- package/dist/Item-DTJPMjFk.js.map +0 -1
- package/dist/Schema-8DxGcORY.js.map +0 -1
- package/dist/configurePlatform-D4aGjKNk.js +0 -31
- package/dist/configurePlatform-D4aGjKNk.js.map +0 -1
- package/dist/errors-CIrbsN_i.js.map +0 -1
- package/dist/errors-CrBxGWah.js +0 -17
- package/dist/errors-CrBxGWah.js.map +0 -1
- package/dist/getPublishPayload-DTjOKd3y.js.map +0 -1
- package/dist/index-CMxEil8T.js.map +0 -1
- package/dist/index-DWK-LOUY.js.map +0 -1
- package/dist/index.browser-shRXMeB3.js.map +0 -1
- package/dist/index.node-DAKJNYp5.js.map +0 -1
- package/dist/publishDraftGraph-CgSLPKvQ.js.map +0 -1
- package/dist/src/client/nodeEndpointDefaults.d.ts +0 -8
- package/dist/src/client/nodeEndpointDefaults.d.ts.map +0 -1
- package/dist/syncDbWithEas-CrAY9Rl2.js.map +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { startCase, isEqual } from 'lodash-es';
|
|
2
|
-
import { B as BaseDb, o as easSyncProcesses, I as eventEmitter,
|
|
2
|
+
import { B as BaseDb, o as easSyncProcesses, I as eventEmitter, ac as isBrowser, a1 as isNode, aE as normalizeAddressConfig, aS as isTestOrSeedDev, j as appState, aT as downloadAllFilesRequestHandler, aU as downloadAllFilesBinaryRequestHandler, h as BaseFileManager, t as models$1, s as modelUids, C as seeds, aF as normalizeAddressList, A as schemas, aP as loadModelsFromDbForSchema, aM as addSchemaToDb, aJ as isInternalSchema, ai as generateId, aR as clearNameMatchLevels, aV as warnOnInvalidNameMatch, aW as INTERNAL_SCHEMA_IDS, aX as linkModelToSchema, n as normalizeDataType, ab as easPropertyNameForPublish, au as SEED_PROTOCOL_SCHEMA_NAME, r as modelSchemas, m as metadata$1, v as properties, L as resolveItemModelFileId, F as versions, ae as normalizePublisher, ag as loadNameMatchLevels, p as htmlEmbeddedImageCoPublish, k as arweaveL1FinalizeJobs, z as publishProcesses, aY as getWatchedAddressesFromDb, aZ as getOwnedAddressesFromDb, a_ as CLIENT_NOT_INITIALIZED } from './index-CrvIcVFJ.js';
|
|
3
3
|
import debug from 'debug';
|
|
4
4
|
import { createActor, setup, assign, fromPromise, fromCallback, waitFor } from 'xstate';
|
|
5
|
-
import { u as MachineIds, a0 as ClientManagerEvents, a1 as withLockedItemStorageRow, a2 as getItemStorageFilePath, a3 as writeItemStorageFile, e as compareMetadataRowsLatestFirst, w as writeInBatches, a4 as resolvePublisherFromSeedRow, C as ClientManagerState, G as isLocalUnsealedDraft, s as selectInBatches, I as Item } from './Item-
|
|
5
|
+
import { u as MachineIds, a0 as ClientManagerEvents, a1 as withLockedItemStorageRow, a2 as getItemStorageFilePath, a3 as writeItemStorageFile, e as compareMetadataRowsLatestFirst, w as writeInBatches, a4 as resolvePublisherFromSeedRow, C as ClientManagerState, G as isLocalUnsealedDraft, s as selectInBatches, I as Item } from './Item-B1MH0tXx.js';
|
|
6
6
|
import { eq, inArray, and, isNotNull, ne, desc, countDistinct, isNull, or, sql, like } from 'drizzle-orm';
|
|
7
|
-
import { a as withDbTabLock, i as isLeaderTab, c as postTabMessage, o as onTabMessage, w as whenLeaderTab, l as listenForOtherTabsEvents, s as startTabCoordination, b as withSeedDbLock, e as emitAcrossTabs, A as ADDRESSES_PERSISTED_EVENT, p as parseAddressesPersistedPayload, L as LOCAL_COPIES_REMOVED_EVENT } from './tabEvents-
|
|
7
|
+
import { a as withDbTabLock, i as isLeaderTab, c as postTabMessage, o as onTabMessage, w as whenLeaderTab, l as listenForOtherTabsEvents, s as startTabCoordination, b as withSeedDbLock, e as emitAcrossTabs, A as ADDRESSES_PERSISTED_EVENT, p as parseAddressesPersistedPayload, L as LOCAL_COPIES_REMOVED_EVENT } from './tabEvents-D9x26vf2.js';
|
|
8
8
|
import { seedGatewayConfigFromSeedConfig, setPreferredArweaveReadBaseUrls, resolveSeedGatewayEndpoints, setResolvedSeedGatewayEndpoints, BaseArweaveClient, ensureReadGatewaySelected, DEFAULT_ARWEAVE_HOST } from '@seedprotocol/arweave';
|
|
9
9
|
import { configureEasReadChain, easName, BaseQueryClient, BaseEasClient, GET_SCHEMAS, whenEasReadChainSettled, getEasReadChainId, DEFAULT_EAS_CHAIN_ID, isEasReadChainConfigured, isPlaceholderUid, localNamesInBestMatchTier, isValidEasAttestationUid } from '@seedprotocol/eas';
|
|
10
10
|
import 'pluralize';
|
|
@@ -212,7 +212,7 @@ function toRunSyncArg(options) {
|
|
|
212
212
|
return undefined;
|
|
213
213
|
}
|
|
214
214
|
const runEasSync = fromPromise(async ({ input, }) => {
|
|
215
|
-
const { runSyncFromEas } = await import('./syncDbWithEas-
|
|
215
|
+
const { runSyncFromEas } = await import('./syncDbWithEas-Y5GysSCm.js');
|
|
216
216
|
// Sync checks for rows and then inserts the rest (no unique index on uids), so syncs in
|
|
217
217
|
// different tabs take turns. A sync can run for minutes, so wait without a timeout.
|
|
218
218
|
await withDbTabLock('eas-sync', async () => {
|
|
@@ -542,39 +542,28 @@ const setupServiceHandlers = () => {
|
|
|
542
542
|
eventEmitter.addListener('service.save', saveServiceHandler);
|
|
543
543
|
};
|
|
544
544
|
|
|
545
|
+
/** `filesDir` when the config sets neither it nor `endpoints.files`. */
|
|
546
|
+
const DEFAULT_FILES_DIR = '.seed';
|
|
545
547
|
/**
|
|
546
|
-
*
|
|
547
|
-
*
|
|
548
|
-
*
|
|
548
|
+
* Fills `filesDir` and `endpoints` so `client.init` can be called with neither. `filesDir` falls
|
|
549
|
+
* back to `endpoints.files`, then to {@link DEFAULT_FILES_DIR}. The endpoint labels have no consumer
|
|
550
|
+
* besides that fallback and the copy saved in `app_state`, so missing ones take `filesDir`.
|
|
549
551
|
*/
|
|
550
|
-
function
|
|
552
|
+
function applySeedConfigDefaults(config) {
|
|
551
553
|
if (!config)
|
|
552
554
|
return config;
|
|
553
555
|
const endpoints = config.endpoints;
|
|
554
556
|
if (endpoints?.filePaths && endpoints?.files)
|
|
555
557
|
return config;
|
|
556
|
-
|
|
557
|
-
return config;
|
|
558
|
-
const filesDir = config.filesDir;
|
|
559
|
-
if (!filesDir)
|
|
560
|
-
return config;
|
|
558
|
+
const filesDir = config.filesDir || endpoints?.files || DEFAULT_FILES_DIR;
|
|
561
559
|
const next = {
|
|
562
560
|
filePaths: endpoints?.filePaths || filesDir,
|
|
563
561
|
files: endpoints?.files || filesDir,
|
|
564
562
|
};
|
|
565
|
-
return { ...config, endpoints: next };
|
|
563
|
+
return { ...config, filesDir, endpoints: next };
|
|
566
564
|
}
|
|
567
565
|
|
|
568
566
|
const logger$e = debug('seedSdk:ClientManager:initialize');
|
|
569
|
-
/**
|
|
570
|
-
* Whether a relative filesDir already names the .seed directory or a path inside
|
|
571
|
-
* it ('.seed', '.seed/files', './.seed/files'). '.seed-alt/x' is not: it is
|
|
572
|
-
* resolved under .seed like any other relative path.
|
|
573
|
-
*/
|
|
574
|
-
function isUnderDotSeed(relativePath) {
|
|
575
|
-
const firstSegment = relativePath.split(/[\\/]+/).find((segment) => segment !== '' && segment !== '.');
|
|
576
|
-
return firstSegment === '.seed';
|
|
577
|
-
}
|
|
578
567
|
const platformClassesInit = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
579
568
|
logger$e('initialize from ClientManager');
|
|
580
569
|
const { isInitialized } = context;
|
|
@@ -586,10 +575,6 @@ const platformClassesInit = fromCallback(({ sendBack, input: { context, event }
|
|
|
586
575
|
sendBack({ type: 'initialized' });
|
|
587
576
|
return;
|
|
588
577
|
}
|
|
589
|
-
// Validate synchronously before starting async operations
|
|
590
|
-
// This ensures errors are handled immediately, preventing unhandled rejections
|
|
591
|
-
const { config } = options;
|
|
592
|
-
const { endpoints } = config || {};
|
|
593
578
|
// Track if the operation is cancelled
|
|
594
579
|
let cancelled = false;
|
|
595
580
|
// Create a promise that will handle validation errors immediately
|
|
@@ -601,21 +586,22 @@ const platformClassesInit = fromCallback(({ sendBack, input: { context, event }
|
|
|
601
586
|
return;
|
|
602
587
|
}
|
|
603
588
|
const { addresses } = options;
|
|
604
|
-
const config =
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
// platform imports so source/vitest resolution stays reliable.
|
|
612
|
-
const { configurePlatform } = await import('./configurePlatform-D4aGjKNk.js');
|
|
589
|
+
const config = applySeedConfigDefaults(options.config);
|
|
590
|
+
if (!config) {
|
|
591
|
+
throw new Error('client.init requires a config');
|
|
592
|
+
}
|
|
593
|
+
const _mod_0 = await import('./configurePlatform-CVoh3JeR.js');
|
|
594
|
+
const _ns_0 = _mod_0.a;
|
|
595
|
+
const { configurePlatform } = _ns_0;
|
|
613
596
|
if (isBrowser()) {
|
|
614
597
|
const { createPlatformServices } = await import('./platform.browser.js');
|
|
615
598
|
configurePlatform(createPlatformServices());
|
|
616
599
|
}
|
|
617
600
|
else if (isNode()) {
|
|
618
|
-
|
|
601
|
+
// `#seed-node-platform` (package.json `imports`) maps to the browser platform under
|
|
602
|
+
// the `browser` condition, so browser bundles never contain the Node platform
|
|
603
|
+
// (libsql, node:fs). A relative import here would ship it to every browser app.
|
|
604
|
+
const { createPlatformServices } = await import('#seed-node-platform');
|
|
619
605
|
configurePlatform(createPlatformServices());
|
|
620
606
|
}
|
|
621
607
|
else {
|
|
@@ -642,45 +628,15 @@ const platformClassesInit = fromCallback(({ sendBack, input: { context, event }
|
|
|
642
628
|
const resolvedGateway = await resolveSeedGatewayEndpoints(gatewayConfig);
|
|
643
629
|
setResolvedSeedGatewayEndpoints(resolvedGateway);
|
|
644
630
|
BaseArweaveClient.setHost(`${resolvedGateway.arweaveProtocol}://${resolvedGateway.arweaveHost}`);
|
|
645
|
-
//
|
|
646
|
-
// Normalize filesDir for Node.js environment
|
|
647
|
-
// In Node.js, filesDir should be resolved relative to .seed directory at project root
|
|
631
|
+
// filesDir falls back to endpoints.files (applySeedConfigDefaults fills both)
|
|
648
632
|
let normalizedFilesDir = filesDir || endpoints?.files;
|
|
649
633
|
// jsdom (and any env with both Node + window) is "browser" for SDK: PathResolver is OPFS/virtual.
|
|
650
634
|
// Do not run real fs against those paths (e.g. mkdir '/.seed').
|
|
651
635
|
if (isNode() && !isBrowser() && normalizedFilesDir) {
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
const dotSeedDir = BasePathResolver.getDotSeedDir();
|
|
657
|
-
// Check if filesDir is a browser OPFS-style path (absolute path starting with '/'
|
|
658
|
-
// that is a simple single-level path like '/app-files', not a real filesystem path)
|
|
659
|
-
// Browser OPFS paths are typically simple like '/app-files', '/files', etc.
|
|
660
|
-
const pathWithoutLeadingSlash = normalizedFilesDir.slice(1);
|
|
661
|
-
const isBrowserOpfsPath = path.isAbsolute(normalizedFilesDir) &&
|
|
662
|
-
normalizedFilesDir.startsWith('/') &&
|
|
663
|
-
pathWithoutLeadingSlash.length > 0 &&
|
|
664
|
-
!pathWithoutLeadingSlash.includes('/') && // Single directory name, no subdirectories
|
|
665
|
-
!fs.existsSync(normalizedFilesDir); // Doesn't exist on filesystem
|
|
666
|
-
if (isBrowserOpfsPath) {
|
|
667
|
-
// Convert browser OPFS path to .seed subdirectory
|
|
668
|
-
// e.g., '/app-files' -> '.seed/app-files'
|
|
669
|
-
const dirName = normalizedFilesDir.slice(1) || 'app-files';
|
|
670
|
-
normalizedFilesDir = path.join(dotSeedDir, dirName);
|
|
671
|
-
}
|
|
672
|
-
else if (!path.isAbsolute(normalizedFilesDir)) {
|
|
673
|
-
// If it's a relative path, check if it is already under .seed
|
|
674
|
-
if (isUnderDotSeed(normalizedFilesDir)) {
|
|
675
|
-
// Already relative to project root, resolve it
|
|
676
|
-
normalizedFilesDir = path.resolve(normalizedFilesDir);
|
|
677
|
-
}
|
|
678
|
-
else {
|
|
679
|
-
// Resolve relative to .seed directory
|
|
680
|
-
normalizedFilesDir = path.join(dotSeedDir, normalizedFilesDir);
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
// If it's an absolute path that exists or is a valid filesystem path, use it as-is
|
|
636
|
+
// Lives in the Node platform so browser bundles (and Next.js server builds, which
|
|
637
|
+
// alias it to the browser platform) carry no fs code with computed paths.
|
|
638
|
+
const { resolveFilesDir } = await import('#seed-node-platform');
|
|
639
|
+
normalizedFilesDir = resolveFilesDir(normalizedFilesDir);
|
|
684
640
|
}
|
|
685
641
|
const normalizedAddresses = normalizeAddressConfig(addresses);
|
|
686
642
|
sendBack({ type: 'updateContext', context: {
|
|
@@ -754,7 +710,7 @@ const saveAppState = fromCallback(({ sendBack, input: { key, value } }) => {
|
|
|
754
710
|
const appDb = BaseDb.getAppDb();
|
|
755
711
|
if (!appDb) {
|
|
756
712
|
// In test environments, continue anyway
|
|
757
|
-
if (
|
|
713
|
+
if (isTestOrSeedDev()) {
|
|
758
714
|
logger$d('[client/actors] [saveAppState] App DB not found, but continuing in test environment');
|
|
759
715
|
return;
|
|
760
716
|
}
|
|
@@ -776,7 +732,7 @@ const saveAppState = fromCallback(({ sendBack, input: { key, value } }) => {
|
|
|
776
732
|
catch (error) {
|
|
777
733
|
logger$d('[client/actors] [saveAppState] Error saving app state:', error);
|
|
778
734
|
// In test environments, continue anyway
|
|
779
|
-
if (
|
|
735
|
+
if (isTestOrSeedDev()) {
|
|
780
736
|
logger$d('[client/actors] [saveAppState] Continuing despite error in test environment');
|
|
781
737
|
return;
|
|
782
738
|
}
|
|
@@ -794,7 +750,7 @@ const saveAppState = fromCallback(({ sendBack, input: { key, value } }) => {
|
|
|
794
750
|
.catch((error) => {
|
|
795
751
|
logger$d('[client/actors] [saveAppState] Error in promise chain:', error);
|
|
796
752
|
// In test environments, still send success to allow state machine to progress
|
|
797
|
-
if (
|
|
753
|
+
if (isTestOrSeedDev()) {
|
|
798
754
|
logger$d('[client/actors] [saveAppState] Sending success despite error in test environment');
|
|
799
755
|
sendBack({
|
|
800
756
|
type: 'saveAppStateSuccess',
|
|
@@ -1051,7 +1007,7 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
1051
1007
|
}
|
|
1052
1008
|
}
|
|
1053
1009
|
catch (error) {
|
|
1054
|
-
if (
|
|
1010
|
+
if (isTestOrSeedDev()) {
|
|
1055
1011
|
logger$a('[client/actors] [addModelsToDb] Warning: Could not fetch schemas from EAS (background):', error.message);
|
|
1056
1012
|
}
|
|
1057
1013
|
else {
|
|
@@ -1073,7 +1029,7 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
1073
1029
|
.catch((error) => {
|
|
1074
1030
|
logger$a('[client/actors] [addModelsToDb] Error:', error);
|
|
1075
1031
|
// In test environments, still send success to allow initialization to complete
|
|
1076
|
-
if (
|
|
1032
|
+
if (isTestOrSeedDev()) {
|
|
1077
1033
|
logger$a('[client/actors] [addModelsToDb] Continuing despite error in test environment');
|
|
1078
1034
|
sendBack({ type: ClientManagerEvents.ADD_MODELS_TO_DB_SUCCESS });
|
|
1079
1035
|
}
|
|
@@ -1238,7 +1194,7 @@ const saveConfig = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
1238
1194
|
const appDb = BaseDb.getAppDb();
|
|
1239
1195
|
if (!appDb) {
|
|
1240
1196
|
// In test environments, continue anyway
|
|
1241
|
-
if (
|
|
1197
|
+
if (isTestOrSeedDev()) {
|
|
1242
1198
|
logger$8('[internal/actors] [saveConfig] App DB not found, but continuing in test environment');
|
|
1243
1199
|
return;
|
|
1244
1200
|
}
|
|
@@ -1296,7 +1252,7 @@ const saveConfig = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
1296
1252
|
catch (error) {
|
|
1297
1253
|
logger$8('[internal/actors] [saveConfig] Error saving config:', error);
|
|
1298
1254
|
// In test environments, continue anyway
|
|
1299
|
-
if (
|
|
1255
|
+
if (isTestOrSeedDev()) {
|
|
1300
1256
|
logger$8('[internal/actors] [saveConfig] Continuing despite error in test environment');
|
|
1301
1257
|
return;
|
|
1302
1258
|
}
|
|
@@ -1312,7 +1268,7 @@ const saveConfig = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
1312
1268
|
.catch((error) => {
|
|
1313
1269
|
logger$8('[internal/actors] [saveConfig] Error in saveConfig promise chain:', error);
|
|
1314
1270
|
// In test environments, still send success to allow state machine to progress
|
|
1315
|
-
if (
|
|
1271
|
+
if (isTestOrSeedDev()) {
|
|
1316
1272
|
logger$8('[internal/actors] [saveConfig] Sending success despite error in test environment');
|
|
1317
1273
|
sendBack({ type: ClientManagerEvents.SAVE_CONFIG_SUCCESS });
|
|
1318
1274
|
}
|
|
@@ -2023,9 +1979,9 @@ function getRefValueType(prop) {
|
|
|
2023
1979
|
* @returns Promise that resolves when properties are found, or rejects if not found after max retries
|
|
2024
1980
|
*/
|
|
2025
1981
|
const verifyPropertiesPersisted = async (db, modelId, modelName, maxRetries = 10, retryDelay = 100) => {
|
|
2026
|
-
const
|
|
2027
|
-
const
|
|
2028
|
-
const modelSchemaMod =
|
|
1982
|
+
const _mod_1 = await import('./index-CrvIcVFJ.js');
|
|
1983
|
+
const _ns_1 = _mod_1.bd;
|
|
1984
|
+
const modelSchemaMod = _ns_1;
|
|
2029
1985
|
const { properties: propertiesTable } = modelSchemaMod;
|
|
2030
1986
|
const drizzleMod = await import('drizzle-orm');
|
|
2031
1987
|
const { eq } = drizzleMod;
|
|
@@ -2246,17 +2202,11 @@ const transformImportToSchemaFile = (importData, version = 1) => {
|
|
|
2246
2202
|
const parseJsonImportContent = (content) => {
|
|
2247
2203
|
try {
|
|
2248
2204
|
const data = JSON.parse(content);
|
|
2249
|
-
//
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
schemaName = data.metadata?.name;
|
|
2255
|
-
}
|
|
2256
|
-
else {
|
|
2257
|
-
// Minimal format: name is at top level
|
|
2258
|
-
schemaName = data.name;
|
|
2259
|
-
}
|
|
2205
|
+
// Complete schema format keeps the name in metadata.name, minimal format at the top level.
|
|
2206
|
+
// A schema file without $schema (SchemaFileInput) still has metadata.name.
|
|
2207
|
+
const schemaName = data.$schema
|
|
2208
|
+
? data.metadata?.name
|
|
2209
|
+
: (data.name ?? data.metadata?.name);
|
|
2260
2210
|
if (!schemaName) {
|
|
2261
2211
|
throw new Error('Schema name is required (either at top level or in metadata.name)');
|
|
2262
2212
|
}
|
|
@@ -2334,6 +2284,21 @@ const getSchemaFilePath = (workingDir, name, version, schemaFileId) => {
|
|
|
2334
2284
|
const filename = `${schemaFileId}_${sanitizedName}_v${version}.json`;
|
|
2335
2285
|
return path.join(workingDir, filename);
|
|
2336
2286
|
};
|
|
2287
|
+
/** The complete schema stored at filePath, or undefined when it can't be read or isn't complete. */
|
|
2288
|
+
const readCompleteSchemaFile = async (filePath) => {
|
|
2289
|
+
try {
|
|
2290
|
+
const schema = JSON.parse(await BaseFileManager.readFileAsString(filePath));
|
|
2291
|
+
if (!schema.$schema)
|
|
2292
|
+
return undefined;
|
|
2293
|
+
if (schema.models)
|
|
2294
|
+
schema.models = normalizeSchemaModels(schema.models);
|
|
2295
|
+
return schema;
|
|
2296
|
+
}
|
|
2297
|
+
catch (error) {
|
|
2298
|
+
logger$6(`Could not read schema file ${filePath}:`, error);
|
|
2299
|
+
return undefined;
|
|
2300
|
+
}
|
|
2301
|
+
};
|
|
2337
2302
|
/**
|
|
2338
2303
|
* Import a JSON schema file and save it in the full schema file format
|
|
2339
2304
|
* Also converts the JSON models to Model classes and adds them to the database
|
|
@@ -2375,6 +2340,9 @@ function warnOnEasNameCollisions(schemaFile) {
|
|
|
2375
2340
|
return warnings;
|
|
2376
2341
|
}
|
|
2377
2342
|
async function importJsonSchema(importFilePathOrContents, version = 1) {
|
|
2343
|
+
return importSchema(importFilePathOrContents, version, { replaceStoredFile: false });
|
|
2344
|
+
}
|
|
2345
|
+
async function importSchema(importFilePathOrContents, version, options) {
|
|
2378
2346
|
// Determine if we have a file path or file contents
|
|
2379
2347
|
let importData;
|
|
2380
2348
|
let importFilePath;
|
|
@@ -2403,6 +2371,7 @@ async function importJsonSchema(importFilePathOrContents, version = 1) {
|
|
|
2403
2371
|
}
|
|
2404
2372
|
// Use original schema file if available, otherwise transform from import format
|
|
2405
2373
|
let schemaFile;
|
|
2374
|
+
let replacingStoredFile = false;
|
|
2406
2375
|
if (originalSchemaFile) {
|
|
2407
2376
|
schemaFile = originalSchemaFile;
|
|
2408
2377
|
// Normalize models if provided as array (some tools output array format)
|
|
@@ -2416,9 +2385,9 @@ async function importJsonSchema(importFilePathOrContents, version = 1) {
|
|
|
2416
2385
|
// Check DB for existing schema by name+version (same as minimal path)
|
|
2417
2386
|
const db = BaseDb.getAppDb();
|
|
2418
2387
|
if (db) {
|
|
2419
|
-
const
|
|
2420
|
-
const
|
|
2421
|
-
const schemaSchemaMod =
|
|
2388
|
+
const _mod_2 = await import('./index-CrvIcVFJ.js');
|
|
2389
|
+
const _ns_2 = _mod_2.bf;
|
|
2390
|
+
const schemaSchemaMod = _ns_2;
|
|
2422
2391
|
const { schemas: schemasTable } = schemaSchemaMod;
|
|
2423
2392
|
const drizzleMod = await import('drizzle-orm');
|
|
2424
2393
|
const { eq, and, desc } = drizzleMod;
|
|
@@ -2465,16 +2434,23 @@ async function importJsonSchema(importFilePathOrContents, version = 1) {
|
|
|
2465
2434
|
schemaFile.id = await getDeterministicSchemaFileId(schemaFile);
|
|
2466
2435
|
logger$6(`Generated deterministic schema ID for ${schemaFile.metadata.name}:`, schemaFile.id);
|
|
2467
2436
|
}
|
|
2468
|
-
//
|
|
2469
|
-
//
|
|
2437
|
+
// A file with this schemaFileId and version is reused only when its content matches. A pinned id
|
|
2438
|
+
// (one the schema file sets) keeps the same path when the content changes.
|
|
2470
2439
|
const workingDir = BaseFileManager.getWorkingDir();
|
|
2471
|
-
BaseFileManager.getPathModule();
|
|
2472
2440
|
const existingFilePath = getSchemaFilePath(workingDir, schemaFile.metadata.name, schemaFile.version, schemaFile.id);
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2441
|
+
if (await BaseFileManager.pathExists(existingFilePath)) {
|
|
2442
|
+
const storedSchema = await readCompleteSchemaFile(existingFilePath);
|
|
2443
|
+
if (storedSchema && compareSchemaContent(schemaFile, storedSchema)) {
|
|
2444
|
+
logger$6(`Schema file already exists with schemaFileId ${schemaFile.id} and the same content, loading it`);
|
|
2445
|
+
return await loadSchemaFromFile(existingFilePath);
|
|
2446
|
+
}
|
|
2447
|
+
if (!options.replaceStoredFile) {
|
|
2448
|
+
throw new Error(`Schema ${schemaFile.metadata.name} v${schemaFile.version} already exists with different content ` +
|
|
2449
|
+
`(schema id ${schemaFile.id}). Bump the schema's version, or delete the existing file first.`);
|
|
2450
|
+
}
|
|
2451
|
+
console.warn(`[seed] schema ${schemaFile.metadata.name} v${schemaFile.version}: content changed but id ` +
|
|
2452
|
+
`${schemaFile.id} and version did not; replacing the stored schema file. Bump "version" when the schema changes.`);
|
|
2453
|
+
replacingStoredFile = true;
|
|
2478
2454
|
}
|
|
2479
2455
|
// Generate missing model and property IDs.
|
|
2480
2456
|
// Use deterministic IDs (from schema content hash) so addModelsToDb finds existing
|
|
@@ -2501,9 +2477,9 @@ async function importJsonSchema(importFilePathOrContents, version = 1) {
|
|
|
2501
2477
|
// For minimal imports: check DB for existing schema before creating new file
|
|
2502
2478
|
const db = BaseDb.getAppDb();
|
|
2503
2479
|
if (db) {
|
|
2504
|
-
const
|
|
2505
|
-
const
|
|
2506
|
-
const schemaSchemaMod =
|
|
2480
|
+
const _mod_3 = await import('./index-CrvIcVFJ.js');
|
|
2481
|
+
const _ns_3 = _mod_3.bf;
|
|
2482
|
+
const schemaSchemaMod = _ns_3;
|
|
2507
2483
|
const { schemas: schemasTable } = schemaSchemaMod;
|
|
2508
2484
|
const drizzleMod = await import('drizzle-orm');
|
|
2509
2485
|
const { eq, and, desc } = drizzleMod;
|
|
@@ -2670,8 +2646,10 @@ async function importJsonSchema(importFilePathOrContents, version = 1) {
|
|
|
2670
2646
|
propertyFileIds.set(modelName, propIds);
|
|
2671
2647
|
}
|
|
2672
2648
|
}
|
|
2673
|
-
// Convert JSON models to Model classes, passing modelFileIds and propertyFileIds so Model instances use correct IDs
|
|
2674
|
-
|
|
2649
|
+
// Convert JSON models to Model classes, passing modelFileIds and propertyFileIds so Model instances use correct IDs.
|
|
2650
|
+
// addModelsToDb below writes their rows; the models adopt them once it has run.
|
|
2651
|
+
const rowsWritten = createRowsWrittenSignal();
|
|
2652
|
+
const modelDefinitions = await createModelsFromJson(importDataForInternal, modelFileIds, propertyFileIds, rowsWritten.promise);
|
|
2675
2653
|
logger$6('loadSchemaFromFile (internal) - modelDefinitions length:', Object.keys(modelDefinitions).length);
|
|
2676
2654
|
// Convert schema file metadata to schema input for database
|
|
2677
2655
|
const schemaInput = {
|
|
@@ -2682,9 +2660,9 @@ async function importJsonSchema(importFilePathOrContents, version = 1) {
|
|
|
2682
2660
|
updatedAt: new Date(schemaFile.metadata.updatedAt).getTime(),
|
|
2683
2661
|
};
|
|
2684
2662
|
// Use dynamic import to break circular dependency
|
|
2685
|
-
const
|
|
2686
|
-
const
|
|
2687
|
-
const dbMod =
|
|
2663
|
+
const _mod_4 = await import('./index-CrvIcVFJ.js');
|
|
2664
|
+
const _ns_4 = _mod_4.bi;
|
|
2665
|
+
const dbMod = _ns_4;
|
|
2688
2666
|
const { addSchemaToDb, addModelsToDb } = dbMod;
|
|
2689
2667
|
// Try to add schema and models to database if database is available
|
|
2690
2668
|
try {
|
|
@@ -2704,13 +2682,13 @@ async function importJsonSchema(importFilePathOrContents, version = 1) {
|
|
|
2704
2682
|
});
|
|
2705
2683
|
// Verify expected models are linked (single attempt - addModelsToDb already confirmed)
|
|
2706
2684
|
const expectedModelNames = Object.keys(schemaFile.models || {});
|
|
2707
|
-
const
|
|
2708
|
-
const
|
|
2709
|
-
const modelSchemaSchemaMod =
|
|
2685
|
+
const _mod_5 = await import('./index-CrvIcVFJ.js');
|
|
2686
|
+
const _ns_5 = _mod_5.bg;
|
|
2687
|
+
const modelSchemaSchemaMod = _ns_5;
|
|
2710
2688
|
const { modelSchemas } = modelSchemaSchemaMod;
|
|
2711
|
-
const
|
|
2712
|
-
const
|
|
2713
|
-
const modelSchemaMod =
|
|
2689
|
+
const _mod_6 = await import('./index-CrvIcVFJ.js');
|
|
2690
|
+
const _ns_6 = _mod_6.bd;
|
|
2691
|
+
const modelSchemaMod = _ns_6;
|
|
2714
2692
|
const { models: modelsTable } = modelSchemaMod;
|
|
2715
2693
|
const drizzleMod = await import('drizzle-orm');
|
|
2716
2694
|
const { eq, and, isNull } = drizzleMod;
|
|
@@ -2800,6 +2778,9 @@ async function importJsonSchema(importFilePathOrContents, version = 1) {
|
|
|
2800
2778
|
// Database not available - log warning but continue
|
|
2801
2779
|
logger$6('Database not available, skipping database operations:', dbError instanceof Error ? dbError.message : String(dbError));
|
|
2802
2780
|
}
|
|
2781
|
+
finally {
|
|
2782
|
+
rowsWritten.settle();
|
|
2783
|
+
}
|
|
2803
2784
|
// Models are now Model instances, no registration needed
|
|
2804
2785
|
// They should be created via Model.create() and are accessible via Model static methods
|
|
2805
2786
|
for (const [modelName] of Object.entries(modelDefinitions)) {
|
|
@@ -2819,7 +2800,7 @@ async function importJsonSchema(importFilePathOrContents, version = 1) {
|
|
|
2819
2800
|
// Get the target file path using ID-based naming (preferred)
|
|
2820
2801
|
const filePath = getSchemaFilePath(workingDir, schemaFile.metadata.name, version, schemaFile.id);
|
|
2821
2802
|
// Check if schema already exists
|
|
2822
|
-
const exists = await BaseFileManager.pathExists(filePath);
|
|
2803
|
+
const exists = !replacingStoredFile && (await BaseFileManager.pathExists(filePath));
|
|
2823
2804
|
if (exists) {
|
|
2824
2805
|
// If we have a file path and the import file is the same as the target file,
|
|
2825
2806
|
// and it's already a complete schema, just load it without writing
|
|
@@ -2907,15 +2888,16 @@ async function applySchemaToDb(schemaFile, modelDefinitions, modelFileIds, prope
|
|
|
2907
2888
|
createdAt: new Date(schemaFile.metadata.createdAt).getTime(),
|
|
2908
2889
|
updatedAt: new Date(schemaFile.metadata.updatedAt).getTime(),
|
|
2909
2890
|
};
|
|
2910
|
-
const
|
|
2911
|
-
const
|
|
2912
|
-
const dbMod =
|
|
2891
|
+
const _mod_7 = await import('./index-CrvIcVFJ.js');
|
|
2892
|
+
const _ns_7 = _mod_7.bi;
|
|
2893
|
+
const dbMod = _ns_7;
|
|
2913
2894
|
const { addSchemaToDb, addModelsToDb } = dbMod;
|
|
2914
2895
|
const db = BaseDb.getAppDb();
|
|
2915
2896
|
if (!db) {
|
|
2916
2897
|
throw new Error('Database not found');
|
|
2917
2898
|
}
|
|
2918
2899
|
warnOnInvalidNameMatch(schemaFile);
|
|
2900
|
+
const droppedModelNames = await getModelsDroppedFromStoredSchema(db, schemaFile);
|
|
2919
2901
|
const schemaData = JSON.stringify(schemaFile, null, 2);
|
|
2920
2902
|
const schemaRecord = await addSchemaToDb(schemaInput, schemaFile.id, schemaData, false);
|
|
2921
2903
|
if (Object.keys(modelDefinitions).length > 0) {
|
|
@@ -2927,11 +2909,66 @@ async function applySchemaToDb(schemaFile, modelDefinitions, modelFileIds, prope
|
|
|
2927
2909
|
});
|
|
2928
2910
|
await new Promise(resolve => setTimeout(resolve, 200));
|
|
2929
2911
|
}
|
|
2912
|
+
if (droppedModelNames.length > 0 && schemaRecord.id) {
|
|
2913
|
+
await unlinkModelsFromSchema(db, schemaRecord.id, droppedModelNames);
|
|
2914
|
+
}
|
|
2930
2915
|
return { schemaRecord };
|
|
2931
2916
|
}
|
|
2917
|
+
/**
|
|
2918
|
+
* Names of the models the stored published schema of this name has and schemaFile drops. A model
|
|
2919
|
+
* whose id is still in schemaFile was renamed, not dropped. Returns none when the stored row is a
|
|
2920
|
+
* draft (its edits aren't the app's to undo) or a newer version than schemaFile.
|
|
2921
|
+
*/
|
|
2922
|
+
async function getModelsDroppedFromStoredSchema(db, schemaFile) {
|
|
2923
|
+
const _mod_8 = await import('./index-CrvIcVFJ.js');
|
|
2924
|
+
const _ns_8 = _mod_8.bf;
|
|
2925
|
+
const { schemas: schemasTable } = _ns_8;
|
|
2926
|
+
const { eq } = await import('drizzle-orm');
|
|
2927
|
+
const rows = await db
|
|
2928
|
+
.select({ version: schemasTable.version, isDraft: schemasTable.isDraft, schemaData: schemasTable.schemaData })
|
|
2929
|
+
.from(schemasTable)
|
|
2930
|
+
.where(eq(schemasTable.name, schemaFile.metadata.name));
|
|
2931
|
+
if (rows.length === 0 || rows.some((row) => row.isDraft))
|
|
2932
|
+
return [];
|
|
2933
|
+
const stored = rows.reduce((a, b) => (b.version > a.version ? b : a));
|
|
2934
|
+
if (!stored.schemaData || stored.version > schemaFile.version)
|
|
2935
|
+
return [];
|
|
2936
|
+
let storedModels;
|
|
2937
|
+
try {
|
|
2938
|
+
storedModels = normalizeSchemaModels(JSON.parse(stored.schemaData).models ?? {});
|
|
2939
|
+
}
|
|
2940
|
+
catch {
|
|
2941
|
+
return [];
|
|
2942
|
+
}
|
|
2943
|
+
const models = schemaFile.models ?? {};
|
|
2944
|
+
const modelIds = new Set(Object.values(models).map((model) => model.id).filter(Boolean));
|
|
2945
|
+
return Object.entries(storedModels)
|
|
2946
|
+
.filter(([name, model]) => !(name in models) && !(model.id && modelIds.has(model.id)))
|
|
2947
|
+
.map(([name]) => name);
|
|
2948
|
+
}
|
|
2949
|
+
/** Delete the model_schemas rows linking the named models to the schema. The models and their items stay. */
|
|
2950
|
+
async function unlinkModelsFromSchema(db, schemaId, modelNames) {
|
|
2951
|
+
const _mod_9 = await import('./index-CrvIcVFJ.js');
|
|
2952
|
+
const _ns_9 = _mod_9.bg;
|
|
2953
|
+
const { modelSchemas } = _ns_9;
|
|
2954
|
+
const _mod_10 = await import('./index-CrvIcVFJ.js');
|
|
2955
|
+
const _ns_10 = _mod_10.bd;
|
|
2956
|
+
const { models: modelsTable } = _ns_10;
|
|
2957
|
+
const { and, eq, inArray } = await import('drizzle-orm');
|
|
2958
|
+
const links = await db
|
|
2959
|
+
.select({ id: modelSchemas.id })
|
|
2960
|
+
.from(modelSchemas)
|
|
2961
|
+
.innerJoin(modelsTable, eq(modelSchemas.modelId, modelsTable.id))
|
|
2962
|
+
.where(and(eq(modelSchemas.schemaId, schemaId), inArray(modelsTable.name, modelNames)));
|
|
2963
|
+
if (links.length === 0)
|
|
2964
|
+
return;
|
|
2965
|
+
await db.delete(modelSchemas).where(inArray(modelSchemas.id, links.map((link) => link.id)));
|
|
2966
|
+
logger$6(`Unlinked models dropped from the schema (schema id ${schemaId}): ${modelNames.join(', ')}`);
|
|
2967
|
+
}
|
|
2932
2968
|
/**
|
|
2933
2969
|
* Sync a canonical schema from a file path or inlined object to the database.
|
|
2934
|
-
*
|
|
2970
|
+
* A stored schema file with the same id and version but different content is overwritten (with a
|
|
2971
|
+
* warning) instead of reused, and models dropped from the schema are unlinked from it.
|
|
2935
2972
|
* Called automatically at init when config.schema is provided.
|
|
2936
2973
|
*
|
|
2937
2974
|
* @param source - File path (string) or complete SchemaFileFormat object
|
|
@@ -2947,11 +2984,11 @@ async function syncSchemaFromSource(source) {
|
|
|
2947
2984
|
const content = await BaseFileManager.readFileAsString(resolvedPath);
|
|
2948
2985
|
const parsed = JSON.parse(content);
|
|
2949
2986
|
const version = parsed?.version ?? 1;
|
|
2950
|
-
await
|
|
2987
|
+
await importSchema({ contents: content }, version, { replaceStoredFile: true });
|
|
2951
2988
|
}
|
|
2952
2989
|
else {
|
|
2953
2990
|
const version = source.version ?? 1;
|
|
2954
|
-
await
|
|
2991
|
+
await importSchema({ contents: JSON.stringify(source) }, version, { replaceStoredFile: true });
|
|
2955
2992
|
}
|
|
2956
2993
|
}
|
|
2957
2994
|
/**
|
|
@@ -3060,8 +3097,10 @@ const loadSchemaFromFile = async (schemaFilePath) => {
|
|
|
3060
3097
|
propertyFileIds.set(modelName, propIds);
|
|
3061
3098
|
}
|
|
3062
3099
|
}
|
|
3063
|
-
// Convert JSON models to Model classes, passing modelFileIds and propertyFileIds so Model instances use correct IDs
|
|
3064
|
-
|
|
3100
|
+
// Convert JSON models to Model classes, passing modelFileIds and propertyFileIds so Model instances use correct IDs.
|
|
3101
|
+
// applySchemaToDb below writes their rows; the models adopt them once it has run.
|
|
3102
|
+
const rowsWritten = createRowsWrittenSignal();
|
|
3103
|
+
const modelDefinitions = await createModelsFromJson(importData, modelFileIds, propertyFileIds, rowsWritten.promise);
|
|
3065
3104
|
logger$6('loadSchemaFromFile - modelDefinitions length:', Object.keys(modelDefinitions).length);
|
|
3066
3105
|
// Try to add schema and models to database if database is available
|
|
3067
3106
|
try {
|
|
@@ -3074,15 +3113,15 @@ const loadSchemaFromFile = async (schemaFilePath) => {
|
|
|
3074
3113
|
modelName,
|
|
3075
3114
|
jsonPropertiesToSchemaProperties(modelName, modelDef, propertyFileIds.get(modelName)),
|
|
3076
3115
|
]));
|
|
3077
|
-
const { schemaRecord } = await applySchemaToDb(schemaFile, modelDefinitions, modelFileIds, propertyFileIds, propertyDefinitions);
|
|
3116
|
+
const { schemaRecord } = await applySchemaToDb(schemaFile, modelDefinitions, modelFileIds, propertyFileIds, propertyDefinitions).finally(rowsWritten.settle);
|
|
3078
3117
|
// Query the database to get model IDs that were just created
|
|
3079
|
-
const
|
|
3080
|
-
const
|
|
3081
|
-
const modelSchemaSchemaMod =
|
|
3118
|
+
const _mod_11 = await import('./index-CrvIcVFJ.js');
|
|
3119
|
+
const _ns_11 = _mod_11.bg;
|
|
3120
|
+
const modelSchemaSchemaMod = _ns_11;
|
|
3082
3121
|
const { modelSchemas } = modelSchemaSchemaMod;
|
|
3083
|
-
const
|
|
3084
|
-
const
|
|
3085
|
-
const modelSchemaMod =
|
|
3122
|
+
const _mod_12 = await import('./index-CrvIcVFJ.js');
|
|
3123
|
+
const _ns_12 = _mod_12.bd;
|
|
3124
|
+
const modelSchemaMod = _ns_12;
|
|
3086
3125
|
const { models: modelsTable } = modelSchemaMod;
|
|
3087
3126
|
const drizzleMod = await import('drizzle-orm');
|
|
3088
3127
|
const { eq } = drizzleMod;
|
|
@@ -3146,9 +3185,9 @@ const loadSchemaFromFile = async (schemaFilePath) => {
|
|
|
3146
3185
|
// After properties are created (file path), ensure schemaFile has the correct IDs from database
|
|
3147
3186
|
// Query the database to get the actual schemaFileId values that were used
|
|
3148
3187
|
// This ensures schemaData matches what's actually in the database
|
|
3149
|
-
const
|
|
3150
|
-
const
|
|
3151
|
-
const modelSchemaMod2 =
|
|
3188
|
+
const _mod_13 = await import('./index-CrvIcVFJ.js');
|
|
3189
|
+
const _ns_13 = _mod_13.bd;
|
|
3190
|
+
const modelSchemaMod2 = _ns_13;
|
|
3152
3191
|
const { properties: propertiesTable } = modelSchemaMod2;
|
|
3153
3192
|
let schemaFileUpdated = false;
|
|
3154
3193
|
for (const [modelName, modelFileId] of modelFileIds.entries()) {
|
|
@@ -3182,9 +3221,9 @@ const loadSchemaFromFile = async (schemaFilePath) => {
|
|
|
3182
3221
|
// This is important even if nothing changed, to ensure consistency
|
|
3183
3222
|
const updatedSchemaData = JSON.stringify(schemaFile, null, 2);
|
|
3184
3223
|
// Update the schema record in the database with current schemaData
|
|
3185
|
-
const
|
|
3186
|
-
const
|
|
3187
|
-
const schemaSchemaMod =
|
|
3224
|
+
const _mod_14 = await import('./index-CrvIcVFJ.js');
|
|
3225
|
+
const _ns_14 = _mod_14.bf;
|
|
3226
|
+
const schemaSchemaMod = _ns_14;
|
|
3188
3227
|
const { schemas: schemasTable } = schemaSchemaMod;
|
|
3189
3228
|
await db
|
|
3190
3229
|
.update(schemasTable)
|
|
@@ -3203,6 +3242,9 @@ const loadSchemaFromFile = async (schemaFilePath) => {
|
|
|
3203
3242
|
// Database not available - log warning but continue
|
|
3204
3243
|
logger$6('Database not available, skipping database operations:', dbError instanceof Error ? dbError.message : String(dbError));
|
|
3205
3244
|
}
|
|
3245
|
+
finally {
|
|
3246
|
+
rowsWritten.settle();
|
|
3247
|
+
}
|
|
3206
3248
|
// Models are now Model instances, no registration needed
|
|
3207
3249
|
// They should be created via Model.create() and are accessible via Model static methods
|
|
3208
3250
|
for (const [modelName] of Object.entries(modelDefinitions)) {
|
|
@@ -3284,6 +3326,18 @@ const jsonPropertiesToSchemaProperties = (modelName, modelDef, propertyFileIds)
|
|
|
3284
3326
|
}
|
|
3285
3327
|
return convertedProperties;
|
|
3286
3328
|
};
|
|
3329
|
+
/**
|
|
3330
|
+
* For callers of createModelsFromJson that write the models with addModelsToDb: pass `promise` as its
|
|
3331
|
+
* persistedBy and call `settle` once addModelsToDb has run or failed (in a finally). The new models wait
|
|
3332
|
+
* for it, then adopt the rows addModelsToDb wrote; any model it didn't write writes itself.
|
|
3333
|
+
*/
|
|
3334
|
+
const createRowsWrittenSignal = () => {
|
|
3335
|
+
let settle;
|
|
3336
|
+
const promise = new Promise((resolve) => {
|
|
3337
|
+
settle = resolve;
|
|
3338
|
+
});
|
|
3339
|
+
return { promise, settle };
|
|
3340
|
+
};
|
|
3287
3341
|
/**
|
|
3288
3342
|
* Create a Model class from a JSON model definition
|
|
3289
3343
|
* @param modelName - The name of the model
|
|
@@ -3292,10 +3346,11 @@ const jsonPropertiesToSchemaProperties = (modelName, modelDef, propertyFileIds)
|
|
|
3292
3346
|
* @returns A Model class that can be used with the SDK
|
|
3293
3347
|
*/
|
|
3294
3348
|
const createModelFromJson = async (modelName, modelDef, schemaName, modelFileId, // Optional modelFileId from JSON file
|
|
3295
|
-
propertyFileIds
|
|
3296
|
-
|
|
3297
|
-
const
|
|
3298
|
-
const
|
|
3349
|
+
propertyFileIds, // Optional map of property names to their file IDs from the JSON file
|
|
3350
|
+
persistedBy) => {
|
|
3351
|
+
const _mod_15 = await import('./errors-3tc6XkCB.js');
|
|
3352
|
+
const _ns_15 = _mod_15.h;
|
|
3353
|
+
const modelMod = _ns_15;
|
|
3299
3354
|
const { Model } = modelMod;
|
|
3300
3355
|
const convertedProperties = jsonPropertiesToSchemaProperties(modelName, modelDef, propertyFileIds);
|
|
3301
3356
|
// Create Model instance with the definition
|
|
@@ -3312,6 +3367,7 @@ propertyFileIds) => {
|
|
|
3312
3367
|
id: modelFileId, // Also pass as id for backward compatibility
|
|
3313
3368
|
properties: convertedProperties,
|
|
3314
3369
|
waitForReady: false,
|
|
3370
|
+
persistedBy,
|
|
3315
3371
|
});
|
|
3316
3372
|
return modelInstance;
|
|
3317
3373
|
};
|
|
@@ -3320,9 +3376,11 @@ propertyFileIds) => {
|
|
|
3320
3376
|
* @param importData - The JSON import data
|
|
3321
3377
|
* @param modelFileIds - Optional map of model names to their file IDs from the JSON file
|
|
3322
3378
|
* @param propertyFileIds - Optional map of model names to maps of property names to their file IDs from the JSON file
|
|
3379
|
+
* @param persistedBy - When the caller writes the models with addModelsToDb: a promise that settles once
|
|
3380
|
+
* that has run (see createRowsWrittenSignal). New models then adopt those rows instead of writing them too.
|
|
3323
3381
|
* @returns ModelDefinitions object with Model classes
|
|
3324
3382
|
*/
|
|
3325
|
-
const createModelsFromJson = async (importData, modelFileIds, propertyFileIds) => {
|
|
3383
|
+
const createModelsFromJson = async (importData, modelFileIds, propertyFileIds, persistedBy) => {
|
|
3326
3384
|
const modelDefinitions = {};
|
|
3327
3385
|
const schemaName = importData.name;
|
|
3328
3386
|
for (const [modelName, modelDef] of Object.entries(importData.models)) {
|
|
@@ -3335,7 +3393,7 @@ const createModelsFromJson = async (importData, modelFileIds, propertyFileIds) =
|
|
|
3335
3393
|
}
|
|
3336
3394
|
// Get propertyFileIds for this model if available
|
|
3337
3395
|
const modelPropertyFileIds = propertyFileIds?.get(modelName);
|
|
3338
|
-
const ModelClass = await createModelFromJson(modelName, modelDef, schemaName, finalModelFileId, modelPropertyFileIds);
|
|
3396
|
+
const ModelClass = await createModelFromJson(modelName, modelDef, schemaName, finalModelFileId, modelPropertyFileIds, persistedBy);
|
|
3339
3397
|
modelDefinitions[modelName] = ModelClass;
|
|
3340
3398
|
}
|
|
3341
3399
|
return modelDefinitions;
|
|
@@ -5650,5 +5708,5 @@ var ClientManager$1 = /*#__PURE__*/Object.freeze({
|
|
|
5650
5708
|
getClient: getClient
|
|
5651
5709
|
});
|
|
5652
5710
|
|
|
5653
|
-
export { requestEasSyncFromEventBus as A, requestEasSyncFromModelsInit as B, ClientManager as C, sendEasSyncClientRequest as D, EAS_CHAIN_ID_APP_STATE_KEY as E, setRetriesWhenOnlineEnabled as F, startEasSyncActor as G, unregisterSeedQueryLocalSource as H, INIT_CONFIG_CONFLICT_MESSAGE as I,
|
|
5654
|
-
//# sourceMappingURL=ClientManager-
|
|
5711
|
+
export { requestEasSyncFromEventBus as A, requestEasSyncFromModelsInit as B, ClientManager as C, sendEasSyncClientRequest as D, EAS_CHAIN_ID_APP_STATE_KEY as E, setRetriesWhenOnlineEnabled as F, startEasSyncActor as G, unregisterSeedQueryLocalSource as H, INIT_CONFIG_CONFLICT_MESSAGE as I, createRowsWrittenSignal as J, createModelsFromJson as K, getLatestSchemaVersion as L, jsonPropertiesToSchemaProperties as M, schema as N, ClientManager$1 as O, SEEDPROTOCOL_Seed_Protocol_v1 as S, getContentHash as a, isVerbatimItemStorageDraftRow as b, convertVerbatimItemStorageRow as c, assertLocalDbChain as d, claimUnpublishedDrafts as e, createLocalQueryDataSource as f, getRefValueType as g, hardDeleteLocalSeedsByLocalIds as h, importJsonSchema as i, createSchema as j, easSyncActor as k, loadSchemaFromFile as l, getClient as m, getPublishedSeedRecord as n, getSchemaNameFromId as o, isSeedQueryLocalSourceRegistered as p, listCompleteSchemaFiles as q, readJsonImportFile as r, syncSchemaFromSource as s, transformImportToSchemaFile as t, loadAllSchemasFromDb as u, mergeEasSyncRequestIntents as v, waitForEasReadChain as w, readSchema as x, registerSeedQueryLocalSource as y, requestEasSyncFromAddressChange as z };
|
|
5712
|
+
//# sourceMappingURL=ClientManager-D6YA20jP.js.map
|