@seedprotocol/sdk 0.3.19 → 0.3.20
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 +5 -1
- package/dist/addModel.js.map +1 -1
- package/dist/bin.js.map +1 -1
- package/dist/{node.app.db.config.js → node/db/node.app.db.config.js} +1 -1
- package/dist/node/db/node.app.db.config.js.map +1 -0
- package/dist/rpcServer.js.map +1 -1
- package/dist/scripts/vite.config.d.ts +1 -1
- package/dist/src/Item/BaseItem.js.map +1 -1
- package/dist/src/Item/queries.js.map +1 -1
- package/dist/src/Item/service/actors/fetchDataFromEas.js.map +1 -1
- package/dist/src/Item/service/actors/hydrateExistingItem.js.map +1 -1
- package/dist/src/Item/service/actors/hydrateNewItem.js.map +1 -1
- package/dist/src/Item/service/actors/initialize.js.map +1 -1
- package/dist/src/Item/service/actors/reload.js.map +1 -1
- package/dist/src/Item/service/actors/waitForDb.js.map +1 -1
- package/dist/src/Item/service/itemMachineSingle.js.map +1 -1
- package/dist/src/ItemProperty/BaseItemProperty.js.map +1 -1
- package/dist/src/ItemProperty/service/actors/hydrateFromDb.js.map +1 -1
- package/dist/src/ItemProperty/service/actors/initialize.js.map +1 -1
- package/dist/src/ItemProperty/service/actors/resolveRelatedValue.js.map +1 -1
- package/dist/src/ItemProperty/service/actors/resolveRemoteStorage.js.map +1 -1
- package/dist/src/ItemProperty/service/actors/saveValueToDb/analyzeInput.js.map +1 -1
- package/dist/src/ItemProperty/service/actors/saveValueToDb/saveImage.js.map +1 -1
- package/dist/src/ItemProperty/service/actors/saveValueToDb/saveItemStorage.js.map +1 -1
- package/dist/src/ItemProperty/service/actors/saveValueToDb/saveRelation.js.map +1 -1
- package/dist/src/ItemProperty/service/actors/waitForDb.js.map +1 -1
- package/dist/src/ItemProperty/service/propertyMachine.js.map +1 -1
- package/dist/src/browser/Item/Item.js.map +1 -1
- package/dist/src/browser/ItemProperty/ItemProperty.js.map +1 -1
- package/dist/src/browser/db/Db.js.map +1 -1
- package/dist/src/browser/helpers/ArweaveClient.js.map +1 -1
- package/dist/src/browser/helpers/FileManager.js.map +1 -1
- package/dist/src/browser/helpers/QueryClient.js.map +1 -1
- package/dist/src/browser/helpers/eas.js.map +1 -1
- package/dist/src/browser/react/SeedImage.js.map +1 -1
- package/dist/src/browser/react/item.js.map +1 -1
- package/dist/src/browser/react/model.js.map +1 -1
- package/dist/src/browser/react/property.js.map +1 -1
- package/dist/src/browser/react/services.js.map +1 -1
- package/dist/src/browser/react/trash.js.map +1 -1
- package/dist/src/browser/workers/FileDownloader.js.map +1 -1
- package/dist/src/browser/workers/ImageResizer.js.map +1 -1
- package/dist/src/browser/workers/filesDownload.js.map +1 -1
- package/dist/src/browser/workers/imageResize.js.map +1 -1
- package/dist/src/client/ClientManager.js.map +1 -1
- package/dist/src/client/actors/initialize.js.map +1 -1
- package/dist/src/client/actors/saveAppState.js.map +1 -1
- package/dist/src/client/clientManagerMachine.js.map +1 -1
- package/dist/src/db/Db/BaseDb.js.map +1 -1
- package/dist/src/db/configs/seed.schema.config.js.map +1 -1
- package/dist/src/db/read/getExistingItem.js.map +1 -1
- package/dist/src/db/read/getItem.js.map +1 -1
- package/dist/src/db/read/getItemData.js.map +1 -1
- package/dist/src/db/read/getItemProperties.js.map +1 -1
- package/dist/src/db/read/getItemProperty.js.map +1 -1
- package/dist/src/db/read/getItems.js.map +1 -1
- package/dist/src/db/read/getMetadata.js.map +1 -1
- package/dist/src/db/read/getModelSchemas.js.map +1 -1
- package/dist/src/db/read/getModels.js.map +1 -1
- package/dist/src/db/read/getPropertyData.js.map +1 -1
- package/dist/src/db/read/getPublishPayload.d.ts.map +1 -1
- package/dist/src/db/read/getPublishPayload.js +14 -0
- package/dist/src/db/read/getPublishPayload.js.map +1 -1
- package/dist/src/db/read/getPublishUploads.js.map +1 -1
- package/dist/src/db/read/getRelationValueData.js.map +1 -1
- package/dist/src/db/read/getSchemaUidForModel.js.map +1 -1
- package/dist/src/db/read/getSeedData.js.map +1 -1
- package/dist/src/db/read/getStorageTransactionIdForSeedUid.js.map +1 -1
- package/dist/src/db/read/getVersionData.js.map +1 -1
- package/dist/src/db/read/subqueries/metadataLatest.js.map +1 -1
- package/dist/src/db/write/createMetadata.js.map +1 -1
- package/dist/src/db/write/createNewItem.js.map +1 -1
- package/dist/src/db/write/createSeed.js.map +1 -1
- package/dist/src/db/write/createSeeds.js.map +1 -1
- package/dist/src/db/write/createVersion.js.map +1 -1
- package/dist/src/db/write/saveAppState.js.map +1 -1
- package/dist/src/db/write/saveMetadata.js.map +1 -1
- package/dist/src/db/write/updateItemPropertyValue.js.map +1 -1
- package/dist/src/db/write/updateMetadata.js.map +1 -1
- package/dist/src/events/files/download.js.map +1 -1
- package/dist/src/events/files/index.js.map +1 -1
- package/dist/src/events/index.js.map +1 -1
- package/dist/src/events/item/publish.js.map +1 -1
- package/dist/src/events/item/syncDbWithEas.js.map +1 -1
- package/dist/src/events/services/allItems.js.map +1 -1
- package/dist/src/graphql/gql/graphql.js.map +1 -1
- package/dist/src/helpers/ArweaveClient/BaseArweaveClient.js.map +1 -1
- package/dist/src/helpers/ArweaveClient/index.js.map +1 -1
- package/dist/src/helpers/ArweaveClient/queries.js.map +1 -1
- package/dist/src/helpers/EasClient/BaseEasClient.js.map +1 -1
- package/dist/src/helpers/FileManager/BaseFileManager.d.ts.map +1 -1
- package/dist/src/helpers/FileManager/BaseFileManager.js +16 -0
- package/dist/src/helpers/FileManager/BaseFileManager.js.map +1 -1
- package/dist/src/helpers/QueryClient/BaseQueryClient.js.map +1 -1
- package/dist/src/helpers/constants.js.map +1 -1
- package/dist/src/helpers/db.js.map +1 -1
- package/dist/src/helpers/environment.js.map +1 -1
- package/dist/src/helpers/getSchemaForItemProperty.js.map +1 -1
- package/dist/src/helpers/getSegmentedItemProperties.js.map +1 -1
- package/dist/src/helpers/index.js.map +1 -1
- package/dist/src/helpers/scripts.js.map +1 -1
- package/dist/src/helpers/updateMachineContext.js.map +1 -1
- package/dist/src/node/Item/Item.js.map +1 -1
- package/dist/src/node/ItemProperty/ItemProperty.js.map +1 -1
- package/dist/src/node/PathResolver.js +1 -1
- package/dist/src/node/PathResolver.js.map +1 -1
- package/dist/src/node/codegen/drizzle.js.map +1 -1
- package/dist/src/node/db/Db.js.map +1 -1
- package/dist/src/node/helpers/ArweaveClient.js.map +1 -1
- package/dist/src/node/helpers/EasClient.js.map +1 -1
- package/dist/src/node/helpers/FileManager.js.map +1 -1
- package/dist/src/node/helpers/QueryClient.js.map +1 -1
- package/dist/src/node/helpers/index.js.map +1 -1
- package/dist/src/node/webpack/index.js.map +1 -1
- package/dist/src/schema/file/queries.js.map +1 -1
- package/dist/src/schema/image/model.js.map +1 -1
- package/dist/src/schema/model/index.js.map +1 -1
- package/dist/src/schema/property/index.js.map +1 -1
- package/dist/src/seedSchema/AppStateSchema.js.map +1 -1
- package/dist/src/seedSchema/ConfigSchema.js.map +1 -1
- package/dist/src/seedSchema/MetadataSchema.js.map +1 -1
- package/dist/src/seedSchema/ModelSchema.js.map +1 -1
- package/dist/src/seedSchema/ModelUidSchema.js.map +1 -1
- package/dist/src/seedSchema/SeedSchema.js.map +1 -1
- package/dist/src/seedSchema/VersionSchema.js.map +1 -1
- package/dist/src/services/allItems/actors/fetchDbData.js.map +1 -1
- package/dist/src/services/allItems/actors/fetchRelatedItems.js.map +1 -1
- package/dist/src/services/allItems/actors/fetchSeeds.js.map +1 -1
- package/dist/src/services/allItems/actors/fetchVersions.js.map +1 -1
- package/dist/src/services/allItems/actors/initialize.js.map +1 -1
- package/dist/src/services/allItems/actors/processItems.js.map +1 -1
- package/dist/src/services/allItems/itemMachineAll.js.map +1 -1
- package/dist/src/services/db/actors/checkStatus.js.map +1 -1
- package/dist/src/services/db/actors/connectToDb.js.map +1 -1
- package/dist/src/services/db/actors/migrate.js.map +1 -1
- package/dist/src/services/db/actors/validate.js.map +1 -1
- package/dist/src/services/db/actors/waitForFiles.js.map +1 -1
- package/dist/src/services/db/dbMachine.js.map +1 -1
- package/dist/src/services/events.js.map +1 -1
- package/dist/src/services/global/actors/addModelsToDb.js.map +1 -1
- package/dist/src/services/global/actors/getSchemaForModel.js.map +1 -1
- package/dist/src/services/global/actors/initialize.js.map +1 -1
- package/dist/src/services/global/actors/savePublishService.js.map +1 -1
- package/dist/src/services/global/globalMachine.js.map +1 -1
- package/dist/src/services/internal/actors/configureFs.js.map +1 -1
- package/dist/src/services/internal/actors/loadAppDb.js.map +1 -1
- package/dist/src/services/internal/actors/saveConfig.js.map +1 -1
- package/dist/src/services/internal/actors/validateInput.js.map +1 -1
- package/dist/src/services/internal/actors/waitForFiles.js.map +1 -1
- package/dist/src/services/internal/constants.js.map +1 -1
- package/dist/src/services/internal/helpers.js.map +1 -1
- package/dist/src/services/internal/internalMachine.js.map +1 -1
- package/dist/src/services/publish/actors/createPublishAttempt.js.map +1 -1
- package/dist/src/services/publish/actors/preparePublishRequestData.js.map +1 -1
- package/dist/src/services/publish/actors/upload.js.map +1 -1
- package/dist/src/services/publish/actors/validateItemData.js.map +1 -1
- package/dist/src/stores/eas.js.map +1 -1
- package/dist/src/stores/modelClass.js.map +1 -1
- package/package.json +11 -10
- package/dist/node.app.db.config.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseItemProperty.js","sources":["../../../../src/ItemProperty/BaseItemProperty.ts"],"sourcesContent":["import { ActorRefFrom, createActor, SnapshotFrom, Subscription, waitFor } from 'xstate'\nimport { BehaviorSubject, Subscriber } from 'rxjs'\nimport { Static } from '@sinclair/typebox'\nimport { IItemProperty } from '@/interfaces/IItemProperty'\nimport { immerable } from 'immer'\nimport { CreatePropertyInstanceProps, PropertyMachineContext } from '@/types'\nimport { getModel } from '@/stores/modelClass'\nimport { propertyMachine } from './service/propertyMachine'\nimport { INTERNAL_PROPERTY_NAMES } from '@/helpers/constants'\nimport debug from 'debug'\nimport pluralize from 'pluralize'\nimport { getPropertyData } from '@/db/read/getPropertyData'\nimport { BaseFileManager, getCorrectId } from '@/helpers'\nimport { TProperty } from '@/schema'\nimport { eventEmitter } from '@/eventBus'\nimport { getSchemaUidForModel } from '@/db/read/getSchemaUidForModel'\n\n\nconst logger = debug('seedSdk:property:class')\n\ntype ItemPropertyService = ActorRefFrom<typeof propertyMachine>\ntype ItemPropertySnapshot = SnapshotFrom<typeof propertyMachine>\n\ntype ItemPropertyFindProps = {\n propertyName: string\n propertyLocalId?: string\n seedLocalId?: string\n seedUid?: string\n}\n\nexport abstract class BaseItemProperty<PropertyType> implements IItemProperty<PropertyType> {\n protected static instanceCache: Map<\n string,\n { instance: BaseItemProperty<any>; refCount: number }\n > = new Map()\n protected readonly _service: ItemPropertyService\n protected _subject: BehaviorSubject<any>\n protected readonly _isRelation: boolean = false\n protected readonly _isList: boolean = false\n protected readonly _alias: string | undefined\n protected _subscription: Subscription\n protected _dataType: string | undefined\n protected _schemaUid: string | undefined\n [immerable] = true\n\n constructor(initialValues: Partial<CreatePropertyInstanceProps>) {\n const { modelName, propertyName, propertyValue, seedLocalId, seedUid, versionLocalId, versionUid, storageTransactionId, schemaUid } = initialValues\n\n if (!modelName) {\n throw new Error('Model name is required')\n }\n\n const ModelClass = getModel(modelName)\n\n if (!ModelClass) {\n throw new Error(`Model ${modelName} not found`)\n }\n\n if (!propertyName) {\n throw new Error(`Property name not provided`)\n }\n\n const serviceInput: Partial<PropertyMachineContext> = {\n propertyValue,\n propertyName,\n seedLocalId,\n seedUid,\n versionLocalId,\n versionUid,\n modelName,\n storageTransactionId,\n propertyRecordSchema: ModelClass.schema[propertyName],\n schemaUid,\n }\n\n\n\n if (!INTERNAL_PROPERTY_NAMES.includes(propertyName)) {\n let propertyNameWithoutId\n\n if (propertyName.endsWith('Id')) {\n propertyNameWithoutId = propertyName.slice(0, -2)\n }\n\n if (propertyName.endsWith('Ids')) {\n propertyNameWithoutId = propertyName.slice(0, -3)\n propertyNameWithoutId = pluralize(propertyNameWithoutId)\n }\n\n const propertyRecordSchema =\n ModelClass.schema[propertyNameWithoutId || propertyName]\n if (propertyRecordSchema) {\n this._dataType = propertyRecordSchema.dataType\n\n serviceInput.propertyRecordSchema = propertyRecordSchema\n\n if (propertyRecordSchema.dataType === 'Relation') {\n this._isRelation = true\n }\n\n if (\n propertyRecordSchema.dataType === 'List' &&\n propertyRecordSchema.ref\n ) {\n this._isList = true\n this._isRelation = true\n\n if (propertyValue) {\n try {\n serviceInput.propertyValue = JSON.parse(propertyValue)\n } catch (e) {\n logger('List property value is not JSON', e)\n }\n }\n\n const propertyNameSingular = pluralize(propertyName!, 1)\n\n this._alias = propertyName\n\n serviceInput.propertyName = `${propertyNameSingular}${propertyRecordSchema.ref}Ids`\n }\n\n if (!this._alias && propertyNameWithoutId) {\n this._alias = propertyNameWithoutId\n }\n }\n }\n\n serviceInput.isRelation = this._isRelation\n\n this._subject = new BehaviorSubject(propertyValue)\n this._service = createActor(propertyMachine, {\n input: serviceInput,\n })\n\n this._subscription = this._service.subscribe(\n async (snapshot: ItemPropertySnapshot) => {\n if (!snapshot || !snapshot.context) {\n return\n }\n\n const { context } = snapshot\n const { propertyRecordSchema } = context\n\n if (context.seedLocalId) {\n const cacheKey = BaseItemProperty.cacheKey(\n context.seedLocalId,\n context.propertyName,\n )\n if (!BaseItemProperty.instanceCache.has(cacheKey)) {\n BaseItemProperty.instanceCache.set(cacheKey, {\n instance: this,\n refCount: 1,\n })\n }\n }\n\n let renderValue\n\n const isImage =\n propertyRecordSchema &&\n propertyRecordSchema.dataType === 'Image'\n\n const isFile =\n propertyRecordSchema &&\n propertyRecordSchema.dataType === 'File'\n\n const isItemStorage = \n propertyRecordSchema &&\n propertyRecordSchema.storageType &&\n propertyRecordSchema.storageType === 'ItemStorage' &&\n context.refResolvedValue &&\n context.localStorageDir\n\n if (!this._schemaUid && context.schemaUid) {\n this._schemaUid = context.schemaUid\n }\n\n if (\n isImage ||\n isFile ||\n isItemStorage\n ) {\n const filePath = `/files/${context.localStorageDir}/${context.refResolvedValue}`\n try {\n const exists = await BaseFileManager.pathExists(filePath)\n if (exists && isItemStorage) {\n renderValue = await BaseFileManager.readFileAsString(filePath,)\n }\n if (exists && isImage) {\n if (context.refResolvedDisplayValue) {\n renderValue = context.refResolvedDisplayValue\n } \n if (!context.refResolvedDisplayValue) {\n renderValue = await BaseFileManager.getContentUrlFromPath(filePath)\n }\n }\n if (exists && isFile) {\n renderValue = await BaseFileManager.readFileAsString(filePath,)\n }\n if (!exists) {\n renderValue = 'No file found'\n }\n } catch (e) {\n logger(\n `[ItemProperty] [${context.seedLocalId}] [${context.propertyName}] [storageType] error`,\n e,\n )\n renderValue = 'No file found'\n }\n }\n\n if (!renderValue) {\n renderValue = context.renderValue || context.propertyValue\n }\n\n let transformedPropertyName = propertyName\n\n const skipTransform =\n INTERNAL_PROPERTY_NAMES.includes(propertyName) || !!this._alias\n\n if (!skipTransform && transformedPropertyName.endsWith('Id')) {\n transformedPropertyName = transformedPropertyName.slice(0, -2)\n }\n\n if (!skipTransform && transformedPropertyName.endsWith('Ids')) {\n transformedPropertyName = transformedPropertyName.slice(0, -3)\n }\n\n if (skipTransform && this._alias) {\n transformedPropertyName = this._alias\n }\n\n if (skipTransform && !this._alias) {\n }\n\n if (this._subject.value === renderValue) {\n return\n }\n\n this._subject.next(renderValue)\n // TODO: Maybe have this only update the property?\n // if (context.seedLocalId || context.seedUid) {\n // eventEmitter.emit(`property.${context.seedUid || context.seedLocalId}.${propertyName}.update`)\n // }\n // if (context.seedUid) {\n // eventEmitter.emit(`item.${modelName}.${context.seedUid}.update`)\n // }\n },\n )\n\n this._service.start()\n }\n\n static PlatformClass: typeof BaseItemProperty\n\n static setPlatformClass(platformClass: typeof BaseItemProperty) {\n this.PlatformClass = platformClass\n }\n\n static create(\n props: Partial<CreatePropertyInstanceProps>,\n ): BaseItemProperty<any> | undefined {\n const { propertyName, seedLocalId, seedUid, versionLocalId, versionUid } =\n props\n if (!propertyName || (!seedLocalId && !seedUid)) {\n return\n }\n const cacheKey = this.cacheKey(\n (seedUid || seedLocalId) as string,\n propertyName,\n )\n if (seedLocalId && propertyName) {\n if (this.instanceCache.has(cacheKey)) {\n const { instance, refCount } = this.instanceCache.get(cacheKey)!\n this.instanceCache.set(cacheKey, {\n instance,\n refCount: refCount + 1,\n })\n return instance\n }\n if (!this.instanceCache.has(cacheKey)) {\n const newInstance = new this(props)\n this.instanceCache.set(cacheKey, {\n instance: newInstance,\n refCount: 1,\n })\n return newInstance\n }\n }\n if (seedUid && propertyName) {\n if (this.instanceCache.has(cacheKey)) {\n const { instance, refCount } = this.instanceCache.get(cacheKey)!\n this.instanceCache.set(cacheKey, { instance, refCount: refCount + 1 })\n return instance\n }\n if (!this.instanceCache.has(cacheKey)) {\n const newInstance = new this(props)\n this.instanceCache.set(cacheKey, { instance: newInstance, refCount: 1 })\n return newInstance\n }\n }\n return new this(props)\n }\n\n static async find({\n propertyName,\n seedLocalId,\n seedUid,\n }: ItemPropertyFindProps): Promise<IItemProperty<any> | undefined> {\n if ((!seedLocalId && !seedUid) || !propertyName) {\n return\n }\n const cacheKeyId = seedUid || seedLocalId\n const cacheKey = BaseItemProperty.cacheKey(cacheKeyId!, propertyName)\n if (this.instanceCache.has(cacheKey)) {\n const { instance, refCount } = this.instanceCache.get(cacheKey)!\n this.instanceCache.set(cacheKey, {\n instance,\n refCount: refCount + 1,\n })\n return instance\n }\n const propertyData = await getPropertyData({\n propertyName,\n seedLocalId,\n seedUid,\n })\n if (!propertyData) {\n return\n }\n return BaseItemProperty.create(propertyData)\n }\n\n static cacheKey(seedLocalIdOrUid: string, propertyName: string): string {\n const { uid, localId } = getCorrectId(seedLocalIdOrUid)\n return `Item_${uid || localId}_${propertyName}`\n }\n\n getService() {\n return this._service\n }\n\n private _getSnapshot(): ItemPropertySnapshot {\n return this._service.getSnapshot() as ItemPropertySnapshot\n }\n\n private _getSnapshotContext(): PropertyMachineContext {\n return this._getSnapshot().context\n }\n\n get localId() {\n return this._getSnapshotContext().localId\n }\n\n get uid() {\n return this._getSnapshotContext().uid\n }\n\n get seedLocalId() {\n return this._getSnapshotContext().seedLocalId\n }\n\n get seedUid() {\n return this._getSnapshotContext().seedUid\n }\n\n get schemaUid() {\n return this._getSnapshotContext().schemaUid\n }\n\n get propertyName() {\n if (this._alias) {\n return this._alias\n }\n return this._getSnapshotContext().propertyName\n }\n\n get modelName() {\n return this._getSnapshotContext().modelName\n }\n\n get propertyDef(): Static<typeof TProperty> | undefined {\n return this._getSnapshotContext().propertyRecordSchema\n }\n\n get localStorageDir(): string | void {\n if (this.propertyDef && this.propertyDef.localStorageDir) {\n return this.propertyDef.localStorageDir\n }\n if (this._getSnapshot().context.localStorageDir) {\n return this._getSnapshot().context.localStorageDir\n }\n }\n\n get refResolvedValue(): string | undefined {\n return this._getSnapshotContext().refResolvedValue\n }\n\n get localStoragePath(): string | void {\n if (this.localStorageDir) {\n return `/files${this.localStorageDir}/${this.refResolvedValue}`\n }\n }\n\n get versionLocalId(): string | undefined {\n return this._getSnapshotContext().versionLocalId\n }\n\n get status() {\n return this._getSnapshot().value\n }\n\n get alias() {\n return this._alias\n }\n\n get value() {\n // logger(\n // `[XXXXXXXXXX] [value] [get] subjectValue: ${this._subject.value} serviceValue: ${this._service.getSnapshot().context.renderValue}`,\n // )\n if (this._dataType === 'Image') {\n return this._getSnapshot().context.refResolvedValue\n }\n return this._subject.value\n }\n\n set value(value: any) {\n if (this._subject.value === value) {\n return\n }\n const context = this._service.getSnapshot().context\n if (!context.propertyRecordSchema) {\n this._subject.next(value)\n }\n this._service.send({\n type: 'save',\n newValue: value,\n })\n }\n\n get published(): boolean {\n return !!this._getSnapshot().context.uid\n }\n\n subscribe(callback: Partial<Subscriber<any>>) {\n return this._subject.subscribe(callback)\n }\n\n async save(): Promise<void> {\n await waitFor(\n this._service,\n (snapshot) => !snapshot.context.isSaving && snapshot.value === 'idle',\n {\n timeout: 10_000,\n },\n )\n // return new Promise((resolve) => {\n // const saveSub = this._service.subscribe((snapshot) => {\n // if (!snapshot.context.isSaving) {\n // saveS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A;QACR,MAAM,OAAO,CACX,IAAI,CAAC,QAAQ,EACb,CAAC,QAAQ,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,IAAI,QAAQ,CAAC,KAAK,KAAK,MAAM,EACrE;AACE,YAAA,OAAO,EAAE,KAAM;AAChB,SAAA,CACF;;;;;;;;;;IAWH,MAAM,GAAA;AACJ,QAAA,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE;;;KAzarB,SAAS;AAZO,gBAAA,CAAA,aAAa,GAG1B,IAAI,GAAG,EAAE;;;;"}
|
|
1
|
+
{"version":3,"file":"BaseItemProperty.js","sources":["../../../../src/ItemProperty/BaseItemProperty.ts"],"sourcesContent":["import { ActorRefFrom, createActor, SnapshotFrom, Subscription, waitFor } from 'xstate'\nimport { BehaviorSubject, Subscriber } from 'rxjs'\nimport { Static } from '@sinclair/typebox'\nimport { IItemProperty } from '@/interfaces/IItemProperty'\nimport { immerable } from 'immer'\nimport { CreatePropertyInstanceProps, PropertyMachineContext } from '@/types'\nimport { getModel } from '@/stores/modelClass'\nimport { propertyMachine } from './service/propertyMachine'\nimport { INTERNAL_PROPERTY_NAMES } from '@/helpers/constants'\nimport debug from 'debug'\nimport pluralize from 'pluralize'\nimport { getPropertyData } from '@/db/read/getPropertyData'\nimport { BaseFileManager, getCorrectId } from '@/helpers'\nimport { TProperty } from '@/schema'\nimport { eventEmitter } from '@/eventBus'\nimport { getSchemaUidForModel } from '@/db/read/getSchemaUidForModel'\n\n\nconst logger = debug('seedSdk:property:class')\n\ntype ItemPropertyService = ActorRefFrom<typeof propertyMachine>\ntype ItemPropertySnapshot = SnapshotFrom<typeof propertyMachine>\n\ntype ItemPropertyFindProps = {\n propertyName: string\n propertyLocalId?: string\n seedLocalId?: string\n seedUid?: string\n}\n\nexport abstract class BaseItemProperty<PropertyType> implements IItemProperty<PropertyType> {\n protected static instanceCache: Map<\n string,\n { instance: BaseItemProperty<any>; refCount: number }\n > = new Map()\n protected readonly _service: ItemPropertyService\n protected _subject: BehaviorSubject<any>\n protected readonly _isRelation: boolean = false\n protected readonly _isList: boolean = false\n protected readonly _alias: string | undefined\n protected _subscription: Subscription\n protected _dataType: string | undefined\n protected _schemaUid: string | undefined\n [immerable] = true\n\n constructor(initialValues: Partial<CreatePropertyInstanceProps>) {\n const { modelName, propertyName, propertyValue, seedLocalId, seedUid, versionLocalId, versionUid, storageTransactionId, schemaUid } = initialValues\n\n if (!modelName) {\n throw new Error('Model name is required')\n }\n\n const ModelClass = getModel(modelName)\n\n if (!ModelClass) {\n throw new Error(`Model ${modelName} not found`)\n }\n\n if (!propertyName) {\n throw new Error(`Property name not provided`)\n }\n\n const serviceInput: Partial<PropertyMachineContext> = {\n propertyValue,\n propertyName,\n seedLocalId,\n seedUid,\n versionLocalId,\n versionUid,\n modelName,\n storageTransactionId,\n propertyRecordSchema: ModelClass.schema[propertyName],\n schemaUid,\n }\n\n\n\n if (!INTERNAL_PROPERTY_NAMES.includes(propertyName)) {\n let propertyNameWithoutId\n\n if (propertyName.endsWith('Id')) {\n propertyNameWithoutId = propertyName.slice(0, -2)\n }\n\n if (propertyName.endsWith('Ids')) {\n propertyNameWithoutId = propertyName.slice(0, -3)\n propertyNameWithoutId = pluralize(propertyNameWithoutId)\n }\n\n const propertyRecordSchema =\n ModelClass.schema[propertyNameWithoutId || propertyName]\n if (propertyRecordSchema) {\n this._dataType = propertyRecordSchema.dataType\n\n serviceInput.propertyRecordSchema = propertyRecordSchema\n\n if (propertyRecordSchema.dataType === 'Relation') {\n this._isRelation = true\n }\n\n if (\n propertyRecordSchema.dataType === 'List' &&\n propertyRecordSchema.ref\n ) {\n this._isList = true\n this._isRelation = true\n\n if (propertyValue) {\n try {\n serviceInput.propertyValue = JSON.parse(propertyValue)\n } catch (e) {\n logger('List property value is not JSON', e)\n }\n }\n\n const propertyNameSingular = pluralize(propertyName!, 1)\n\n this._alias = propertyName\n\n serviceInput.propertyName = `${propertyNameSingular}${propertyRecordSchema.ref}Ids`\n }\n\n if (!this._alias && propertyNameWithoutId) {\n this._alias = propertyNameWithoutId\n }\n }\n }\n\n serviceInput.isRelation = this._isRelation\n\n this._subject = new BehaviorSubject(propertyValue)\n this._service = createActor(propertyMachine, {\n input: serviceInput,\n })\n\n this._subscription = this._service.subscribe(\n async (snapshot: ItemPropertySnapshot) => {\n if (!snapshot || !snapshot.context) {\n return\n }\n\n const { context } = snapshot\n const { propertyRecordSchema } = context\n\n if (context.seedLocalId) {\n const cacheKey = BaseItemProperty.cacheKey(\n context.seedLocalId,\n context.propertyName,\n )\n if (!BaseItemProperty.instanceCache.has(cacheKey)) {\n BaseItemProperty.instanceCache.set(cacheKey, {\n instance: this,\n refCount: 1,\n })\n }\n }\n\n let renderValue\n\n const isImage =\n propertyRecordSchema &&\n propertyRecordSchema.dataType === 'Image'\n\n const isFile =\n propertyRecordSchema &&\n propertyRecordSchema.dataType === 'File'\n\n const isItemStorage = \n propertyRecordSchema &&\n propertyRecordSchema.storageType &&\n propertyRecordSchema.storageType === 'ItemStorage' &&\n context.refResolvedValue &&\n context.localStorageDir\n\n if (!this._schemaUid && context.schemaUid) {\n this._schemaUid = context.schemaUid\n }\n\n if (\n isImage ||\n isFile ||\n isItemStorage\n ) {\n const filePath = `/files/${context.localStorageDir}/${context.refResolvedValue}`\n try {\n const exists = await BaseFileManager.pathExists(filePath)\n if (exists && isItemStorage) {\n renderValue = await BaseFileManager.readFileAsString(filePath,)\n }\n if (exists && isImage) {\n if (context.refResolvedDisplayValue) {\n renderValue = context.refResolvedDisplayValue\n } \n if (!context.refResolvedDisplayValue) {\n renderValue = await BaseFileManager.getContentUrlFromPath(filePath)\n }\n }\n if (exists && isFile) {\n renderValue = await BaseFileManager.readFileAsString(filePath,)\n }\n if (!exists) {\n renderValue = 'No file found'\n }\n } catch (e) {\n logger(\n `[ItemProperty] [${context.seedLocalId}] [${context.propertyName}] [storageType] error`,\n e,\n )\n renderValue = 'No file found'\n }\n }\n\n if (!renderValue) {\n renderValue = context.renderValue || context.propertyValue\n }\n\n let transformedPropertyName = propertyName\n\n const skipTransform =\n INTERNAL_PROPERTY_NAMES.includes(propertyName) || !!this._alias\n\n if (!skipTransform && transformedPropertyName.endsWith('Id')) {\n transformedPropertyName = transformedPropertyName.slice(0, -2)\n }\n\n if (!skipTransform && transformedPropertyName.endsWith('Ids')) {\n transformedPropertyName = transformedPropertyName.slice(0, -3)\n }\n\n if (skipTransform && this._alias) {\n transformedPropertyName = this._alias\n }\n\n if (skipTransform && !this._alias) {\n }\n\n if (this._subject.value === renderValue) {\n return\n }\n\n this._subject.next(renderValue)\n // TODO: Maybe have this only update the property?\n // if (context.seedLocalId || context.seedUid) {\n // eventEmitter.emit(`property.${context.seedUid || context.seedLocalId}.${propertyName}.update`)\n // }\n // if (context.seedUid) {\n // eventEmitter.emit(`item.${modelName}.${context.seedUid}.update`)\n // }\n },\n )\n\n this._service.start()\n }\n\n static PlatformClass: typeof BaseItemProperty\n\n static setPlatformClass(platformClass: typeof BaseItemProperty) {\n this.PlatformClass = platformClass\n }\n\n static create(\n props: Partial<CreatePropertyInstanceProps>,\n ): BaseItemProperty<any> | undefined {\n const { propertyName, seedLocalId, seedUid, versionLocalId, versionUid } =\n props\n if (!propertyName || (!seedLocalId && !seedUid)) {\n return\n }\n const cacheKey = this.cacheKey(\n (seedUid || seedLocalId) as string,\n propertyName,\n )\n if (seedLocalId && propertyName) {\n if (this.instanceCache.has(cacheKey)) {\n const { instance, refCount } = this.instanceCache.get(cacheKey)!\n this.instanceCache.set(cacheKey, {\n instance,\n refCount: refCount + 1,\n })\n return instance\n }\n if (!this.instanceCache.has(cacheKey)) {\n const newInstance = new this(props)\n this.instanceCache.set(cacheKey, {\n instance: newInstance,\n refCount: 1,\n })\n return newInstance\n }\n }\n if (seedUid && propertyName) {\n if (this.instanceCache.has(cacheKey)) {\n const { instance, refCount } = this.instanceCache.get(cacheKey)!\n this.instanceCache.set(cacheKey, { instance, refCount: refCount + 1 })\n return instance\n }\n if (!this.instanceCache.has(cacheKey)) {\n const newInstance = new this(props)\n this.instanceCache.set(cacheKey, { instance: newInstance, refCount: 1 })\n return newInstance\n }\n }\n return new this(props)\n }\n\n static async find({\n propertyName,\n seedLocalId,\n seedUid,\n }: ItemPropertyFindProps): Promise<IItemProperty<any> | undefined> {\n if ((!seedLocalId && !seedUid) || !propertyName) {\n return\n }\n const cacheKeyId = seedUid || seedLocalId\n const cacheKey = BaseItemProperty.cacheKey(cacheKeyId!, propertyName)\n if (this.instanceCache.has(cacheKey)) {\n const { instance, refCount } = this.instanceCache.get(cacheKey)!\n this.instanceCache.set(cacheKey, {\n instance,\n refCount: refCount + 1,\n })\n return instance\n }\n const propertyData = await getPropertyData({\n propertyName,\n seedLocalId,\n seedUid,\n })\n if (!propertyData) {\n return\n }\n return BaseItemProperty.create(propertyData)\n }\n\n static cacheKey(seedLocalIdOrUid: string, propertyName: string): string {\n const { uid, localId } = getCorrectId(seedLocalIdOrUid)\n return `Item_${uid || localId}_${propertyName}`\n }\n\n getService() {\n return this._service\n }\n\n private _getSnapshot(): ItemPropertySnapshot {\n return this._service.getSnapshot() as ItemPropertySnapshot\n }\n\n private _getSnapshotContext(): PropertyMachineContext {\n return this._getSnapshot().context\n }\n\n get localId() {\n return this._getSnapshotContext().localId\n }\n\n get uid() {\n return this._getSnapshotContext().uid\n }\n\n get seedLocalId() {\n return this._getSnapshotContext().seedLocalId\n }\n\n get seedUid() {\n return this._getSnapshotContext().seedUid\n }\n\n get schemaUid() {\n return this._getSnapshotContext().schemaUid\n }\n\n get propertyName() {\n if (this._alias) {\n return this._alias\n }\n return this._getSnapshotContext().propertyName\n }\n\n get modelName() {\n return this._getSnapshotContext().modelName\n }\n\n get propertyDef(): Static<typeof TProperty> | undefined {\n return this._getSnapshotContext().propertyRecordSchema\n }\n\n get localStorageDir(): string | void {\n if (this.propertyDef && this.propertyDef.localStorageDir) {\n return this.propertyDef.localStorageDir\n }\n if (this._getSnapshot().context.localStorageDir) {\n return this._getSnapshot().context.localStorageDir\n }\n }\n\n get refResolvedValue(): string | undefined {\n return this._getSnapshotContext().refResolvedValue\n }\n\n get localStoragePath(): string | void {\n if (this.localStorageDir) {\n return `/files${this.localStorageDir}/${this.refResolvedValue}`\n }\n }\n\n get versionLocalId(): string | undefined {\n return this._getSnapshotContext().versionLocalId\n }\n\n get status() {\n return this._getSnapshot().value\n }\n\n get alias() {\n return this._alias\n }\n\n get value() {\n // logger(\n // `[XXXXXXXXXX] [value] [get] subjectValue: ${this._subject.value} serviceValue: ${this._service.getSnapshot().context.renderValue}`,\n // )\n if (this._dataType === 'Image') {\n return this._getSnapshot().context.refResolvedValue\n }\n return this._subject.value\n }\n\n set value(value: any) {\n if (this._subject.value === value) {\n return\n }\n const context = this._service.getSnapshot().context\n if (!context.propertyRecordSchema) {\n this._subject.next(value)\n }\n this._service.send({\n type: 'save',\n newValue: value,\n })\n }\n\n get published(): boolean {\n return !!this._getSnapshot().context.uid\n }\n\n subscribe(callback: Partial<Subscriber<any>>) {\n return this._subject.subscribe(callback)\n }\n\n async save(): Promise<void> {\n await waitFor(\n this._service,\n (snapshot) => !snapshot.context.isSaving && snapshot.value === 'idle',\n {\n timeout: 10_000,\n },\n )\n // return new Promise((resolve) => {\n // const saveSub = this._service.subscribe((snapshot) => {\n // if (!snapshot.context.isSaving) {\n // saveSub.unsubscribe()\n // resolve()\n // }\n // })\n // })\n }\n\n unload() {\n this._service.stop()\n }\n} "],"names":[],"mappings":";;;;;;;;;;;;;AAkBA,MAAM,MAAM,GAAG,KAAK,CAAC,wBAAwB,CAAC;MAYxB,gBAAgB,CAAA;AAepC,IAAA,WAAA,CAAY,aAAmD,EAAA;QAR5C,IAAA,CAAA,WAAW,GAAY,KAAK;QAC5B,IAAA,CAAA,OAAO,GAAY,KAAK;QAK3C,IAAA,CAAA,EAAA,CAAW,GAAG,IAAI;QAGhB,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,UAAU,EA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AAC,KAAK,KAAK,MAAM,EACrE;AACE,YAAA,OAAO,EAAE,KAAM;AAChB,SAAA,CACF;;;;;;;;;IASH;IAEA,MAAM,GAAA;AACJ,QAAA,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE;IACtB;;KA1aC,SAAS;AAZO,gBAAA,CAAA,aAAa,GAG1B,IAAI,GAAG,EAAE;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydrateFromDb.js","sources":["../../../../../../src/ItemProperty/service/actors/hydrateFromDb.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { and, eq, or, sql } from 'drizzle-orm'\nimport debug from 'debug'\nimport { metadata } from '@/seedSchema'\nimport { BaseDb } from '@/db/Db/BaseDb'\nimport { updateMetadata } from '@/db/write/updateMetadata'\nimport { FromCallbackInput } from '@/types/machines'\nimport { PropertyMachineContext } from '@/types/property'\nimport { BaseFileManager } from '@/helpers'\n\nconst logger = debug('seedSdk:property:actors:hydrateFromDb')\n\nexport const hydrateFromDb = fromCallback<\n EventObject,\n FromCallbackInput<PropertyMachineContext, EventObject>\n>(({ sendBack, input: { context } }) => {\n const {\n seedUid,\n seedLocalId,\n propertyName: propertyNameRaw,\n propertyRecordSchema,\n modelName,\n } = context\n\n let propertyName = propertyNameRaw\n\n const isRelation =\n propertyRecordSchema &&\n propertyRecordSchema.ref &&\n propertyRecordSchema.dataType === 'Relation'\n\n const isImage =\n propertyRecordSchema &&\n propertyRecordSchema.dataType === 'Image'\n\n const isFile =\n propertyRecordSchema &&\n propertyRecordSchema.dataType === 'File'\n\n if (\n (\n isRelation || \n isImage ||\n isFile\n ) &&\n !propertyNameRaw.endsWith('Id')\n ) {\n propertyName = propertyNameRaw + 'Id'\n }\n\n if (\n propertyRecordSchema &&\n propertyRecordSchema.ref &&\n propertyRecordSchema.dataType === 'List' &&\n !propertyNameRaw.endsWith('Ids')\n ) {\n propertyName = propertyNameRaw + 'Ids'\n }\n\n const _hydrateFromDb = async () => {\n const appDb = BaseDb.getAppDb()\n\n const whereClauses = []\n\n if (isRelation || isImage || isFile) {\n let missingPropertyNameVariant\n if (propertyName.endsWith('Id')) {\n missingPropertyNameVariant = propertyName.slice(0, -2)\n }\n if (!propertyName.endsWith('Id')) {\n missingPropertyNameVariant = propertyName + 'Id'\n }\n if (missingPropertyNameVariant) {\n whereClauses.push(\n or(\n eq(metadata.propertyName, propertyName),\n eq(metadata.propertyName, missingPropertyNameVariant),\n ),\n )\n }\n if (!missingPropertyNameVariant) {\n whereClauses.push(eq(metadata.propertyName, propertyName))\n }\n } else {\n whereClauses.push(eq(metadata.propertyName, propertyName))\n }\n\n if (seedUid) {\n whereClauses.push(eq(metadata.seedUid, seedUid))\n }\n\n if (seedLocalId) {\n whereClauses.push(eq(metadata.seedLocalId, seedLocalId))\n }\n\n const rows = await appDb\n .select()\n .from(metadata)\n .where(and(...whereClauses))\n .orderBy(sql.raw('COALESCE(attestation_created_at, created_at) DESC'))\n\n if (!rows || !rows.length) {\n return\n }\n\n const firstRow = rows[0]\n\n const {\n localId,\n uid,\n propertyName: propertyNameFromDb,\n propertyValue: propertyValueFromDb,\n seedLocalId: seedLocalIdFromDb,\n seedUid: seedUidFromDb,\n schemaUid: schemaUidFromDb,\n versionLocalId: versionLocalIdFromDb,\n versionUid: versionUidFromDb,\n refValueType,\n } = firstRow\n\n let { refResolvedDisplayValue, refResolvedValue, localStorageDir } = firstRow\n\n let propertyValueProcessed: string | string[] | undefined | null =\n propertyValueFromDb\n\n\n if (isImage) {\n let shouldReadFromFile = true\n\n if (\n refResolvedValue &&\n refResolvedDisplayValue &&\n refResolvedDisplayValue.includes('http')\n ) {\n try {\n const response = await fetch(refResolvedDisplayValue, {\n method: 'HEAD',\n }).catch((error) => {\n // No-op\n shouldReadFromFile = true\n })\n\n if (!response || !response.ok) {\n shouldReadFromFile = true\n }\n\n // Check if the status is in the 200-299 range\n if (response && response.ok) {\n shouldReadFromFile = false\n }\n } catch (error) {\n shouldReadFromFile = true\n }\n }\n\n if (shouldReadFromFile) {\n let dir = localStorageDir\n if (\n !dir &&\n isImage\n ) {\n dir = 'images'\n }\n\n dir = dir!.replace(/^\\//, '')\n\n if (\n propertyValueFromDb &&\n propertyValueFromDb.length === 66\n ) {\n // Here the storageTransactionId is stored on a different record and\n // we want to add it as the refResolvedValue\n const storageTransactionQuery = await appDb\n .select({\n propertyValue: metadata.propertyValue,\n })\n .from(metadata)\n .where(\n and(\n eq(metadata.seedUid, propertyValueFromDb),\n or(\n eq(metadata.propertyName, 'storageTransactionId'),\n eq(metadata.propertyName, 'transactionId'),\n ),\n ),\n )\n\n if (storageTransactionQuery && storageTransactionQuery.length > 0) {\n const row = storageTransactionQuery[0]\n refResolvedValue = row.propertyValue\n await updateMetadata({\n localId,\n refResolvedValue,\n localStorageDir: '/images',\n })\n }\n }\n\n const dirPath = `/files/${dir}`\n const fs = await BaseFileManager.getFs()\n const path = BaseFileManager.getPathModule()\n const files = await fs.promises.readdir(dirPath)\n const matchingFiles = files.filter((file: string) => {\n return path.basename(file).includes(refResolvedValue!)\n })\n let fileExists = false\n let filename\n let filePath\n if (matchingFiles && matchingFiles.length > 0) {\n fileExists = true\n filename = matchingFiles[0]\n filePath = `/files/${dir}/${filename}`\n }\n localStorageDir = `/${dir}`\n if (fileExists && filename && filePath) {\n const file = await BaseFileManager.readFile(filePath)\n refResolvedDisplayValue = URL.createObjectURL(file)\n await updateMetadata({\n localId,\n refResolvedValue: filename,\n refResolvedDisplayValue: refResolvedDisplayValue,\n localStorageDir,\n })\n }\n\n }\n }\n\n if (\n propertyRecordSchema &&\n propertyRecordSchema.dataType === 'List' &&\n propertyRecordSchema.ref &&\n typeof propertyValueFromDb === 'string'\n ) {\n propertyValueProcessed = propertyValueFromDb.split(',')\n }\n\n sendBack({\n type: 'updateContext',\n localId,\n uid,\n propertyValue: propertyValueProcessed,\n seedLocalId: seedLocalIdFromDb,\n seedUid: seedUidFromDb,\n versionLocalId: versionLocalIdFromDb,\n versionUid: versionUidFromDb,\n schemaUid: schemaUidFromDb,\n refValueType,\n localStorageDir,\n refResolvedValue,\n refResolvedDisplayValue,\n renderValue: refResolvedDisplayValue,\n populatedFromDb: true,\n })\n\n if (\n propertyRecordSchema &&\n propertyRecordSchema.storageType &&\n propertyRecordSchema.storageType === 'ItemStorage'\n ) {\n const { BaseItem } = await import(`@/Item/BaseItem`)\n const item = await BaseItem.find({\n seedLocalId,\n modelName,\n })\n if (item) {\n const filePath = `/files/${localStorageDir}/${refResolvedValue}`\n const exists = await BaseFileManager.pathExists(filePath)\n\n if (!exists) {\n return\n }\n\n const renderValue = await BaseFileManager.readFileAsString(filePath)\n const property = item.properties[propertyName]\n property.getService().send({ type: 'updateContext', renderValue })\n return\n }\n }\n }\n\n _hydrateFromDb().then(() => {\n sendBack({ type: 'hydrateFromDbSuccess' })\n })\n})\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAUe,KAAK,CAAC,uCAAuC;AAE/C,MAAA,aAAa,GAAG,YAAY,CAGvC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,KAAI;AACrC,IAAA,MAAM,EACJ,OAAO,EACP,WAAW,EACX,YAAY,EAAE,eAAe,EAC7B,oBAAoB,EACpB,SAAS,GACV,GAAG,OAAO;IAEX,IAAI,YAAY,GAAG,eAAe;IAElC,MAAM,UAAU,GACd,oBAAoB;AACpB,QAAA,oBAAoB,CAAC,GAAG;AACxB,QAAA,oBAAoB,CAAC,QAAQ,KAAK,UAAU;IAE9C,MAAM,OAAO,GACX,oBAAoB;AACpB,QAAA,oBAAoB,CAAC,QAAQ,KAAK,OAAO;IAE3C,MAAM,MAAM,GACV,oBAAoB;AACpB,QAAA,oBAAoB,CAAC,QAAQ,KAAK,MAAM;AAE1C,IAAA,IACE,CACE,UAAU;QACV,OAAO;AACP,QAAA,MAAM;AAER,QAAA,CAAC,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,EAC/B;AACA,QAAA,YAAY,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CAAC;AAC5C,KAAC,CAAC;AACJ,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"hydrateFromDb.js","sources":["../../../../../../src/ItemProperty/service/actors/hydrateFromDb.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { and, eq, or, sql } from 'drizzle-orm'\nimport debug from 'debug'\nimport { metadata } from '@/seedSchema'\nimport { BaseDb } from '@/db/Db/BaseDb'\nimport { updateMetadata } from '@/db/write/updateMetadata'\nimport { FromCallbackInput } from '@/types/machines'\nimport { PropertyMachineContext } from '@/types/property'\nimport { BaseFileManager } from '@/helpers'\n\nconst logger = debug('seedSdk:property:actors:hydrateFromDb')\n\nexport const hydrateFromDb = fromCallback<\n EventObject,\n FromCallbackInput<PropertyMachineContext, EventObject>\n>(({ sendBack, input: { context } }) => {\n const {\n seedUid,\n seedLocalId,\n propertyName: propertyNameRaw,\n propertyRecordSchema,\n modelName,\n } = context\n\n let propertyName = propertyNameRaw\n\n const isRelation =\n propertyRecordSchema &&\n propertyRecordSchema.ref &&\n propertyRecordSchema.dataType === 'Relation'\n\n const isImage =\n propertyRecordSchema &&\n propertyRecordSchema.dataType === 'Image'\n\n const isFile =\n propertyRecordSchema &&\n propertyRecordSchema.dataType === 'File'\n\n if (\n (\n isRelation || \n isImage ||\n isFile\n ) &&\n !propertyNameRaw.endsWith('Id')\n ) {\n propertyName = propertyNameRaw + 'Id'\n }\n\n if (\n propertyRecordSchema &&\n propertyRecordSchema.ref &&\n propertyRecordSchema.dataType === 'List' &&\n !propertyNameRaw.endsWith('Ids')\n ) {\n propertyName = propertyNameRaw + 'Ids'\n }\n\n const _hydrateFromDb = async () => {\n const appDb = BaseDb.getAppDb()\n\n const whereClauses = []\n\n if (isRelation || isImage || isFile) {\n let missingPropertyNameVariant\n if (propertyName.endsWith('Id')) {\n missingPropertyNameVariant = propertyName.slice(0, -2)\n }\n if (!propertyName.endsWith('Id')) {\n missingPropertyNameVariant = propertyName + 'Id'\n }\n if (missingPropertyNameVariant) {\n whereClauses.push(\n or(\n eq(metadata.propertyName, propertyName),\n eq(metadata.propertyName, missingPropertyNameVariant),\n ),\n )\n }\n if (!missingPropertyNameVariant) {\n whereClauses.push(eq(metadata.propertyName, propertyName))\n }\n } else {\n whereClauses.push(eq(metadata.propertyName, propertyName))\n }\n\n if (seedUid) {\n whereClauses.push(eq(metadata.seedUid, seedUid))\n }\n\n if (seedLocalId) {\n whereClauses.push(eq(metadata.seedLocalId, seedLocalId))\n }\n\n const rows = await appDb\n .select()\n .from(metadata)\n .where(and(...whereClauses))\n .orderBy(sql.raw('COALESCE(attestation_created_at, created_at) DESC'))\n\n if (!rows || !rows.length) {\n return\n }\n\n const firstRow = rows[0]\n\n const {\n localId,\n uid,\n propertyName: propertyNameFromDb,\n propertyValue: propertyValueFromDb,\n seedLocalId: seedLocalIdFromDb,\n seedUid: seedUidFromDb,\n schemaUid: schemaUidFromDb,\n versionLocalId: versionLocalIdFromDb,\n versionUid: versionUidFromDb,\n refValueType,\n } = firstRow\n\n let { refResolvedDisplayValue, refResolvedValue, localStorageDir } = firstRow\n\n let propertyValueProcessed: string | string[] | undefined | null =\n propertyValueFromDb\n\n\n if (isImage) {\n let shouldReadFromFile = true\n\n if (\n refResolvedValue &&\n refResolvedDisplayValue &&\n refResolvedDisplayValue.includes('http')\n ) {\n try {\n const response = await fetch(refResolvedDisplayValue, {\n method: 'HEAD',\n }).catch((error) => {\n // No-op\n shouldReadFromFile = true\n })\n\n if (!response || !response.ok) {\n shouldReadFromFile = true\n }\n\n // Check if the status is in the 200-299 range\n if (response && response.ok) {\n shouldReadFromFile = false\n }\n } catch (error) {\n shouldReadFromFile = true\n }\n }\n\n if (shouldReadFromFile) {\n let dir = localStorageDir\n if (\n !dir &&\n isImage\n ) {\n dir = 'images'\n }\n\n dir = dir!.replace(/^\\//, '')\n\n if (\n propertyValueFromDb &&\n propertyValueFromDb.length === 66\n ) {\n // Here the storageTransactionId is stored on a different record and\n // we want to add it as the refResolvedValue\n const storageTransactionQuery = await appDb\n .select({\n propertyValue: metadata.propertyValue,\n })\n .from(metadata)\n .where(\n and(\n eq(metadata.seedUid, propertyValueFromDb),\n or(\n eq(metadata.propertyName, 'storageTransactionId'),\n eq(metadata.propertyName, 'transactionId'),\n ),\n ),\n )\n\n if (storageTransactionQuery && storageTransactionQuery.length > 0) {\n const row = storageTransactionQuery[0]\n refResolvedValue = row.propertyValue\n await updateMetadata({\n localId,\n refResolvedValue,\n localStorageDir: '/images',\n })\n }\n }\n\n const dirPath = `/files/${dir}`\n const fs = await BaseFileManager.getFs()\n const path = BaseFileManager.getPathModule()\n const files = await fs.promises.readdir(dirPath)\n const matchingFiles = files.filter((file: string) => {\n return path.basename(file).includes(refResolvedValue!)\n })\n let fileExists = false\n let filename\n let filePath\n if (matchingFiles && matchingFiles.length > 0) {\n fileExists = true\n filename = matchingFiles[0]\n filePath = `/files/${dir}/${filename}`\n }\n localStorageDir = `/${dir}`\n if (fileExists && filename && filePath) {\n const file = await BaseFileManager.readFile(filePath)\n refResolvedDisplayValue = URL.createObjectURL(file)\n await updateMetadata({\n localId,\n refResolvedValue: filename,\n refResolvedDisplayValue: refResolvedDisplayValue,\n localStorageDir,\n })\n }\n\n }\n }\n\n if (\n propertyRecordSchema &&\n propertyRecordSchema.dataType === 'List' &&\n propertyRecordSchema.ref &&\n typeof propertyValueFromDb === 'string'\n ) {\n propertyValueProcessed = propertyValueFromDb.split(',')\n }\n\n sendBack({\n type: 'updateContext',\n localId,\n uid,\n propertyValue: propertyValueProcessed,\n seedLocalId: seedLocalIdFromDb,\n seedUid: seedUidFromDb,\n versionLocalId: versionLocalIdFromDb,\n versionUid: versionUidFromDb,\n schemaUid: schemaUidFromDb,\n refValueType,\n localStorageDir,\n refResolvedValue,\n refResolvedDisplayValue,\n renderValue: refResolvedDisplayValue,\n populatedFromDb: true,\n })\n\n if (\n propertyRecordSchema &&\n propertyRecordSchema.storageType &&\n propertyRecordSchema.storageType === 'ItemStorage'\n ) {\n const { BaseItem } = await import(`@/Item/BaseItem`)\n const item = await BaseItem.find({\n seedLocalId,\n modelName,\n })\n if (item) {\n const filePath = `/files/${localStorageDir}/${refResolvedValue}`\n const exists = await BaseFileManager.pathExists(filePath)\n\n if (!exists) {\n return\n }\n\n const renderValue = await BaseFileManager.readFileAsString(filePath)\n const property = item.properties[propertyName]\n property.getService().send({ type: 'updateContext', renderValue })\n return\n }\n }\n }\n\n _hydrateFromDb().then(() => {\n sendBack({ type: 'hydrateFromDbSuccess' })\n })\n})\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAUe,KAAK,CAAC,uCAAuC;AAErD,MAAM,aAAa,GAAG,YAAY,CAGvC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,KAAI;AACrC,IAAA,MAAM,EACJ,OAAO,EACP,WAAW,EACX,YAAY,EAAE,eAAe,EAC7B,oBAAoB,EACpB,SAAS,GACV,GAAG,OAAO;IAEX,IAAI,YAAY,GAAG,eAAe;IAElC,MAAM,UAAU,GACd,oBAAoB;AACpB,QAAA,oBAAoB,CAAC,GAAG;AACxB,QAAA,oBAAoB,CAAC,QAAQ,KAAK,UAAU;IAE9C,MAAM,OAAO,GACX,oBAAoB;AACpB,QAAA,oBAAoB,CAAC,QAAQ,KAAK,OAAO;IAE3C,MAAM,MAAM,GACV,oBAAoB;AACpB,QAAA,oBAAoB,CAAC,QAAQ,KAAK,MAAM;AAE1C,IAAA,IACE,CACE,UAAU;QACV,OAAO;AACP,QAAA,MAAM;AAER,QAAA,CAAC,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,EAC/B;AACA,QAAA,YAAY,GAAG,eAAe,GAAG,IAAI;IACvC;AAEA,IAAA,IACE,oBAAoB;AACpB,QAAA,oBAAoB,CAAC,GAAG;QACxB,oBAAoB,CAAC,QAAQ,KAAK,MAAM;AACxC,QAAA,CAAC,eAAe,CAAC,QAAQ,CAAC,KAAK,CAAC,EAChC;AACA,QAAA,YAAY,GAAG,e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1
|
-
{"version":3,"file":"initialize.js","sources":["../../../../../../src/ItemProperty/service/actors/initialize.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { FromCallbackInput } from '@/types/machines'\nimport { PropertyMachineContext } from '@/types/property'\nimport { getSchemaUidForSchemaDefinition } from '@/stores/eas'\nimport { BaseFileManager } from '@/helpers/FileManager/BaseFileManager'\nimport { INTERNAL_PROPERTY_NAMES } from '@/helpers/constants'\n\n\nexport const initialize = fromCallback<\n EventObject,\n FromCallbackInput<PropertyMachineContext, EventObject>\n>(({ sendBack, input: { context } }) => {\n const { \n isRelation, \n propertyName, \n storageTransactionId,\n propertyRecordSchema, \n } = context\n let { schemaUid } = context\n\n const _initialize = async () => {\n if (\n !schemaUid && \n !INTERNAL_PROPERTY_NAMES.includes(propertyName) &&\n (\n !propertyRecordSchema ||\n !propertyRecordSchema.storageType ||\n propertyRecordSchema.storageType !== 'ItemStorage'\n )\n ) {\n schemaUid = await getSchemaUidForSchemaDefinition({ schemaText: propertyName })\n if (schemaUid) {\n sendBack({ type: 'updateContext', schemaUid })\n }\n }\n \n if (isRelation) {\n sendBack({ type: 'isRelatedProperty' })\n sendBack({ type: 'initializeSuccess' })\n return\n }\n \n if (!isRelation) {\n if (\n (propertyName !== 'html' && propertyName !== 'json') ||\n !storageTransactionId\n ) {\n sendBack({ type: 'initializeSuccess' })\n return\n }\n \n if (propertyName === 'html') {\n const htmlFilePath = `/files/html/${storageTransactionId}.html`\n const exists = await BaseFileManager.pathExists(htmlFilePath)\n if (!exists) {\n return\n }\n const renderValue = await BaseFileManager.readFileAsString(htmlFilePath)\n .catch((error) => {\n console.warn('Error reading html file', error)\n })\n sendBack({ type: 'updateContext', renderValue })\n return\n }\n if (propertyName === 'json') {\n const jsonFilePath = `/files/json/${storageTransactionId}.json`\n const exists = await BaseFileManager.pathExists(jsonFilePath)\n if (!exists) {\n return\n }\n const renderValue = await BaseFileManager.readFileAsString(jsonFilePath)\n .catch((error) => {\n console.warn('Error reading json file', error)\n })\n sendBack({ type: 'updateContext', renderValue })\n return\n }\n \n }\n }\n\n _initialize().then(() => {\n sendBack({ type: 'initializeSuccess' })\n })\n})\n"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"initialize.js","sources":["../../../../../../src/ItemProperty/service/actors/initialize.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { FromCallbackInput } from '@/types/machines'\nimport { PropertyMachineContext } from '@/types/property'\nimport { getSchemaUidForSchemaDefinition } from '@/stores/eas'\nimport { BaseFileManager } from '@/helpers/FileManager/BaseFileManager'\nimport { INTERNAL_PROPERTY_NAMES } from '@/helpers/constants'\n\n\nexport const initialize = fromCallback<\n EventObject,\n FromCallbackInput<PropertyMachineContext, EventObject>\n>(({ sendBack, input: { context } }) => {\n const { \n isRelation, \n propertyName, \n storageTransactionId,\n propertyRecordSchema, \n } = context\n let { schemaUid } = context\n\n const _initialize = async () => {\n if (\n !schemaUid && \n !INTERNAL_PROPERTY_NAMES.includes(propertyName) &&\n (\n !propertyRecordSchema ||\n !propertyRecordSchema.storageType ||\n propertyRecordSchema.storageType !== 'ItemStorage'\n )\n ) {\n schemaUid = await getSchemaUidForSchemaDefinition({ schemaText: propertyName })\n if (schemaUid) {\n sendBack({ type: 'updateContext', schemaUid })\n }\n }\n \n if (isRelation) {\n sendBack({ type: 'isRelatedProperty' })\n sendBack({ type: 'initializeSuccess' })\n return\n }\n \n if (!isRelation) {\n if (\n (propertyName !== 'html' && propertyName !== 'json') ||\n !storageTransactionId\n ) {\n sendBack({ type: 'initializeSuccess' })\n return\n }\n \n if (propertyName === 'html') {\n const htmlFilePath = `/files/html/${storageTransactionId}.html`\n const exists = await BaseFileManager.pathExists(htmlFilePath)\n if (!exists) {\n return\n }\n const renderValue = await BaseFileManager.readFileAsString(htmlFilePath)\n .catch((error) => {\n console.warn('Error reading html file', error)\n })\n sendBack({ type: 'updateContext', renderValue })\n return\n }\n if (propertyName === 'json') {\n const jsonFilePath = `/files/json/${storageTransactionId}.json`\n const exists = await BaseFileManager.pathExists(jsonFilePath)\n if (!exists) {\n return\n }\n const renderValue = await BaseFileManager.readFileAsString(jsonFilePath)\n .catch((error) => {\n console.warn('Error reading json file', error)\n })\n sendBack({ type: 'updateContext', renderValue })\n return\n }\n \n }\n }\n\n _initialize().then(() => {\n sendBack({ type: 'initializeSuccess' })\n })\n})\n"],"names":[],"mappings":";;;;;AAQO,MAAM,UAAU,GAAG,YAAY,CAGpC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,KAAI;IACrC,MAAM,EACJ,UAAU,EACV,YAAY,EACZ,oBAAoB,EACpB,oBAAoB,GACrB,GAAG,OAAO;AACX,IAAA,IAAI,EAAE,SAAS,EAAE,GAAG,OAAO;AAE3B,IAAA,MAAM,WAAW,GAAG,YAAW;AAC7B,QAAA,IACE,CAAC,SAAS;AACV,YAAA,CAAC,uBAAuB,CAAC,QAAQ,CAAC,YAAY,CAAC;AAC/C,aACE,CAAC,oBAAoB;gBACrB,CAAC,oBAAoB,CAAC,WAAW;AACjC,gBAAA,oBAAoB,CAAC,WAAW,KAAK,aAAa,CACnD,EACD;YACA,SAAS,GAAG,MAAM,+BAA+B,CAAC,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC;YAC/E,IAAI,SAAS,EAAE;gBACb,QAAQ,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,CAAC;YAChD;QACF;QAEA,IAAI,UAAU,EAAE;AACd,YAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC;AACvC,YAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC;YACvC;QACF;QAEA,IAAI,CAAC,UAAU,EAAE;YACf,IACE,CAAC,YAAY,KAAK,MAAM,IAAI,YAAY,KAAK,MAAM;gBACnD,CAAC,oBAAoB,EACrB;AACA,gBAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,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{"version":3,"file":"resolveRelatedValue.js","sources":["../../../../../../src/ItemProperty/service/actors/resolveRelatedValue.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { BaseFileManager, convertTxIdToImage } from '@/helpers'\nimport debug from 'debug'\nimport { FromCallbackInput } from '@/types/machines'\nimport { PropertyMachineContext } from '@/types/property'\nimport { getStorageTransactionIdForSeedUid } from '@/db/read/getStorageTransactionIdForSeedUid'\nimport { getRelationValueData } from '@/db/read/getRelationValueData'\n\nconst logger = debug('seedSdk:property:actors:resolveRelatedValue')\n\nconst storageTransactionIdToContentUrl = new Map<string, string>()\nconst refResolvedValueToContentUrl = new Map<string, string>()\nconst seedUidToContentUrl = new Map<string, string>()\n\nexport const resolveRelatedValue = fromCallback<\n EventObject,\n FromCallbackInput<PropertyMachineContext, EventObject>\n>(({ sendBack, input: { context } }) => {\n const {\n isRelation,\n propertyValue,\n propertyName,\n seedUid,\n propertyRecordSchema,\n populatedFromDb,\n schemaUid,\n } = context\n\n const _resolveRelatedValue = async () => {\n if (!propertyValue || !isRelation || populatedFromDb) {\n return\n }\n\n let parsedValue\n\n try {\n parsedValue = JSON.parse(propertyValue)\n } catch (error) {\n logger(`${propertyName} value is not a JSON string.`)\n }\n\n if (!parsedValue && seedUidToContentUrl.has(propertyValue)) {\n const contentUrl = seedUidToContentUrl.get(propertyValue)\n sendBack({\n type: 'updateContext',\n renderValue: contentUrl,\n })\n sendBack({\n type: 'resolvingRelatedValueSuccess',\n refResolvedDisplayValue: contentUrl,\n })\n return true\n }\n\n if (Array.isArray(propertyValue)) {\n // TODO: Handle array of seedUids\n logger(`${propertyName} value is an array of seedUids`)\n return\n }\n\n if (Array.isArray(parsedValue)) {\n logger(`${propertyName} value is a stringified array of seedUids`)\n return\n }\n\n const storageTransactionId =\n await getStorageTransactionIdForSeedUid(propertyValue)\n\n if (storageTransactionId) {\n if (storageTransactionIdToContentUrl.has(storageTransactionId)) {\n const contentUrl =\n storageTransactionIdToContentUrl.get(storageTransactionId)\n sendBack({\n type: 'updateContext',\n renderValue: contentUrl,\n })\n sendBack({\n type: 'resolvingRelatedValueSuccess',\n refResolvedDisplayValue: contentUrl,\n refResolvedValue: storageTransactionId,\n })\n return true\n }\n\n const contentUrl = await convertTxIdToImage(storageTransactionId)\n if (contentUrl) {\n seedUidToContentUrl.set(propertyValue, contentUrl)\n }\n sendBack({\n type: 'updateContext',\n renderValue: contentUrl,\n })\n sendBack({\n type: 'resolvingRelatedValueSuccess',\n refResolvedDisplayValue: contentUrl,\n refResolvedValue: storageTransactionId,\n })\n return true\n }\n\n const relationValueData = await getRelationValueData(propertyValue)\n\n if (relationValueData) {\n const { refResolvedValue } = relationValueData\n const propertyValueFromDb = relationValueData.propertyValue\n\n // This handles a local-only relation value and resolves from the filesystem\n if (\n refResolvedValue &&\n propertyRecordSchema.dataType === 'Relation' &&\n propertyValueFromDb.length === 10 &&\n propertyRecordSchema.ref\n ) {\n if (refResolvedValueToContentUrl.has(refResolvedValue)) {\n const contentUrl = refResolvedValueToContentUrl.get(refResolvedValue)\n sendBack({\n type: 'updateContext',\n renderValue: contentUrl,\n })\n sendBack({\n type: 'resolvingRelatedValueSuccess',\n refResolvedDisplayValue: contentUrl,\n })\n return true\n }\n\n const fileExists = await BaseFileManager.pathExists(\n '/files/images/' + refResolvedValue,\n )\n if (fileExists) {\n const file = await BaseFileManager.readFile(\n '/files/images/' + refResolvedValue,\n )\n const contentUrl = URL.createObjectURL(file)\n refResolvedValueToContentUrl.set(refResolvedValue, contentUrl)\n sendBack({\n type: 'updateContext',\n renderValue: contentUrl,\n })\n sendBack({\n type: 'resolvingRelatedValueSuccess',\n refResolvedDisplayValue: contentUrl,\n })\n return true\n }\n }\n\n if (typeof propertyValueFromDb === 'string') {\n // Check files for a filename that matches the propertyValue\n if (\n propertyRecordSchema &&\n propertyRecordSchema.refValueType === 'Image'\n ) {\n let contentUrl\n\n if (storageTransactionIdToContentUrl.has(propertyValueFromDb)) {\n contentUrl =\n storageTransactionIdToContentUrl.get(propertyValueFromDb)\n }\n\n if (!contentUrl) {\n const imageFileExists = await BaseFileManager.pathExists(\n `/images/${propertyValue}`,\n )\n if (imageFileExists) {\n const file = await BaseFileManager.readFile(\n `/images/${propertyValue}`,\n )\n contentUrl = URL.createObjectURL(file)\n storageTransactionIdToContentUrl.set(\n propertyValueFromDb,\n contentUrl,\n )\n }\n }\n\n if (contentUrl) {\n sendBack({\n type: 'updateContext',\n renderValue: contentUrl,\n })\n sendBack({\n type: 'resolvingRelatedValueSuccess',\n refResolvedDisplayValue: contentUrl,\n })\n return true\n }\n }\n }\n }\n }\n\n _resolveRelatedValue().then((success) => {\n // if (success) {\n // sendBack({\n // type: 'resolvingRelatedValueDone',\n // })\n // }\n // return\n sendBack({\n type: 'resolvingRelatedValueDone',\n })\n })\n})\n\n// const eventKey = `storage.transaction.${initialValue}.contentUrl.response`\n//\n// const contentUrlListener = async (event) => {\n// console.log('[itemProperty] [constructor] contentUrlListener', event)\n// }\n//\n// eventEmitter.once(eventKey, contentUrlListener)\n//\n// const ready = getArePropertyEventHandlersReady()\n//\n// console.log('[itemProperty] [constructor] ready', ready)\n//\n// eventEmitter.emit('storage.transaction.contentUrl.request', {\n// storageTransactionId: initialValue,\n// })\n\n// Related property values can either be seedUid or seedUid[]\n// let relatedSeedUid: string\n// let relatedSeedUids: string[]\n//\n// if (Array.isArray(propertyValue)) {\n// relatedSeedUids = propertyValue\n// } else {\n// relatedSeedUid = propertyValue\n// }\n//\n// if (relatedSeedUid) {\n// console.log(\n// `[property/actors] [resolveRelatedValue] seedUid: ${relatedSeedUid}`,\n// )\n// const latestVersionOfRelatedSeedQuery = await appDb.run(\n// sql.raw(\n// `\n// SELECT local_id, uid, MAX(attestation_created_at)\n// FROM versions\n// WHERE seed_uid = '${relatedSeedUid}';\n// `,\n// ),\n// )\n// if (\n// latestVersionOfRelatedSeedQuery &&\n// latestVersionOfRelatedSeedQuery.rows &&\n// latestVersionOfRelatedSeedQuery.rows.length > 0\n// ) {\n// const latestVersionOfRelatedSeed =\n// latestVersionOfRelatedSeedQuery.rows[0]\n// console.log(\n// '[property/actors] [resolveRelatedValue] latestVersionOfRelatedSeed',\n// latestVersionOfRelatedSeed,\n// )\n// const storageIdQuery = await appDb.run(\n// sql.raw(\n// `\n// SELECT property_value, MAX(attestation_created_at), ref_resolved_display_value, ref_resolved_value\n// FROM metadata\n// WHERE seed_uid = '${relatedSeedUid}'\n// AND property_name = 'storageTransactionId';\n// `,\n// ),\n// )\n//\n// if (\n// storageIdQuery &&\n// storageIdQuery.rows &&\n// storageIdQuery.rows.length > 0\n// ) {\n// const storageId = storageIdQuery.rows[0][0]\n//\n// if (!storageId) {\n// console.error(\n// `storageId not found for ${propertyName} with relatedSeedUid ${relatedSeedUid}`,\n// )\n// }\n//\n// const refResolvedDisplayValue = storageIdQuery.rows[0][2]\n// let resolvedValue = storageIdQuery.rows[0][3]\n//\n// if (refResolvedDisplayValue && resolvedValue) {\n// sendBack({\n// type: 'resolvingRelatedValueSuccess',\n// refResolvedDisplayValue,\n// resolvedValue,\n// })\n// return\n// }\n//\n// console.log(\n// '[property/actors] [resolveRelatedValue] storageId',\n// storageId,\n// )\n//\n// const contentUrl = await convertTxIdToImage(storageId)\n//\n// if (!contentUrl) {\n// throw new Error(\n// `contentUrl not found for ${propertyName} with relatedSeedUid ${relatedSeedUid}`,\n// )\n// }\n//\n// await appDb.run(\n// sql.raw(\n// `UPDATE metadata\n// SET ref_resolved_display_value = '${contentUrl}',\n// ref_resolved_value = '${storageId}'\n// WHERE seed_uid = '${relatedSeedUid}'\n// AND property_name = 'storageTransactionId';\n// `,\n// ),\n// )\n//\n// sendBack({\n// type: 'resolvingRelatedValueSuccess',\n// refResolvedDisplayValue: contentUrl,\n// resolvedValue: storageId,\n// })\n// }\n// }\n//\n// const versionUidQuery = await appDb.run(\n// sql.raw(\n// `\n// SELECT uid\n// FROM versions\n// WHERE seed_uid = '${relatedSeedUid}';\n// `,\n// ),\n// )\n//\n// if (\n// versionUidQuery &&\n// versionUidQuery.rows &&\n// versionUidQuery.rows.length > 0\n// ) {\n// const versionUids = versionUidQuery.rows.map((row) => row[0])\n// console.log(\n// '[property/actors] [resolveRelatedValue] versionUids',\n// versionUids,\n// )\n// const { itemProperties } = await easClient.request(GET_PROPERTIES, {\n// where: {\n// refUID: {\n// in: versionUids,\n// },\n// decodedDataJson: {\n// contains: 'storage_transaction_id',\n// },\n// },\n// })\n//\n// console.log(\n// '[property/actors] [resolveRelatedValue] itemProperties',\n// itemProperties,\n// )\n//\n// if (itemProperties && itemProperties.length > 0) {\n// await savePropertiesToDb(itemProperties)\n// }\n// }\n// }\n"],"names":[],"mappings":";;;;;;;AAQA,MAAM,MAAM,GAAG,KAAK,CAAC,6CAA6C,CAAC;AAEnE,MAAM,gCAAgC,GAAG,IAAI,GAAG,EAAkB;AAClE,MAAM,4BAA4B,GAAG,IAAI,GAAG,EAAkB;AAC9D,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAAkB;AAExC,MAAA,mBAAmB,GAAG,YAAY,CAG7C,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,KAAI;AACrC,IAAA,MAAM,EACJ,UAAU,EACV,aAAa,EACb,YAAY,EACZ,OAAO,EACP,oBAAoB,EACpB,eAAe,EACf,SAAS,GACV,GAAG,OAAO;AAEX,IAAA,MAAM,oBAAoB,GAAG,YAAW;QACtC,IAAI,CAAC,aAAa,IAAI,CAAC,UAAU,IAAI,eAAe,EAAE;YACpD;;AAGF,QAAA,IAAI,WAAW;AAEf,QAAA,IAAI;AACF,YAAA,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC;;QACvC,OAAO,KAAK,EAAE;AACd,YAAA,MAAM,CAAC,CAAA,EAAG,YAAY,CAAA,4BAAA,CAA8B,CAAC;;QAGvD,IAAI,CAAC,WAAW,IAAI,mBAAmB,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE;YAC1D,MAAM,UAAU,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,OAAO,IAAI;;;;;AAKrB,KAAC;AAED,IAAA,oBAAoB,EAAE,CAAC,IAAI,CAAC,CAAC,OAAO,KAAI;;;;;;;AAOtC,QAAA,QAAQ,CAAC;AACP,YAAA,IAAI,EAAE,2BAA2B;AAClC,SAAA,CAAC;AACJ,KAAC,CAAC;AACJ,CAAC;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"resolveRelatedValue.js","sources":["../../../../../../src/ItemProperty/service/actors/resolveRelatedValue.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { BaseFileManager, convertTxIdToImage } from '@/helpers'\nimport debug from 'debug'\nimport { FromCallbackInput } from '@/types/machines'\nimport { PropertyMachineContext } from '@/types/property'\nimport { getStorageTransactionIdForSeedUid } from '@/db/read/getStorageTransactionIdForSeedUid'\nimport { getRelationValueData } from '@/db/read/getRelationValueData'\n\nconst logger = debug('seedSdk:property:actors:resolveRelatedValue')\n\nconst storageTransactionIdToContentUrl = new Map<string, string>()\nconst refResolvedValueToContentUrl = new Map<string, string>()\nconst seedUidToContentUrl = new Map<string, string>()\n\nexport const resolveRelatedValue = fromCallback<\n EventObject,\n FromCallbackInput<PropertyMachineContext, EventObject>\n>(({ sendBack, input: { context } }) => {\n const {\n isRelation,\n propertyValue,\n propertyName,\n seedUid,\n propertyRecordSchema,\n populatedFromDb,\n schemaUid,\n } = context\n\n const _resolveRelatedValue = async () => {\n if (!propertyValue || !isRelation || populatedFromDb) {\n return\n }\n\n let parsedValue\n\n try {\n parsedValue = JSON.parse(propertyValue)\n } catch (error) {\n logger(`${propertyName} value is not a JSON string.`)\n }\n\n if (!parsedValue && seedUidToContentUrl.has(propertyValue)) {\n const contentUrl = seedUidToContentUrl.get(propertyValue)\n sendBack({\n type: 'updateContext',\n renderValue: contentUrl,\n })\n sendBack({\n type: 'resolvingRelatedValueSuccess',\n refResolvedDisplayValue: contentUrl,\n })\n return true\n }\n\n if (Array.isArray(propertyValue)) {\n // TODO: Handle array of seedUids\n logger(`${propertyName} value is an array of seedUids`)\n return\n }\n\n if (Array.isArray(parsedValue)) {\n logger(`${propertyName} value is a stringified array of seedUids`)\n return\n }\n\n const storageTransactionId =\n await getStorageTransactionIdForSeedUid(propertyValue)\n\n if (storageTransactionId) {\n if (storageTransactionIdToContentUrl.has(storageTransactionId)) {\n const contentUrl =\n storageTransactionIdToContentUrl.get(storageTransactionId)\n sendBack({\n type: 'updateContext',\n renderValue: contentUrl,\n })\n sendBack({\n type: 'resolvingRelatedValueSuccess',\n refResolvedDisplayValue: contentUrl,\n refResolvedValue: storageTransactionId,\n })\n return true\n }\n\n const contentUrl = await convertTxIdToImage(storageTransactionId)\n if (contentUrl) {\n seedUidToContentUrl.set(propertyValue, contentUrl)\n }\n sendBack({\n type: 'updateContext',\n renderValue: contentUrl,\n })\n sendBack({\n type: 'resolvingRelatedValueSuccess',\n refResolvedDisplayValue: contentUrl,\n refResolvedValue: storageTransactionId,\n })\n return true\n }\n\n const relationValueData = await getRelationValueData(propertyValue)\n\n if (relationValueData) {\n const { refResolvedValue } = relationValueData\n const propertyValueFromDb = relationValueData.propertyValue\n\n // This handles a local-only relation value and resolves from the filesystem\n if (\n refResolvedValue &&\n propertyRecordSchema.dataType === 'Relation' &&\n propertyValueFromDb.length === 10 &&\n propertyRecordSchema.ref\n ) {\n if (refResolvedValueToContentUrl.has(refResolvedValue)) {\n const contentUrl = refResolvedValueToContentUrl.get(refResolvedValue)\n sendBack({\n type: 'updateContext',\n renderValue: contentUrl,\n })\n sendBack({\n type: 'resolvingRelatedValueSuccess',\n refResolvedDisplayValue: contentUrl,\n })\n return true\n }\n\n const fileExists = await BaseFileManager.pathExists(\n '/files/images/' + refResolvedValue,\n )\n if (fileExists) {\n const file = await BaseFileManager.readFile(\n '/files/images/' + refResolvedValue,\n )\n const contentUrl = URL.createObjectURL(file)\n refResolvedValueToContentUrl.set(refResolvedValue, contentUrl)\n sendBack({\n type: 'updateContext',\n renderValue: contentUrl,\n })\n sendBack({\n type: 'resolvingRelatedValueSuccess',\n refResolvedDisplayValue: contentUrl,\n })\n return true\n }\n }\n\n if (typeof propertyValueFromDb === 'string') {\n // Check files for a filename that matches the propertyValue\n if (\n propertyRecordSchema &&\n propertyRecordSchema.refValueType === 'Image'\n ) {\n let contentUrl\n\n if (storageTransactionIdToContentUrl.has(propertyValueFromDb)) {\n contentUrl =\n storageTransactionIdToContentUrl.get(propertyValueFromDb)\n }\n\n if (!contentUrl) {\n const imageFileExists = await BaseFileManager.pathExists(\n `/images/${propertyValue}`,\n )\n if (imageFileExists) {\n const file = await BaseFileManager.readFile(\n `/images/${propertyValue}`,\n )\n contentUrl = URL.createObjectURL(file)\n storageTransactionIdToContentUrl.set(\n propertyValueFromDb,\n contentUrl,\n )\n }\n }\n\n if (contentUrl) {\n sendBack({\n type: 'updateContext',\n renderValue: contentUrl,\n })\n sendBack({\n type: 'resolvingRelatedValueSuccess',\n refResolvedDisplayValue: contentUrl,\n })\n return true\n }\n }\n }\n }\n }\n\n _resolveRelatedValue().then((success) => {\n // if (success) {\n // sendBack({\n // type: 'resolvingRelatedValueDone',\n // })\n // }\n // return\n sendBack({\n type: 'resolvingRelatedValueDone',\n })\n })\n})\n\n// const eventKey = `storage.transaction.${initialValue}.contentUrl.response`\n//\n// const contentUrlListener = async (event) => {\n// console.log('[itemProperty] [constructor] contentUrlListener', event)\n// }\n//\n// eventEmitter.once(eventKey, contentUrlListener)\n//\n// const ready = getArePropertyEventHandlersReady()\n//\n// console.log('[itemProperty] [constructor] ready', ready)\n//\n// eventEmitter.emit('storage.transaction.contentUrl.request', {\n// storageTransactionId: initialValue,\n// })\n\n// Related property values can either be seedUid or seedUid[]\n// let relatedSeedUid: string\n// let relatedSeedUids: string[]\n//\n// if (Array.isArray(propertyValue)) {\n// relatedSeedUids = propertyValue\n// } else {\n// relatedSeedUid = propertyValue\n// }\n//\n// if (relatedSeedUid) {\n// console.log(\n// `[property/actors] [resolveRelatedValue] seedUid: ${relatedSeedUid}`,\n// )\n// const latestVersionOfRelatedSeedQuery = await appDb.run(\n// sql.raw(\n// `\n// SELECT local_id, uid, MAX(attestation_created_at)\n// FROM versions\n// WHERE seed_uid = '${relatedSeedUid}';\n// `,\n// ),\n// )\n// if (\n// latestVersionOfRelatedSeedQuery &&\n// latestVersionOfRelatedSeedQuery.rows &&\n// latestVersionOfRelatedSeedQuery.rows.length > 0\n// ) {\n// const latestVersionOfRelatedSeed =\n// latestVersionOfRelatedSeedQuery.rows[0]\n// console.log(\n// '[property/actors] [resolveRelatedValue] latestVersionOfRelatedSeed',\n// latestVersionOfRelatedSeed,\n// )\n// const storageIdQuery = await appDb.run(\n// sql.raw(\n// `\n// SELECT property_value, MAX(attestation_created_at), ref_resolved_display_value, ref_resolved_value\n// FROM metadata\n// WHERE seed_uid = '${relatedSeedUid}'\n// AND property_name = 'storageTransactionId';\n// `,\n// ),\n// )\n//\n// if (\n// storageIdQuery &&\n// storageIdQuery.rows &&\n// storageIdQuery.rows.length > 0\n// ) {\n// const storageId = storageIdQuery.rows[0][0]\n//\n// if (!storageId) {\n// console.error(\n// `storageId not found for ${propertyName} with relatedSeedUid ${relatedSeedUid}`,\n// )\n// }\n//\n// const refResolvedDisplayValue = storageIdQuery.rows[0][2]\n// let resolvedValue = storageIdQuery.rows[0][3]\n//\n// if (refResolvedDisplayValue && resolvedValue) {\n// sendBack({\n// type: 'resolvingRelatedValueSuccess',\n// refResolvedDisplayValue,\n// resolvedValue,\n// })\n// return\n// }\n//\n// console.log(\n// '[property/actors] [resolveRelatedValue] storageId',\n// storageId,\n// )\n//\n// const contentUrl = await convertTxIdToImage(storageId)\n//\n// if (!contentUrl) {\n// throw new Error(\n// `contentUrl not found for ${propertyName} with relatedSeedUid ${relatedSeedUid}`,\n// )\n// }\n//\n// await appDb.run(\n// sql.raw(\n// `UPDATE metadata\n// SET ref_resolved_display_value = '${contentUrl}',\n// ref_resolved_value = '${storageId}'\n// WHERE seed_uid = '${relatedSeedUid}'\n// AND property_name = 'storageTransactionId';\n// `,\n// ),\n// )\n//\n// sendBack({\n// type: 'resolvingRelatedValueSuccess',\n// refResolvedDisplayValue: contentUrl,\n// resolvedValue: storageId,\n// })\n// }\n// }\n//\n// const versionUidQuery = await appDb.run(\n// sql.raw(\n// `\n// SELECT uid\n// FROM versions\n// WHERE seed_uid = '${relatedSeedUid}';\n// `,\n// ),\n// )\n//\n// if (\n// versionUidQuery &&\n// versionUidQuery.rows &&\n// versionUidQuery.rows.length > 0\n// ) {\n// const versionUids = versionUidQuery.rows.map((row) => row[0])\n// console.log(\n// '[property/actors] [resolveRelatedValue] versionUids',\n// versionUids,\n// )\n// const { itemProperties } = await easClient.request(GET_PROPERTIES, {\n// where: {\n// refUID: {\n// in: versionUids,\n// },\n// decodedDataJson: {\n// contains: 'storage_transaction_id',\n// },\n// },\n// })\n//\n// console.log(\n// '[property/actors] [resolveRelatedValue] itemProperties',\n// itemProperties,\n// )\n//\n// if (itemProperties && itemProperties.length > 0) {\n// await savePropertiesToDb(itemProperties)\n// }\n// }\n// }\n"],"names":[],"mappings":";;;;;;;AAQA,MAAM,MAAM,GAAG,KAAK,CAAC,6CAA6C,CAAC;AAEnE,MAAM,gCAAgC,GAAG,IAAI,GAAG,EAAkB;AAClE,MAAM,4BAA4B,GAAG,IAAI,GAAG,EAAkB;AAC9D,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAAkB;AAE9C,MAAM,mBAAmB,GAAG,YAAY,CAG7C,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,KAAI;AACrC,IAAA,MAAM,EACJ,UAAU,EACV,aAAa,EACb,YAAY,EACZ,OAAO,EACP,oBAAoB,EACpB,eAAe,EACf,SAAS,GACV,GAAG,OAAO;AAEX,IAAA,MAAM,oBAAoB,GAAG,YAAW;QACtC,IAAI,CAAC,aAAa,IAAI,CAAC,UAAU,IAAI,eAAe,EAAE;YACpD;QACF;AAEA,QAAA,IAAI,WAAW;AAEf,QAAA,IAAI;AACF,YAAA,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC;QACzC;QAAE,OAAO,KAAK,EAAE;AACd,YAAA,MAAM,CAAC,CAAA,EAAG,YAAY,CAAA,4BAAA,CAA8B,CAAC;QACvD;QAEA,IAAI,CAAC,WAAW,IAAI,mBAAmB,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE;YAC1D,MAAM,UAAU,GAAG,mBAAmB,CAAC,GAAG,CAAC,aAAa,CAAC;AACzD,YAAA,QAAQ,CAAC;AACP,gBAAA,IAAI,EAAE,eAAe;AACrB,gBAAA,WAAW,EAAE,UAAU;AACxB,aAAA,CAAC;AACF,YAAA,QAAQ,CAAC;AACP,gBAAA,IAAI,EAAE,8BAA8B;AACpC,gBAAA,uBAAuB,EAAE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,SAAA,CAAC;AACJ,IAAA,CAAC,CAAC;AACJ,CAAC;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveRemoteStorage.js","sources":["../../../../../../src/ItemProperty/service/actors/resolveRemoteStorage.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { FromCallbackInput } from '@/types/machines'\nimport { PropertyMachineContext } from '@/types/property'\nimport { BaseFileManager } from '@/helpers/FileManager/BaseFileManager'\n\n\nexport const resolveRemoteStorage = fromCallback<\n EventObject,\n FromCallbackInput<PropertyMachineContext, EventObject>\n>(({ sendBack, input: { context } }) => {\n const { propertyInstances } = context\n\n if (!propertyInstances) {\n throw new Error(`propertyInstances not found for ${context.seedLocalId}`)\n }\n\n if (!propertyInstances.has('storageTransactionId')) {\n return\n }\n\n const storageTransactionId = propertyInstances.get('storageTransactionId')\n\n const _resolveRemoteStorage = async (): Promise<void> => {\n\n const filesDirExists = await BaseFileManager.pathExists('/files')\n\n if (!filesDirExists) {\n await BaseFileManager.createDirIfNotExists('/files')\n }\n\n const path = BaseFileManager.getPathModule()\n\n const htmlDir = path.join('/files', 'html')\n\n const htmlExists = await BaseFileManager.pathExists(htmlDir)\n\n const fs = await BaseFileManager.getFs()\n\n if (htmlExists) {\n const htmlFiles = await fs.promises.readdir(htmlDir)\n const matchingHtmlFile = htmlFiles.find(\n (file: string) => file === `${storageTransactionId}.html`,\n )\n if (matchingHtmlFile) {\n const htmlString = await fs.promises.readFile(\n path.join(htmlDir, matchingHtmlFile),\n 'utf8',\n )\n sendBack({\n type: 'updateValue',\n propertyName: 'html',\n propertyValue: htmlString,\n })\n }\n }\n\n if (!htmlExists) {\n await fs.promises.mkdir(htmlDir)\n }\n\n const jsonDir = path.join('/files', 'json')\n\n const jsonExists = await fs.promises.exists(jsonDir)\n\n if (jsonExists) {\n const jsonFiles = await fs.promises.readdir(jsonDir)\n const matchingJsonFile = jsonFiles.find(\n (file: string) => file === `${storageTransactionId}.json`,\n )\n if (matchingJsonFile) {\n const jsonString = await fs.promises.readFile(\n path.join(jsonDir, matchingJsonFile),\n 'utf8',\n )\n sendBack({\n type: 'updateValue',\n propertyName: 'json',\n propertyValue: jsonString,\n })\n }\n }\n\n if (!jsonExists) {\n await fs.promises.mkdir(jsonDir)\n }\n }\n\n _resolveRemoteStorage().then(() => {\n sendBack({ type: 'resolveRemoteStorageSuccess' })\n return\n })\n})\n"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"resolveRemoteStorage.js","sources":["../../../../../../src/ItemProperty/service/actors/resolveRemoteStorage.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { FromCallbackInput } from '@/types/machines'\nimport { PropertyMachineContext } from '@/types/property'\nimport { BaseFileManager } from '@/helpers/FileManager/BaseFileManager'\n\n\nexport const resolveRemoteStorage = fromCallback<\n EventObject,\n FromCallbackInput<PropertyMachineContext, EventObject>\n>(({ sendBack, input: { context } }) => {\n const { propertyInstances } = context\n\n if (!propertyInstances) {\n throw new Error(`propertyInstances not found for ${context.seedLocalId}`)\n }\n\n if (!propertyInstances.has('storageTransactionId')) {\n return\n }\n\n const storageTransactionId = propertyInstances.get('storageTransactionId')\n\n const _resolveRemoteStorage = async (): Promise<void> => {\n\n const filesDirExists = await BaseFileManager.pathExists('/files')\n\n if (!filesDirExists) {\n await BaseFileManager.createDirIfNotExists('/files')\n }\n\n const path = BaseFileManager.getPathModule()\n\n const htmlDir = path.join('/files', 'html')\n\n const htmlExists = await BaseFileManager.pathExists(htmlDir)\n\n const fs = await BaseFileManager.getFs()\n\n if (htmlExists) {\n const htmlFiles = await fs.promises.readdir(htmlDir)\n const matchingHtmlFile = htmlFiles.find(\n (file: string) => file === `${storageTransactionId}.html`,\n )\n if (matchingHtmlFile) {\n const htmlString = await fs.promises.readFile(\n path.join(htmlDir, matchingHtmlFile),\n 'utf8',\n )\n sendBack({\n type: 'updateValue',\n propertyName: 'html',\n propertyValue: htmlString,\n })\n }\n }\n\n if (!htmlExists) {\n await fs.promises.mkdir(htmlDir)\n }\n\n const jsonDir = path.join('/files', 'json')\n\n const jsonExists = await fs.promises.exists(jsonDir)\n\n if (jsonExists) {\n const jsonFiles = await fs.promises.readdir(jsonDir)\n const matchingJsonFile = jsonFiles.find(\n (file: string) => file === `${storageTransactionId}.json`,\n )\n if (matchingJsonFile) {\n const jsonString = await fs.promises.readFile(\n path.join(jsonDir, matchingJsonFile),\n 'utf8',\n )\n sendBack({\n type: 'updateValue',\n propertyName: 'json',\n propertyValue: jsonString,\n })\n }\n }\n\n if (!jsonExists) {\n await fs.promises.mkdir(jsonDir)\n }\n }\n\n _resolveRemoteStorage().then(() => {\n sendBack({ type: 'resolveRemoteStorageSuccess' })\n return\n })\n})\n"],"names":[],"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AACF,IAAA,CAAC,CAAC;AACJ,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyzeInput.js","sources":["../../../../../../../src/ItemProperty/service/actors/saveValueToDb/analyzeInput.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { FromCallbackInput } from '@/types/machines'\nimport {\n ItemPropertyValueType,\n PropertyMachineContext,\n SaveValueToDbEvent,\n} from '@/types/property'\nimport { updateItemPropertyValue } from '@/db/write/updateItemPropertyValue'\n\nimport { getSchemaForItemProperty } from '@/helpers/getSchemaForItemProperty'\nimport { INTERNAL_DATA_TYPES } from '@/helpers/constants'\nimport { TypedData } from '@ethereum-attestation-service/eas-sdk/dist/offchain/typed-data-handler'\n\nexport const analyzeInput = fromCallback<\n EventObject,\n FromCallbackInput<PropertyMachineContext, SaveValueToDbEvent>\n>(({ sendBack, input: { context, event } }) => {\n const {\n localId,\n propertyName: propertyNameRaw,\n seedLocalId,\n versionLocalId,\n versionUid,\n propertyValue: existingValue,\n propertyRecordSchema,\n modelName,\n } = context\n\n let { schemaUid } = context\n\n let newValue: ItemPropertyValueType\n\n if (event) {\n newValue = event.newValue\n }\n\n if (existingValue === newValue) {\n sendBack({ type: 'saveValueToDbSuccess' })\n return\n }\n\n if (!propertyRecordSchema) {\n throw new Error('Missing propertyRecordSchema')\n }\n\n const _analyzeInput = async (): Promise<boolean> => {\n let propertyName = propertyNameRaw\n\n if (\n propertyRecordSchema.refValueType &&\n propertyRecordSchema.refValueType !== 'Image' &&\n propertyRecordSchema.dataType === 'Relation'\n ) {\n sendBack({\n type: 'saveRelation',\n newValue,\n })\n return false\n }\n\n if (\n propertyRecordSchema.refValueType === 'Image' ||\n propertyRecordSchema.dataType === 'Image'\n ) {\n sendBack({\n type: 'saveImage',\n newValue,\n })\n return false\n }\n\n if (\n propertyRecordSchema.storageType &&\n propertyRecordSchema.storageType === 'ItemStorage'\n ) {\n sendBack({\n type: 'saveItemStorage',\n newValue,\n })\n return false\n }\n\n if (!schemaUid) {\n let easDataType\n\n if (propertyRecordSchema.dataType) {\n easDataType = INTERNAL_DATA_TYPES[propertyRecordSchema.dataType]\n .eas as TypedData['type']\n }\n\n const schemaFromEas = await getSchemaForItemProperty({\n propertyName,\n easDataType,\n })\n if (schemaFromEas) {\n schemaUid = schemaFromEas.id\n }\n }\n\n const result = await updateItemPropertyValue({\n localId,\n propertyName,\n newValue,\n seedLocalId,\n versionLocalId,\n versionUid,\n modelName,\n schemaUid,\n })\n\n let updatedContext: Partial<PropertyMachineContext> = {\n propertyValue: newValue,\n }\n\n if (localId) {\n updatedContext.localId = localId\n }\n\n if (schemaUid) {\n updatedContext.schemaUid = schemaUid\n }\n\n if (!localId && result?.localId) {\n updatedContext.localId = result.localId\n }\n\n if (!schemaUid && result?.schemaUid) {\n updatedContext.schemaUid = result.schemaUid\n }\n\n sendBack({\n type: 'updateContext',\n ...updatedContext,\n })\n\n return true\n }\n\n _analyzeInput().then((isDone) => {\n if (isDone) {\n sendBack({ type: 'saveValueToDbSuccess' })\n }\n })\n})\n"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"analyzeInput.js","sources":["../../../../../../../src/ItemProperty/service/actors/saveValueToDb/analyzeInput.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { FromCallbackInput } from '@/types/machines'\nimport {\n ItemPropertyValueType,\n PropertyMachineContext,\n SaveValueToDbEvent,\n} from '@/types/property'\nimport { updateItemPropertyValue } from '@/db/write/updateItemPropertyValue'\n\nimport { getSchemaForItemProperty } from '@/helpers/getSchemaForItemProperty'\nimport { INTERNAL_DATA_TYPES } from '@/helpers/constants'\nimport { TypedData } from '@ethereum-attestation-service/eas-sdk/dist/offchain/typed-data-handler'\n\nexport const analyzeInput = fromCallback<\n EventObject,\n FromCallbackInput<PropertyMachineContext, SaveValueToDbEvent>\n>(({ sendBack, input: { context, event } }) => {\n const {\n localId,\n propertyName: propertyNameRaw,\n seedLocalId,\n versionLocalId,\n versionUid,\n propertyValue: existingValue,\n propertyRecordSchema,\n modelName,\n } = context\n\n let { schemaUid } = context\n\n let newValue: ItemPropertyValueType\n\n if (event) {\n newValue = event.newValue\n }\n\n if (existingValue === newValue) {\n sendBack({ type: 'saveValueToDbSuccess' })\n return\n }\n\n if (!propertyRecordSchema) {\n throw new Error('Missing propertyRecordSchema')\n }\n\n const _analyzeInput = async (): Promise<boolean> => {\n let propertyName = propertyNameRaw\n\n if (\n propertyRecordSchema.refValueType &&\n propertyRecordSchema.refValueType !== 'Image' &&\n propertyRecordSchema.dataType === 'Relation'\n ) {\n sendBack({\n type: 'saveRelation',\n newValue,\n })\n return false\n }\n\n if (\n propertyRecordSchema.refValueType === 'Image' ||\n propertyRecordSchema.dataType === 'Image'\n ) {\n sendBack({\n type: 'saveImage',\n newValue,\n })\n return false\n }\n\n if (\n propertyRecordSchema.storageType &&\n propertyRecordSchema.storageType === 'ItemStorage'\n ) {\n sendBack({\n type: 'saveItemStorage',\n newValue,\n })\n return false\n }\n\n if (!schemaUid) {\n let easDataType\n\n if (propertyRecordSchema.dataType) {\n easDataType = INTERNAL_DATA_TYPES[propertyRecordSchema.dataType]\n .eas as TypedData['type']\n }\n\n const schemaFromEas = await getSchemaForItemProperty({\n propertyName,\n easDataType,\n })\n if (schemaFromEas) {\n schemaUid = schemaFromEas.id\n }\n }\n\n const result = await updateItemPropertyValue({\n localId,\n propertyName,\n newValue,\n seedLocalId,\n versionLocalId,\n versionUid,\n modelName,\n schemaUid,\n })\n\n let updatedContext: Partial<PropertyMachineContext> = {\n propertyValue: newValue,\n }\n\n if (localId) {\n updatedContext.localId = localId\n }\n\n if (schemaUid) {\n updatedContext.schemaUid = schemaUid\n }\n\n if (!localId && result?.localId) {\n updatedContext.localId = result.localId\n }\n\n if (!schemaUid && result?.schemaUid) {\n updatedContext.schemaUid = result.schemaUid\n }\n\n sendBack({\n type: 'updateContext',\n ...updatedContext,\n })\n\n return true\n }\n\n _analyzeInput().then((isDone) => {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cAAc;AAClB,SAAA,CAAC;AAEF,QAAA,OAAO,IAAI;AACb,IAAA,CAAC;AAED,IAAA,aAAa,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,KAAI;QAC9B,IAAI,MAAM,EAAE;AACV,YAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,sBAAsB,EAAE,CAAC;QAC5C;AACF,IAAA,CAAC,CAAC;AACJ,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"saveImage.js","sources":["../../../../../../../src/ItemProperty/service/actors/saveValueToDb/saveImage.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { FromCallbackInput } from '@/types/machines'\nimport {\n ItemPropertyValueType,\n PropertyMachineContext,\n SaveValueToDbEvent,\n} from '@/types/property'\nimport { createSeed } from '@/db/write/createSeed'\nimport { getDataTypeFromString, getMimeType } from '@/helpers'\nimport { createVersion } from '@/db/write/createVersion'\nimport { createMetadata } from '@/db/write/createMetadata'\nimport { updateItemPropertyValue } from '@/db/write/updateItemPropertyValue'\nimport { getSchemaUidForModel } from '@/db/read/getSchemaUidForModel'\nimport { BaseFileManager } from '@/helpers/FileManager/BaseFileManager'\nimport { eventEmitter } from '@/eventBus'\nimport { ImageSize } from '@/helpers/constants'\n\n\nconst readFileAsArrayBuffer = async (file: File): Promise<ArrayBuffer> => {\n return new Promise((resolve) => {\n const reader = new FileReader()\n reader.onload = async (e) => {\n const arrayBuffer = e.target.result as ArrayBuffer\n\n resolve(arrayBuffer)\n }\n\n reader.readAsArrayBuffer(file)\n })\n}\n\nconst fetchImage = async (url: string) => {\n const response = await fetch(url)\n const mimeType = response.headers.get('Content-Type')\n const imageBuffer = await response.arrayBuffer()\n const bytes = new Uint8Array(imageBuffer)\n\n const binaryString = bytes.reduce(\n (acc, byte) => acc + String.fromCharCode(byte),\n '',\n )\n\n let base64 = btoa(binaryString)\n\n if (mimeType) {\n base64 = `data:${mimeType};base64,${base64}`\n }\n\n return base64\n}\n\nlet imageSchemaUid: string | undefined\n\nexport const saveImage = fromCallback<\n EventObject,\n FromCallbackInput<PropertyMachineContext, SaveValueToDbEvent>\n>(({ sendBack, input: { context, event } }) => {\n const {\n localId,\n propertyName: propertyNameRaw,\n propertyValue: existingValue,\n propertyRecordSchema,\n modelName,\n seedLocalId,\n seedUid,\n versionLocalId,\n versionUid,\n } = context\n\n let { schemaUid } = context\n\n let newValue: ItemPropertyValueType\n\n if (event) {\n newValue = event.newValue\n }\n\n if (existingValue === newValue) {\n sendBack({ type: 'saveValueToDbSuccess' })\n return\n }\n\n const _saveImage = async (): Promise<void> => {\n let propertyName = propertyNameRaw\n\n if (!propertyNameRaw.endsWith('Id')) {\n propertyName = `${propertyName}Id`\n }\n\n let newValueType\n let fileData: string | ArrayBuffer | undefined\n let mimeType\n let fileName\n\n if (!imageSchemaUid) {\n imageSchemaUid = await getSchemaUidForModel('Image')\n }\n\n if (typeof newValue === 'string') {\n newValueType = getDataTypeFromString(newValue)\n }\n\n if (newValueType === 'imageBase64') {\n mimeType = getMimeType(newValue as string)\n const base64Data = (newValue as string).split(',')[1] // Strip the Base64 prefix\n const binaryString = atob(base64Data)\n\n const binaryLength = binaryString.length\n const binaryArray = new Uint8Array(binaryLength)\n for (let i = 0; i < binaryLength; i++) {\n binaryArray[i] = binaryString.charCodeAt(i)\n }\n fileData = binaryArray.buffer\n }\n\n if (newValueType === 'url') {\n fileData = await fetchImage(newValue as string)\n }\n\n if (newValue instanceof File) {\n fileName = newValue.name\n mimeType = newValue.type\n fileData = await readFileAsArrayBuffer(newValue)\n }\n\n if (!fileData) {\n throw new Error('No file data found')\n }\n\n const newImageSeedLocalId = await createSeed({\n type: 'image',\n })\n\n if (!fileName) {\n fileName = newImageSeedLocalId\n if (mimeType) {\n fileName += `.${mimeType.split('/')[1]}`\n }\n }\n\n const filePath = `/files/images/${fileName}`\n\n const imageVersionLocalId = await createVersion({\n seedLocalId: newImageSeedLocalId,\n seedType: 'image',\n })\n\n if (fileData instanceof ArrayBuffer) {\n try {\n await BaseFileManager.saveFile(filePath, new Uint8Array(fileData))\n } catch (e) {\n const fs = await BaseFileManager.getFs()\n fs.writeFileSync(filePath, new Uint8Array(fileData))\n eventEmitter.emit('file-saved', filePath)\n }\n }\n\n if (typeof fileData === 'string') {\n try {\n await BaseFileManager.saveFile(filePath, fileData)\n } catch (e) {\n const fs = await BaseFileManager.getFs()\n fs.writeFileSync(filePath, fileData)\n eventEmitter.emit('file-saved', filePath)\n }\n }\n\n\n await BaseFileManager.resizeImage({filePath, width: ImageSize.EXTRA_SMALL, height: ImageSize.EXTRA_SMALL})\n await BaseFileManager.resizeImage({filePath, width: ImageSize.SMALL, height: ImageSize.SMALL})\n await BaseFileManager.resizeImage({filePath, width: ImageSize.MEDIUM, height: ImageSize.MEDIUM})\n await BaseFileManager.resizeImage({filePath, width: ImageSize.LARGE, height: ImageSize.LARGE})\n await BaseFileManager.resizeImage({filePath, width: ImageSize.EXTRA_LARGE, height: ImageSize.EXTRA_LARGE})\n\n const refResolvedDisplayValue = await BaseFileManager.getContentUrlFromPath(filePath)\n\n let newLocalId\n\n if (!localId) {\n const result = await createMetadata(\n {\n propertyName,\n propertyValue: newImageSeedLocalId,\n seedLocalId,\n seedUid,\n versionLocalId,\n versionUid,\n modelName,\n schemaUid,\n refSeedType: 'image',\n refModelUid: imageSchemaUid,\n refSchemaUid: imageSchemaUid,\n refResolvedDisplayValue,\n refResolvedValue: fileName,\n localStorageDir: '/images',\n easDataType: 'bytes32',\n },\n propertyRecordSchema,\n )\n\n newLocalId = result[0].localId\n }\n\n if (localId) {\n await updateItemPropertyValue({\n localId: localId,\n propertyName: propertyNameRaw,\n newValue: newImageSeedLocalId,\n seedLocalId,\n versionLocalId,\n modelName,\n schemaUid,\n refSeedType: 'image',\n refResolvedDisplayValue,\n refResolvedValue: fileName,\n refModelUid: imageSchemaUid,\n refSchemaUid: imageSchemaUid,\n localStorageDir: '/images',\n easDataType: 'bytes32',\n })\n }\n\n sendBack({\n type: 'updateContext',\n localId: newLocalId || localId,\n propertyValue: newImageSeedLocalId,\n refSeedType: 'image',\n refSchemaUid: imageSchemaUid,\n renderValue: refResolvedDisplayValue,\n refResolvedDisplayValue,\n refResolvedValue: fileName,\n localStorageDir: '/images',\n easDataType: 'bytes32',\n schemaUid,\n })\n }\n\n _saveImage().then(() => {\n sendBack({ type: 'saveImageSuccess' })\n })\n})\n"],"names":[],"mappings":";;;;;;;;;;;AAkBA,MAAM,qBAAqB,GAAG,OAAO,IAAU,KAA0B;AACvE,IAAA,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,KAAI;AAC7B,QAAA,MAAM,MAAM,GAAG,IAAI,UAAU,EAAE;AAC/B,QAAA,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,KAAI;AAC1B,YAAA,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,MAAqB;YAElD,OAAO,CAAC,WAAW,CAAC;AACtB,SAAC;AAED,QAAA,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC;AAChC,KAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,GAAG,OAAO,GAAW,KAAI;AACvC,IAAA,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC;IACjC,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;AACrD,IAAA,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,WAAW,EAAE;AAChD,IAAA,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC;IAEzC,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAC/B,CAAC,GAAG,EAAE,IAAI,KAAK,GAAG,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,EAC9C,EAAE,CACH;AAED,IAAA,IAAI,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC;IAE/B,IAAI,QAAQ,EAAE;AACZ,QAAA,MAAM,GAAG,CAAQ,KAAA,EAA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OAAO,EAAE,UAAU,IAAI,OAAO;AAC9B,YAAA,aAAa,EAAE,mBAAmB;AAClC,YAAA,WAAW,EAAE,OAAO;AACpB,YAAA,YAAY,EAAE,cAAc;AAC5B,YAAA,WAAW,EAAE,uBAAuB;YACpC,uBAAuB;AACvB,YAAA,gBAAgB,EAAE,QAAQ;AAC1B,YAAA,eAAe,EAAE,SAAS;AAC1B,YAAA,WAAW,EAAE,SAAS;YACtB,SAAS;AACV,SAAA,CAAC;AACJ,KAAC;AAED,IAAA,UAAU,EAAE,CAAC,IAAI,CAAC,MAAK;AACrB,QAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC;AACxC,KAAC,CAAC;AACJ,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"saveImage.js","sources":["../../../../../../../src/ItemProperty/service/actors/saveValueToDb/saveImage.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { FromCallbackInput } from '@/types/machines'\nimport {\n ItemPropertyValueType,\n PropertyMachineContext,\n SaveValueToDbEvent,\n} from '@/types/property'\nimport { createSeed } from '@/db/write/createSeed'\nimport { getDataTypeFromString, getMimeType } from '@/helpers'\nimport { createVersion } from '@/db/write/createVersion'\nimport { createMetadata } from '@/db/write/createMetadata'\nimport { updateItemPropertyValue } from '@/db/write/updateItemPropertyValue'\nimport { getSchemaUidForModel } from '@/db/read/getSchemaUidForModel'\nimport { BaseFileManager } from '@/helpers/FileManager/BaseFileManager'\nimport { eventEmitter } from '@/eventBus'\nimport { ImageSize } from '@/helpers/constants'\n\n\nconst readFileAsArrayBuffer = async (file: File): Promise<ArrayBuffer> => {\n return new Promise((resolve) => {\n const reader = new FileReader()\n reader.onload = async (e) => {\n const arrayBuffer = e.target.result as ArrayBuffer\n\n resolve(arrayBuffer)\n }\n\n reader.readAsArrayBuffer(file)\n })\n}\n\nconst fetchImage = async (url: string) => {\n const response = await fetch(url)\n const mimeType = response.headers.get('Content-Type')\n const imageBuffer = await response.arrayBuffer()\n const bytes = new Uint8Array(imageBuffer)\n\n const binaryString = bytes.reduce(\n (acc, byte) => acc + String.fromCharCode(byte),\n '',\n )\n\n let base64 = btoa(binaryString)\n\n if (mimeType) {\n base64 = `data:${mimeType};base64,${base64}`\n }\n\n return base64\n}\n\nlet imageSchemaUid: string | undefined\n\nexport const saveImage = fromCallback<\n EventObject,\n FromCallbackInput<PropertyMachineContext, SaveValueToDbEvent>\n>(({ sendBack, input: { context, event } }) => {\n const {\n localId,\n propertyName: propertyNameRaw,\n propertyValue: existingValue,\n propertyRecordSchema,\n modelName,\n seedLocalId,\n seedUid,\n versionLocalId,\n versionUid,\n } = context\n\n let { schemaUid } = context\n\n let newValue: ItemPropertyValueType\n\n if (event) {\n newValue = event.newValue\n }\n\n if (existingValue === newValue) {\n sendBack({ type: 'saveValueToDbSuccess' })\n return\n }\n\n const _saveImage = async (): Promise<void> => {\n let propertyName = propertyNameRaw\n\n if (!propertyNameRaw.endsWith('Id')) {\n propertyName = `${propertyName}Id`\n }\n\n let newValueType\n let fileData: string | ArrayBuffer | undefined\n let mimeType\n let fileName\n\n if (!imageSchemaUid) {\n imageSchemaUid = await getSchemaUidForModel('Image')\n }\n\n if (typeof newValue === 'string') {\n newValueType = getDataTypeFromString(newValue)\n }\n\n if (newValueType === 'imageBase64') {\n mimeType = getMimeType(newValue as string)\n const base64Data = (newValue as string).split(',')[1] // Strip the Base64 prefix\n const binaryString = atob(base64Data)\n\n const binaryLength = binaryString.length\n const binaryArray = new Uint8Array(binaryLength)\n for (let i = 0; i < binaryLength; i++) {\n binaryArray[i] = binaryString.charCodeAt(i)\n }\n fileData = binaryArray.buffer\n }\n\n if (newValueType === 'url') {\n fileData = await fetchImage(newValue as string)\n }\n\n if (newValue instanceof File) {\n fileName = newValue.name\n mimeType = newValue.type\n fileData = await readFileAsArrayBuffer(newValue)\n }\n\n if (!fileData) {\n throw new Error('No file data found')\n }\n\n const newImageSeedLocalId = await createSeed({\n type: 'image',\n })\n\n if (!fileName) {\n fileName = newImageSeedLocalId\n if (mimeType) {\n fileName += `.${mimeType.split('/')[1]}`\n }\n }\n\n const filePath = `/files/images/${fileName}`\n\n const imageVersionLocalId = await createVersion({\n seedLocalId: newImageSeedLocalId,\n seedType: 'image',\n })\n\n if (fileData instanceof ArrayBuffer) {\n try {\n await BaseFileManager.saveFile(filePath, new Uint8Array(fileData))\n } catch (e) {\n const fs = await BaseFileManager.getFs()\n fs.writeFileSync(filePath, new Uint8Array(fileData))\n eventEmitter.emit('file-saved', filePath)\n }\n }\n\n if (typeof fileData === 'string') {\n try {\n await BaseFileManager.saveFile(filePath, fileData)\n } catch (e) {\n const fs = await BaseFileManager.getFs()\n fs.writeFileSync(filePath, fileData)\n eventEmitter.emit('file-saved', filePath)\n }\n }\n\n\n await BaseFileManager.resizeImage({filePath, width: ImageSize.EXTRA_SMALL, height: ImageSize.EXTRA_SMALL})\n await BaseFileManager.resizeImage({filePath, width: ImageSize.SMALL, height: ImageSize.SMALL})\n await BaseFileManager.resizeImage({filePath, width: ImageSize.MEDIUM, height: ImageSize.MEDIUM})\n await BaseFileManager.resizeImage({filePath, width: ImageSize.LARGE, height: ImageSize.LARGE})\n await BaseFileManager.resizeImage({filePath, width: ImageSize.EXTRA_LARGE, height: ImageSize.EXTRA_LARGE})\n\n const refResolvedDisplayValue = await BaseFileManager.getContentUrlFromPath(filePath)\n\n let newLocalId\n\n if (!localId) {\n const result = await createMetadata(\n {\n propertyName,\n propertyValue: newImageSeedLocalId,\n seedLocalId,\n seedUid,\n versionLocalId,\n versionUid,\n modelName,\n schemaUid,\n refSeedType: 'image',\n refModelUid: imageSchemaUid,\n refSchemaUid: imageSchemaUid,\n refResolvedDisplayValue,\n refResolvedValue: fileName,\n localStorageDir: '/images',\n easDataType: 'bytes32',\n },\n propertyRecordSchema,\n )\n\n newLocalId = result[0].localId\n }\n\n if (localId) {\n await updateItemPropertyValue({\n localId: localId,\n propertyName: propertyNameRaw,\n newValue: newImageSeedLocalId,\n seedLocalId,\n versionLocalId,\n modelName,\n schemaUid,\n refSeedType: 'image',\n refResolvedDisplayValue,\n refResolvedValue: fileName,\n refModelUid: imageSchemaUid,\n refSchemaUid: imageSchemaUid,\n localStorageDir: '/images',\n easDataType: 'bytes32',\n })\n }\n\n sendBack({\n type: 'updateContext',\n localId: newLocalId || localId,\n propertyValue: newImageSeedLocalId,\n refSeedType: 'image',\n refSchemaUid: imageSchemaUid,\n renderValue: refResolvedDisplayValue,\n refResolvedDisplayValue,\n refResolvedValue: fileName,\n localStorageDir: '/images',\n easDataType: 'bytes32',\n schemaUid,\n })\n }\n\n _saveImage().then(() => {\n sendBack({ type: 'saveImageSuccess' })\n })\n})\n"],"names":[],"mappings":";;;;;;;;;;;AAkBA,MAAM,qBAAqB,GAAG,OAAO,IAAU,KAA0B;AACvE,IAAA,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,KAAI;AAC7B,QAAA,MAAM,MAAM,GAAG,IAAI,UAAU,EAAE;AAC/B,QAAA,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,KAAI;AAC1B,YAAA,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,MAAqB;YAElD,OAAO,CAAC,WAAW,CAAC;AACtB,QAAA,CAAC;AAED,QAAA,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC;AAChC,IAAA,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,GAAG,OAAO,GAAW,KAAI;AACvC,IAAA,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC;IACjC,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;AACrD,IAAA,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,WAAW,EAAE;AAChD,IAAA,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC;IAEzC,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAC/B,CAAC,GAAG,EAAE,IAAI,KAAK,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,gBAAA,QAAQ,EAAE,mBAAmB;gBAC7B,WAAW;gBACX,cAAc;gBACd,SAAS;gBACT,SAAS;AACT,gBAAA,WAAW,EAAE,OAAO;gBACpB,uBAAuB;AACvB,gBAAA,gBAAgB,EAAE,QAAQ;AAC1B,gBAEA,eAAe,EAAE,SAElB,CAAA,CAAC;QACJ;AAEA,QAAA,QAAQ,CAAC;AACP,YAAA,IAAI,EAAE,eAAe;YACrB,OAAO,EAAE,UAAU,IAAI,OAAO;AAC9B,YAAA,aAAa,EAAE,mBAAmB;AAClC,YAAA,WAAW,EAAE,OAAO;AACpB,YAAA,YAAY,EAAE,cAAc;AAC5B,YAAA,WAAW,EAAE,uBAAuB;YACpC,uBAAuB;AACvB,YAAA,gBAAgB,EAAE,QAAQ;AAC1B,YAAA,eAAe,EAAE,SAAS;AAC1B,YAAA,WAAW,EAAE,SAAS;YACtB,SAAS;AACV,SAAA,CAAC;AACJ,IAAA,CAAC;AAED,IAAA,UAAU,EAAE,CAAC,IAAI,CAAC,MAAK;AACrB,QAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC;AACxC,IAAA,CAAC,CAAC;AACJ,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"saveItemStorage.js","sources":["../../../../../../../src/ItemProperty/service/actors/saveValueToDb/saveItemStorage.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { FromCallbackInput } from '@/types/machines'\nimport {\n ItemPropertyValueType,\n PropertyMachineContext,\n SaveValueToDbEvent,\n} from '@/types/property'\nimport { BaseDb } from '@/db/Db/BaseDb'\nimport { getItemPropertyData } from '@/db/read/getItemProperty'\nimport { getItemData } from '@/db/read/getItemData'\nimport { and, eq } from 'drizzle-orm'\nimport { metadata } from '@/seedSchema'\nimport { createMetadata } from '@/db/write/createMetadata'\nimport { BaseFileManager } from '@/helpers/FileManager/BaseFileManager'\n\nexport const saveItemStorage = fromCallback<\n EventObject,\n FromCallbackInput<PropertyMachineContext, SaveValueToDbEvent>\n>(({ sendBack, input: { context, event } }) => {\n const {\n localId,\n seedLocalId,\n seedUid,\n propertyName,\n propertyRecordSchema,\n modelName,\n propertyValue: existingValue,\n } = context\n\n if (!propertyRecordSchema) {\n throw new Error('Missing propertyRecordSchema')\n }\n\n let newValue: ItemPropertyValueType\n\n if (event) {\n newValue = event.newValue\n }\n\n if (existingValue === newValue) {\n sendBack({ type: 'saveValueToDbSuccess' })\n return\n }\n\n const _saveItemStorage = async (): Promise<boolean> => {\n // Save value to file\n const appDb = BaseDb.getAppDb()\n let propertyData\n\n if (localId) {\n propertyData = await getItemPropertyData({\n localId,\n })\n }\n\n if (!localId && seedLocalId) {\n const itemData = await getItemData({\n seedLocalId,\n })\n if (itemData) {\n const whereClauses = [\n eq(metadata.propertyName, propertyName),\n eq(metadata.seedLocalId, seedLocalId),\n ]\n\n if (itemData.latestVersionLocalId) {\n whereClauses.push(\n eq(metadata.versionLocalId, itemData.latestVersionLocalId),\n )\n }\n\n const queryRows = await appDb\n .select()\n .from(metadata)\n .where(and(...whereClauses))\n\n if (queryRows && queryRows.length) {\n propertyData = queryRows[0]\n }\n\n if (!propertyData && newValue) {\n\n const filename = `${seedUid || seedLocalId}${propertyRecordSchema.filenameSuffix}`\n const writeToPath = `/files/${propertyRecordSchema.localStorageDir}/${filename}`\n await BaseFileManager.saveFile(writeToPath, newValue as string | Blob | ArrayBuffer)\n\n const propertyDataRows = await createMetadata(\n {\n propertyName,\n propertyValue: filename,\n modelType: modelName.toLowerCase(),\n seedLocalId,\n seedUid,\n versionLocalId: itemData.latestVersionLocalId,\n versionUid: itemData.latestVersionUid,\n localStorageDir: propertyRecordSchema.localStorageDir,\n refValueType: 'file',\n },\n propertyRecordSchema,\n )\n\n propertyData = propertyDataRows[0]\n }\n\n // propertyData = {\n // propertyName,\n // seedLocalId,\n // seedUid,\n // versionLocalId: itemData.latestVersionLocalId,\n // versionUid: itemData.latestVersionUid,\n // schemaUid: itemData.schemaUid,\n // }\n }\n }\n\n const localStorageDir =\n propertyRecordSchema.localStorageDir || propertyData.localStorageDir\n const fileName =\n propertyData.refResolvedValue ||\n `${propertyData.seedUid || propertyData.seedLocalId}${propertyRecordSchema.filenameSuffix}`\n\n if (!localStorageDir || !fileName) {\n throw new Error(\n `Missing localStorageDir: ${localStorageDir} or fileName: ${fileName}`,\n )\n }\n\n const filePath = `/files/${localStorageDir}/${fileName}`\n try {\n await BaseFileManager.saveFile(filePath, newValue as string | Blob | ArrayBuffer)\n } catch (error) {\n const fs = await BaseFileManager.getFs()\n fs.writeFileSync(filePath, newValue)\n }\n\n await appDb\n .update(metadata)\n .set({\n refResolvedValue: fileName,\n })\n .where(eq(metadata.localId, propertyData.localId))\n\n sendBack({\n type: 'updateContext',\n renderValue: newValue,\n })\n\n return true\n }\n\n _saveItemStorage().then((success) => {\n if (success) {\n sendBack({ type: 'saveItemStorageSuccess' })\n }\n })\n})\n"],"names":[],"mappings":";;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"saveItemStorage.js","sources":["../../../../../../../src/ItemProperty/service/actors/saveValueToDb/saveItemStorage.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { FromCallbackInput } from '@/types/machines'\nimport {\n ItemPropertyValueType,\n PropertyMachineContext,\n SaveValueToDbEvent,\n} from '@/types/property'\nimport { BaseDb } from '@/db/Db/BaseDb'\nimport { getItemPropertyData } from '@/db/read/getItemProperty'\nimport { getItemData } from '@/db/read/getItemData'\nimport { and, eq } from 'drizzle-orm'\nimport { metadata } from '@/seedSchema'\nimport { createMetadata } from '@/db/write/createMetadata'\nimport { BaseFileManager } from '@/helpers/FileManager/BaseFileManager'\n\nexport const saveItemStorage = fromCallback<\n EventObject,\n FromCallbackInput<PropertyMachineContext, SaveValueToDbEvent>\n>(({ sendBack, input: { context, event } }) => {\n const {\n localId,\n seedLocalId,\n seedUid,\n propertyName,\n propertyRecordSchema,\n modelName,\n propertyValue: existingValue,\n } = context\n\n if (!propertyRecordSchema) {\n throw new Error('Missing propertyRecordSchema')\n }\n\n let newValue: ItemPropertyValueType\n\n if (event) {\n newValue = event.newValue\n }\n\n if (existingValue === newValue) {\n sendBack({ type: 'saveValueToDbSuccess' })\n return\n }\n\n const _saveItemStorage = async (): Promise<boolean> => {\n // Save value to file\n const appDb = BaseDb.getAppDb()\n let propertyData\n\n if (localId) {\n propertyData = await getItemPropertyData({\n localId,\n })\n }\n\n if (!localId && seedLocalId) {\n const itemData = await getItemData({\n seedLocalId,\n })\n if (itemData) {\n const whereClauses = [\n eq(metadata.propertyName, propertyName),\n eq(metadata.seedLocalId, seedLocalId),\n ]\n\n if (itemData.latestVersionLocalId) {\n whereClauses.push(\n eq(metadata.versionLocalId, itemData.latestVersionLocalId),\n )\n }\n\n const queryRows = await appDb\n .select()\n .from(metadata)\n .where(and(...whereClauses))\n\n if (queryRows && queryRows.length) {\n propertyData = queryRows[0]\n }\n\n if (!propertyData && newValue) {\n\n const filename = `${seedUid || seedLocalId}${propertyRecordSchema.filenameSuffix}`\n const writeToPath = `/files/${propertyRecordSchema.localStorageDir}/${filename}`\n await BaseFileManager.saveFile(writeToPath, newValue as string | Blob | ArrayBuffer)\n\n const propertyDataRows = await createMetadata(\n {\n propertyName,\n propertyValue: filename,\n modelType: modelName.toLowerCase(),\n seedLocalId,\n seedUid,\n versionLocalId: itemData.latestVersionLocalId,\n versionUid: itemData.latestVersionUid,\n localStorageDir: propertyRecordSchema.localStorageDir,\n refValueType: 'file',\n },\n propertyRecordSchema,\n )\n\n propertyData = propertyDataRows[0]\n }\n\n // propertyData = {\n // propertyName,\n // seedLocalId,\n // seedUid,\n // versionLocalId: itemData.latestVersionLocalId,\n // versionUid: itemData.latestVersionUid,\n // schemaUid: itemData.schemaUid,\n // }\n }\n }\n\n const localStorageDir =\n propertyRecordSchema.localStorageDir || propertyData.localStorageDir\n const fileName =\n propertyData.refResolvedValue ||\n `${propertyData.seedUid || propertyData.seedLocalId}${propertyRecordSchema.filenameSuffix}`\n\n if (!localStorageDir || !fileName) {\n throw new Error(\n `Missing localStorageDir: ${localStorageDir} or fileName: ${fileName}`,\n )\n }\n\n const filePath = `/files/${localStorageDir}/${fileName}`\n try {\n await BaseFileManager.saveFile(filePath, newValue as string | Blob | ArrayBuffer)\n } catch (error) {\n const fs = await BaseFileManager.getFs()\n fs.writeFileSync(filePath, newValue)\n }\n\n await appDb\n .update(metadata)\n .set({\n refResolvedValue: fileName,\n })\n .where(eq(metadata.localId, propertyData.localId))\n\n sendBack({\n type: 'updateContext',\n renderValue: newValue,\n })\n\n return true\n }\n\n _saveItemStorage().then((success) => {\n if (success) {\n sendBack({ type: 'saveItemStorageSuccess' })\n }\n })\n})\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAeO,MAAM,eAAe,GAAG,YAAY,CAGzC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,KAAI;AAC5C,IAAA,MAAM,EACJ,OAAO,EACP,WAAW,EACX,OAAO,EACP,YAAY,EACZ,oBAAoB,EACpB,SAAS,EACT,aAAa,EAAE,aAAa,GAC7B,GAAG,OAAO;IAEX,IAAI,CAAC,oBAAoB,EAAE;AACzB,QAAA,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC;IACjD;AAEA,IAAA,IAAI,QAA+B;IAEnC,IAAI,KAAK,EAAE;AACT,QAAA,QAAQ,GAAG,KAAK,CAAC,QAAQ;IAC3B;AAEA,IAAA,IAAI,aAAa,KAAK,QAAQ,EAAE;AAC9B,QAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,sBAAsB,EAAE,CAAC;QAC1C;IACF;AAEA,IAAA,MAAM,gBAAgB,GAAG,YAA6B;;AAEpD,QAAA,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,EAAE;AAC/B,QAAA,IAAI,YAAY;QAEhB,IAAI,OAAO,EAAE;YACX,YAAY,GAAG,MAAM,mBAAmB,CAAC;gBACvC,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AE,eAAe;AACrB,YAAA,WAAW,EAAE,QAAQ;AACtB,SAAA,CAAC;AAEF,QAAA,OAAO,IAAI;AACb,IAAA,CAAC;AAED,IAAA,gBAAgB,EAAE,CAAC,IAAI,CAAC,CAAC,OAAO,KAAI;QAClC,IAAI,OAAO,EAAE;AACX,YAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,wBAAwB,EAAE,CAAC;QAC9C;AACF,IAAA,CAAC,CAAC;AACJ,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"saveRelation.js","sources":["../../../../../../../src/ItemProperty/service/actors/saveValueToDb/saveRelation.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { FromCallbackInput } from '@/types/machines'\nimport {\n ItemPropertyValueType,\n PropertyMachineContext,\n SaveValueToDbEvent,\n} from '@/types/property'\nimport { getDataTypeFromString } from '@/helpers'\n\nexport const saveRelation = fromCallback<\n EventObject,\n FromCallbackInput<PropertyMachineContext, SaveValueToDbEvent>\n>(({ sendBack, input: { context, event } }) => {\n const {\n localId,\n propertyName: propertyNameRaw,\n versionLocalId,\n seedUid,\n seedLocalId,\n propertyValue: existingValue,\n propertyRecordSchema,\n } = context\n\n if (!propertyRecordSchema) {\n throw new Error('Missing propertyRecordSchema')\n }\n\n let newValue: ItemPropertyValueType\n\n if (event) {\n newValue = event.newValue\n }\n\n const _saveRelation = async (): Promise<boolean> => {\n let refResolvedDisplayValue\n let refSeedType\n let propertyName = propertyNameRaw\n let versionLocalIdToSave = versionLocalId\n\n const refResolvedValue = newValue\n\n if (!propertyName.endsWith('Id')) {\n propertyName = `${propertyName}Id`\n }\n\n let newValueType\n\n if (typeof newValue === 'string') {\n newValueType = getDataTypeFromString(newValue)\n }\n\n if (newValue instanceof File) {\n newValueType = 'file'\n }\n\n if (propertyRecordSchema.dataType === 'Image') {\n sendBack({\n type: 'saveImage',\n newValue,\n newValueType,\n })\n return false\n }\n\n return true\n\n // let fileType\n //\n // const dirs = await fs.promises.readdir('/files')\n //\n // for (const dir of dirs) {\n // const files = await fs.promises.readdir(`/files/${dir}`)\n // if (newValue && files.includes(newValue as string)) {\n // fileType = dir\n // break\n // }\n // }\n //\n // if (newValue && fileType === 'images') {\n // const filePath = `/files/images/${newValue}`\n // refResolvedDisplayValue = await getContentUrlFromPath(filePath)\n // refSeedType = 'image'\n // newValue = await createSeed({\n // type: refSeedType,\n // })\n // await createVersion({\n // seedLocalId,\n // seedUid,\n // seedType: refSeedType,\n // })\n // }\n //\n // await updateItemPropertyValue({\n // propertyLocalId: localId,\n // propertyName,\n // newValue,\n // seedLocalId,\n // refSeedType,\n // refResolvedValue,\n // refResolvedDisplayValue,\n // versionLocalId,\n // modelName: itemModelName,\n // schemaUid,\n // })\n }\n\n _saveRelation().then((isDone) => {\n if (isDone) {\n sendBack({ type: 'saveRelationSuccess' })\n }\n })\n})\n"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"saveRelation.js","sources":["../../../../../../../src/ItemProperty/service/actors/saveValueToDb/saveRelation.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { FromCallbackInput } from '@/types/machines'\nimport {\n ItemPropertyValueType,\n PropertyMachineContext,\n SaveValueToDbEvent,\n} from '@/types/property'\nimport { getDataTypeFromString } from '@/helpers'\n\nexport const saveRelation = fromCallback<\n EventObject,\n FromCallbackInput<PropertyMachineContext, SaveValueToDbEvent>\n>(({ sendBack, input: { context, event } }) => {\n const {\n localId,\n propertyName: propertyNameRaw,\n versionLocalId,\n seedUid,\n seedLocalId,\n propertyValue: existingValue,\n propertyRecordSchema,\n } = context\n\n if (!propertyRecordSchema) {\n throw new Error('Missing propertyRecordSchema')\n }\n\n let newValue: ItemPropertyValueType\n\n if (event) {\n newValue = event.newValue\n }\n\n const _saveRelation = async (): Promise<boolean> => {\n let refResolvedDisplayValue\n let refSeedType\n let propertyName = propertyNameRaw\n let versionLocalIdToSave = versionLocalId\n\n const refResolvedValue = newValue\n\n if (!propertyName.endsWith('Id')) {\n propertyName = `${propertyName}Id`\n }\n\n let newValueType\n\n if (typeof newValue === 'string') {\n newValueType = getDataTypeFromString(newValue)\n }\n\n if (newValue instanceof File) {\n newValueType = 'file'\n }\n\n if (propertyRecordSchema.dataType === 'Image') {\n sendBack({\n type: 'saveImage',\n newValue,\n newValueType,\n })\n return false\n }\n\n return true\n\n // let fileType\n //\n // const dirs = await fs.promises.readdir('/files')\n //\n // for (const dir of dirs) {\n // const files = await fs.promises.readdir(`/files/${dir}`)\n // if (newValue && files.includes(newValue as string)) {\n // fileType = dir\n // break\n // }\n // }\n //\n // if (newValue && fileType === 'images') {\n // const filePath = `/files/images/${newValue}`\n // refResolvedDisplayValue = await getContentUrlFromPath(filePath)\n // refSeedType = 'image'\n // newValue = await createSeed({\n // type: refSeedType,\n // })\n // await createVersion({\n // seedLocalId,\n // seedUid,\n // seedType: refSeedType,\n // })\n // }\n //\n // await updateItemPropertyValue({\n // propertyLocalId: localId,\n // propertyName,\n // newValue,\n // seedLocalId,\n // refSeedType,\n // refResolvedValue,\n // refResolvedDisplayValue,\n // versionLocalId,\n // modelName: itemModelName,\n // schemaUid,\n // })\n }\n\n _saveRelation().then((isDone) => {\n if (isDone) {\n sendBack({ type: 'saveRelationSuccess' })\n }\n })\n})\n"],"names":[],"mappings":";;;AASO,MAAM,YAAY,GAAG,YAAY,CAGtC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,KAAI;IAC5C,MAAM,EACJ,OAAO,EACP,YAAY,EAAE,eAAe,EAC7B,cAAc,EACd,OAAO,EACP,WAAW,EACX,aAAa,EAAE,aAAa,EAC5B,oBAAoB,GACrB,GAAG,OAAO;IAEX,IAAI,CAAC,oBAAoB,EAAE;AACzB,QAAA,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC;IACjD;AAEA,IAAA,IAAI,QAA+B;IAEnC,IAAI,KAAK,EAAE;AACT,QAAA,QAAQ,GAAG,KAAK,CAAC,QAAQ;IAC3B;AAEA,IAAA,MAAM,aAAa,GAAG,YAA6B;QAGjD,IAAI,YAAY,GAAG,eAAe;QAKlC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;AAChC,YAAA,YAAY,GAAG,CAAA,EAAG,YAAY,CAAA,EAAA,CAAI;QACpC;AAEA,QAAA,IAAI,YAAY;AAEhB,QAAA,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;AAChC,YAAA,YAAY,GAAG,qBAAqB,CAAC,QAAQ,CAAC;QAChD;AAEA,QAAA,IAAI,QAAQ,YAAY,IAAI,EAAE;YAC5B,YAAY,GAAG,MAAM;QACvB;AAEA,QAAA,IAAI,oBAAoB,CAAC,QAAQ,KAAK,OAAO,EAAE;AAC7C,YAAA,QAAQ,CAAC;AACP,gBAAA,IAAI,EAAE,WAAW;gBACjB,QAAQ;gBACR,YAAY;AACb,aAAA,CAAC;AACF,YAAA,OAAO,KAAK;QACd;AAEA,QAAA,OAAO,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCb,IAAA,CAAC;AAED,IAAA,aAAa,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,KAAI;QAC9B,IAAI,MAAM,EAAE;AACV,YAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,qBAAqB,EAAE,CAAC;QAC3C;AACF,IAAA,CAAC,CAAC;AACJ,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitForDb.js","sources":["../../../../../../src/ItemProperty/service/actors/waitForDb.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { FromCallbackInput, PropertyMachineContext } from '@/types'\nimport { BaseDb } from '@/db/Db/BaseDb'\nimport debug from 'debug'\n\nconst logger = debug('seedSdk:ItemProperty:service:actors:waitForDb')\n\nexport const waitForDb = fromCallback<\n EventObject,\n FromCallbackInput<PropertyMachineContext>\n>(({ sendBack }) => {\n const _waitForDb = new Promise<void>((resolve) => {\n const interval = setInterval(() => {\n const appDb = BaseDb.getAppDb()\n if (appDb) {\n clearInterval(interval)\n resolve()\n }\n }, 100)\n })\n\n _waitForDb.then(() => {\n sendBack({ type: 'waitForDbSuccess' })\n })\n})\n"],"names":[],"mappings":";;;;AAKe,KAAK,CAAC,+CAA+C;
|
|
1
|
+
{"version":3,"file":"waitForDb.js","sources":["../../../../../../src/ItemProperty/service/actors/waitForDb.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { FromCallbackInput, PropertyMachineContext } from '@/types'\nimport { BaseDb } from '@/db/Db/BaseDb'\nimport debug from 'debug'\n\nconst logger = debug('seedSdk:ItemProperty:service:actors:waitForDb')\n\nexport const waitForDb = fromCallback<\n EventObject,\n FromCallbackInput<PropertyMachineContext>\n>(({ sendBack }) => {\n const _waitForDb = new Promise<void>((resolve) => {\n const interval = setInterval(() => {\n const appDb = BaseDb.getAppDb()\n if (appDb) {\n clearInterval(interval)\n resolve()\n }\n }, 100)\n })\n\n _waitForDb.then(() => {\n sendBack({ type: 'waitForDbSuccess' })\n })\n})\n"],"names":[],"mappings":";;;;AAKe,KAAK,CAAC,+CAA+C;AAE7D,MAAM,SAAS,GAAG,YAAY,CAGnC,CAAC,EAAE,QAAQ,EAAE,KAAI;IACjB,MAAM,UAAU,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,KAAI;AAC/C,QAAA,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAK;AAChC,YAAA,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,EAAE;YAC/B,IAAI,KAAK,EAAE;gBACT,aAAa,CAAC,QAAQ,CAAC;AACvB,gBAAA,OAAO,EAAE;YACX;QACF,CAAC,EAAE,GAAG,CAAC;AACT,IAAA,CAAC,CAAC;AAEF,IAAA,UAAU,CAAC,IAAI,CAAC,MAAK;AACnB,QAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC;AACxC,IAAA,CAAC,CAAC;AACJ,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"propertyMachine.js","sources":["../../../../../src/ItemProperty/service/propertyMachine.ts"],"sourcesContent":["import { assign, setup } from 'xstate'\nimport { PropertyMachineContext } from '@/types'\n\nimport { resolveRemoteStorage } from '@/ItemProperty/service/actors/resolveRemoteStorage'\nimport { waitForDb } from '@/ItemProperty/service/actors/waitForDb'\nimport { initialize } from '@/ItemProperty/service/actors/initialize'\nimport { resolveRelatedValue } from '@/ItemProperty/service/actors/resolveRelatedValue'\nimport { hydrateFromDb } from '@/ItemProperty/service/actors/hydrateFromDb'\nimport {\n saveImage,\n saveItemStorage,\n saveRelation,\n} from '@/ItemProperty/service/actors/saveValueToDb'\nimport { analyzeInput } from '@/ItemProperty/service/actors/saveValueToDb/analyzeInput' // import { updateMachineContext } from '@/helpers'\n// import { updateMachineContext } from '@/helpers'\n\nexport const propertyMachine = setup({\n types: {\n context: {} as PropertyMachineContext,\n input: {} as PropertyMachineContext,\n },\n // actions: {\n // updateContext: updateMachineContext,\n // },\n actors: {\n waitForDb,\n hydrateFromDb,\n initialize,\n resolveRelatedValue,\n resolveRemoteStorage,\n analyzeInput,\n saveImage,\n saveRelation,\n saveItemStorage,\n },\n}).createMachine({\n id: 'itemProperty',\n initial: 'waitingForDb',\n context: ({ input }) => input as PropertyMachineContext,\n on: {\n // reload: '.hydratingFromDb',\n save: {\n actions: assign({\n isSaving: true,\n }),\n target: '.saving',\n },\n updateContext: {\n actions: assign(({ context, event }) => {\n const newContext = Object.assign({}, context)\n\n for (let i = 0; i < Object.keys(event).length; i++) {\n const key = Object.keys(event)[i]\n if (key === 'type') {\n continue\n }\n newContext[key] = event[key]\n }\n return newContext\n }),\n },\n },\n states: {\n idle: {},\n waitingForDb: {\n on: {\n waitForDbSuccess: {\n target: 'hydratingFromDb',\n actions: assign({\n isDbReady: true,\n }),\n },\n },\n invoke: {\n src: 'waitForDb',\n input: ({ context }) => ({ context }),\n },\n },\n hydratingFromDb: {\n on: {\n hydrateFromDbSuccess: 'initializing',\n },\n invoke: {\n src: 'hydrateFromDb',\n input: ({ context }) => ({ context }),\n },\n },\n initializing: {\n on: {\n initializeSuccess: 'idle',\n isRelatedProperty: {\n target: 'resolvingRelatedValue',\n },\n hasRemoteBackup: {\n target: 'resolvingRemoteStorage',\n },\n },\n invoke: {\n src: 'initialize',\n input: ({ context, event }) => ({ context, event }),\n },\n },\n resolvingRelatedValue: {\n on: {\n resolvingRelatedValueSuccess: {\n target: 'idle',\n actions: assign({\n refResolvedDisplayValue: ({ event }) =>\n event.refResolvedDisplayValue,\n refResolvedValue: ({ event }) => event.refResolvedValue,\n }),\n },\n resolvingRelatedValueDone: {\n target: 'idle',\n },\n },\n invoke: {\n src: 'resolveRelatedValue',\n input: ({ context }) => ({ context }),\n },\n },\n resolvingRemoteStorage: {\n on: {\n resolveRemoteStorageSuccess: {\n target: 'idle',\n },\n },\n invoke: {\n src: 'resolveRemoteStorage',\n input: ({ context }) => ({ context }),\n },\n },\n saving: {\n initial: 'analyzingInput',\n states: {\n analyzingInput: {\n on: {\n saveValueToDbSuccess: {\n target: 'doneSaving',\n },\n saveImage: 'savingImage',\n saveRelation: 'savingRelation',\n saveItemStorage: 'savingItemStorage',\n },\n invoke: {\n src: 'analyzeInput',\n input: ({ context, event }) => ({ context, event }),\n },\n },\n savingImage: {\n on: {\n saveImageSuccess: 'doneSaving',\n },\n invoke: {\n src: 'saveImage',\n input: ({ context, event }) => ({ context, event }),\n },\n },\n savingRelation: {\n on: {\n saveRelationSuccess: 'doneSaving',\n },\n invoke: {\n src: 'saveRelation',\n input: ({ context, event }) => ({ context, event }),\n },\n },\n savingItemStorage: {\n on: {\n saveItemStorageSuccess: 'doneSaving',\n },\n invoke: {\n src: 'saveItemStorage',\n input: ({ context, event }) => ({ context, event }),\n },\n },\n doneSaving: {\n type: 'final',\n },\n },\n onDone: {\n target: 'idle',\n actions: assign(({ context }) => {\n return {\n isSaving: false,\n }\n }),\n },\n },\n },\n\n // conflict: {\n // on: {\n // resolveConflict: {\n // target: 'saving',\n // actions: assign({\n // data: ({ context, event }) => event.output,\n // }),\n // },\n // },\n // },\n})\n"],"names":[],"mappings":";;;;;;;;;;;AAcA;AAEO,MAAM,eAAe,GAAG,KAAK,CAAC;AACnC,IAAA,KAAK,EAAE;AACL,QAAA,OAAO,EAAE,EAA4B;AACrC,QAAA,KAAK,EAAE,EAA4B;AACpC,KAAA;;;;AAID,IAAA,MAAM,EAAE;QACN,SAAS;QACT,aAAa;QACb,UAAU;QACV,mBAAmB;QACnB,oBAAoB;QACpB,YAAY;QACZ,SAAS;QACT,YAAY;QACZ,eAAe;AAChB,KAAA;CACF,CAAC,CAAC,aAAa,CAAC;AACf,IAAA,EAAE,EAAE,cAAc;AAClB,IAAA,OAAO,EAAE,cAAc;IACvB,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,KAA+B;AACvD,IAAA,EAAE,EAAE;;AAEF,QAAA,IAAI,EAAE;YACJ,OAAO,EAAE,MAAM,CAAC;AACd,gBAAA,QAAQ,EAAE,IAAI;aACf,CAAC;AACF,YAAA,MAAM,EAAE,SAAS;AAClB,SAAA;AACD,QAAA,aAAa,EAAE;YACb,OAAO,EAAE,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAI;gBACrC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC;AAE7C,gBAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;oBAClD,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACjC,oBAAA,IAAI,GAAG,KAAK,MAAM,EAAE;wBAClB
|
|
1
|
+
{"version":3,"file":"propertyMachine.js","sources":["../../../../../src/ItemProperty/service/propertyMachine.ts"],"sourcesContent":["import { assign, setup } from 'xstate'\nimport { PropertyMachineContext } from '@/types'\n\nimport { resolveRemoteStorage } from '@/ItemProperty/service/actors/resolveRemoteStorage'\nimport { waitForDb } from '@/ItemProperty/service/actors/waitForDb'\nimport { initialize } from '@/ItemProperty/service/actors/initialize'\nimport { resolveRelatedValue } from '@/ItemProperty/service/actors/resolveRelatedValue'\nimport { hydrateFromDb } from '@/ItemProperty/service/actors/hydrateFromDb'\nimport {\n saveImage,\n saveItemStorage,\n saveRelation,\n} from '@/ItemProperty/service/actors/saveValueToDb'\nimport { analyzeInput } from '@/ItemProperty/service/actors/saveValueToDb/analyzeInput' // import { updateMachineContext } from '@/helpers'\n// import { updateMachineContext } from '@/helpers'\n\nexport const propertyMachine = setup({\n types: {\n context: {} as PropertyMachineContext,\n input: {} as PropertyMachineContext,\n },\n // actions: {\n // updateContext: updateMachineContext,\n // },\n actors: {\n waitForDb,\n hydrateFromDb,\n initialize,\n resolveRelatedValue,\n resolveRemoteStorage,\n analyzeInput,\n saveImage,\n saveRelation,\n saveItemStorage,\n },\n}).createMachine({\n id: 'itemProperty',\n initial: 'waitingForDb',\n context: ({ input }) => input as PropertyMachineContext,\n on: {\n // reload: '.hydratingFromDb',\n save: {\n actions: assign({\n isSaving: true,\n }),\n target: '.saving',\n },\n updateContext: {\n actions: assign(({ context, event }) => {\n const newContext = Object.assign({}, context)\n\n for (let i = 0; i < Object.keys(event).length; i++) {\n const key = Object.keys(event)[i]\n if (key === 'type') {\n continue\n }\n newContext[key] = event[key]\n }\n return newContext\n }),\n },\n },\n states: {\n idle: {},\n waitingForDb: {\n on: {\n waitForDbSuccess: {\n target: 'hydratingFromDb',\n actions: assign({\n isDbReady: true,\n }),\n },\n },\n invoke: {\n src: 'waitForDb',\n input: ({ context }) => ({ context }),\n },\n },\n hydratingFromDb: {\n on: {\n hydrateFromDbSuccess: 'initializing',\n },\n invoke: {\n src: 'hydrateFromDb',\n input: ({ context }) => ({ context }),\n },\n },\n initializing: {\n on: {\n initializeSuccess: 'idle',\n isRelatedProperty: {\n target: 'resolvingRelatedValue',\n },\n hasRemoteBackup: {\n target: 'resolvingRemoteStorage',\n },\n },\n invoke: {\n src: 'initialize',\n input: ({ context, event }) => ({ context, event }),\n },\n },\n resolvingRelatedValue: {\n on: {\n resolvingRelatedValueSuccess: {\n target: 'idle',\n actions: assign({\n refResolvedDisplayValue: ({ event }) =>\n event.refResolvedDisplayValue,\n refResolvedValue: ({ event }) => event.refResolvedValue,\n }),\n },\n resolvingRelatedValueDone: {\n target: 'idle',\n },\n },\n invoke: {\n src: 'resolveRelatedValue',\n input: ({ context }) => ({ context }),\n },\n },\n resolvingRemoteStorage: {\n on: {\n resolveRemoteStorageSuccess: {\n target: 'idle',\n },\n },\n invoke: {\n src: 'resolveRemoteStorage',\n input: ({ context }) => ({ context }),\n },\n },\n saving: {\n initial: 'analyzingInput',\n states: {\n analyzingInput: {\n on: {\n saveValueToDbSuccess: {\n target: 'doneSaving',\n },\n saveImage: 'savingImage',\n saveRelation: 'savingRelation',\n saveItemStorage: 'savingItemStorage',\n },\n invoke: {\n src: 'analyzeInput',\n input: ({ context, event }) => ({ context, event }),\n },\n },\n savingImage: {\n on: {\n saveImageSuccess: 'doneSaving',\n },\n invoke: {\n src: 'saveImage',\n input: ({ context, event }) => ({ context, event }),\n },\n },\n savingRelation: {\n on: {\n saveRelationSuccess: 'doneSaving',\n },\n invoke: {\n src: 'saveRelation',\n input: ({ context, event }) => ({ context, event }),\n },\n },\n savingItemStorage: {\n on: {\n saveItemStorageSuccess: 'doneSaving',\n },\n invoke: {\n src: 'saveItemStorage',\n input: ({ context, event }) => ({ context, event }),\n },\n },\n doneSaving: {\n type: 'final',\n },\n },\n onDone: {\n target: 'idle',\n actions: assign(({ context }) => {\n return {\n isSaving: false,\n }\n }),\n },\n },\n },\n\n // conflict: {\n // on: {\n // resolveConflict: {\n // target: 'saving',\n // actions: assign({\n // data: ({ context, event }) => event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AE,YAAY;AAC/B,qBAAA;AACD,oBAAA,MAAM,EAAE;AACN,wBAAA,GAAG,EAAE,WAAW;AAChB,wBAAA,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AACpD,qBAAA;AACF,iBAAA;AACD,gBAAA,cAAc,EAAE;AACd,oBAAA,EAAE,EAAE;AACF,wBAAA,mBAAmB,EAAE,YAAY;AAClC,qBAAA;AACD,oBAAA,MAAM,EAAE;AACN,wBAAA,GAAG,EAAE,cAAc;AACnB,wBAAA,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AACpD,qBAAA;AACF,iBAAA;AACD,gBAAA,iBAAiB,EAAE;AACjB,oBAAA,EAAE,EAAE;AACF,wBAAA,sBAAsB,EAAE,YAAY;AACrC,qBAAA;AACD,oBAAA,MAAM,EAAE;AACN,wBAAA,GAAG,EAAE,iBAAiB;AACtB,wBAAA,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AACpD,qBAAA;AACF,iBAAA;AACD,gBAAA,UAAU,EAAE;AACV,oBAAA,IAAI,EAAE,OAAO;AACd,iBAAA;AACF,aAAA;AACD,YAAA,MAAM,EAAE;AACN,gBAAA,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,KAAI;oBAC9B,OAAO;AACL,wBAAA,QAAQ,EAAE,KAAK;qBAChB;AACH,gBAAA,CAAC,CAAC;AACH,aAAA;AACF,SAAA;AACF,KAAA;;;;;;;;;;;AAYF,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Item.js","sources":["../../../../../src/browser/Item/Item.ts"],"sourcesContent":["import {\n ModelSchema,\n ModelValues,\n NewItemProps,\n} from '@/types'\nimport { BaseItem } from '@/Item/BaseItem'\nimport { IItem } from '@/interfaces'\n\nexport class Item<T extends ModelValues<ModelSchema>> extends BaseItem<T> implements IItem<T> {\n\n constructor(initialValues: NewItemProps<T>,) {\n super(initialValues,)\n }\n\n}\n"],"names":[],"mappings":";;AAQM,MAAO,IAAyC,SAAQ,QAAW,CAAA;AAEvE,IAAA,WAAA,CAAY,aAA8B,EAAA;QACxC,KAAK,CAAC,aAAa,CAAE
|
|
1
|
+
{"version":3,"file":"Item.js","sources":["../../../../../src/browser/Item/Item.ts"],"sourcesContent":["import {\n ModelSchema,\n ModelValues,\n NewItemProps,\n} from '@/types'\nimport { BaseItem } from '@/Item/BaseItem'\nimport { IItem } from '@/interfaces'\n\nexport class Item<T extends ModelValues<ModelSchema>> extends BaseItem<T> implements IItem<T> {\n\n constructor(initialValues: NewItemProps<T>,) {\n super(initialValues,)\n }\n\n}\n"],"names":[],"mappings":";;AAQM,MAAO,IAAyC,SAAQ,QAAW,CAAA;AAEvE,IAAA,WAAA,CAAY,aAA8B,EAAA;QACxC,KAAK,CAAC,aAAa,CAAE;IACvB;AAED;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ItemProperty.js","sources":["../../../../../src/browser/ItemProperty/ItemProperty.ts"],"sourcesContent":["import { CreatePropertyInstanceProps, PropertyType } from '@/types'\nimport { IItemProperty } from '@/interfaces/IItemProperty'\nimport { BaseItemProperty } from '@/ItemProperty/BaseItemProperty'\n\n\nclass ItemProperty extends BaseItemProperty<PropertyType> implements IItemProperty<PropertyType> {\n\n\n constructor(initialValues: Partial<CreatePropertyInstanceProps>) {\n super(initialValues)\n }\n\n}\n\nexport { ItemProperty }\n"],"names":[],"mappings":";;AAKA,MAAM,YAAa,SAAQ,gBAA8B,CAAA;AAGvD,IAAA,WAAA,CAAY,aAAmD,EAAA;QAC7D,KAAK,CAAC,aAAa,CAAC
|
|
1
|
+
{"version":3,"file":"ItemProperty.js","sources":["../../../../../src/browser/ItemProperty/ItemProperty.ts"],"sourcesContent":["import { CreatePropertyInstanceProps, PropertyType } from '@/types'\nimport { IItemProperty } from '@/interfaces/IItemProperty'\nimport { BaseItemProperty } from '@/ItemProperty/BaseItemProperty'\n\n\nclass ItemProperty extends BaseItemProperty<PropertyType> implements IItemProperty<PropertyType> {\n\n\n constructor(initialValues: Partial<CreatePropertyInstanceProps>) {\n super(initialValues)\n }\n\n}\n\nexport { ItemProperty }\n"],"names":[],"mappings":";;AAKA,MAAM,YAAa,SAAQ,gBAA8B,CAAA;AAGvD,IAAA,WAAA,CAAY,aAAmD,EAAA;QAC7D,KAAK,CAAC,aAAa,CAAC;IACtB;AAED;;;;"}
|