@seedprotocol/sdk 0.3.7 → 0.3.8
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/dist/src/ItemProperty/BaseItemProperty.d.ts +6 -6
- package/dist/src/ItemProperty/service/actors/hydrateFromDb.js +2 -2
- package/dist/src/ItemProperty/service/actors/hydrateFromDb.js.map +1 -1
- package/dist/src/ItemProperty/service/actors/resolveRelatedValue.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/resolveRelatedValue.js +4 -4
- package/dist/src/ItemProperty/service/actors/resolveRelatedValue.js.map +1 -1
- package/dist/src/ItemProperty/service/actors/saveValueToDb/analyzeInput.js +4 -4
- package/dist/src/ItemProperty/service/actors/saveValueToDb/analyzeInput.js.map +1 -1
- package/dist/src/ItemProperty/service/actors/saveValueToDb/index.d.ts +1 -1
- package/dist/src/ItemProperty/service/actors/saveValueToDb/index.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/saveValueToDb/saveImage.d.ts +5 -0
- package/dist/src/ItemProperty/service/actors/saveValueToDb/saveImage.d.ts.map +1 -0
- package/dist/src/ItemProperty/service/actors/saveValueToDb/{saveImageSrc.js → saveImage.js} +6 -6
- package/dist/src/ItemProperty/service/actors/saveValueToDb/saveImage.js.map +1 -0
- package/dist/src/ItemProperty/service/actors/saveValueToDb/saveRelation.js +2 -2
- package/dist/src/ItemProperty/service/actors/saveValueToDb/saveRelation.js.map +1 -1
- package/dist/src/ItemProperty/service/propertyMachine.d.ts +7 -7
- package/dist/src/ItemProperty/service/propertyMachine.js +6 -6
- package/dist/src/ItemProperty/service/propertyMachine.js.map +1 -1
- package/dist/src/helpers/constants.d.ts +1 -1
- package/dist/src/helpers/constants.js +1 -1
- package/dist/src/helpers/constants.js.map +1 -1
- package/dist/src/helpers/getSegmentedItemProperties.js +1 -1
- package/dist/src/helpers/getSegmentedItemProperties.js.map +1 -1
- package/dist/src/helpers/index.d.ts +1 -1
- package/dist/src/helpers/index.d.ts.map +1 -1
- package/dist/src/helpers/index.js +3 -3
- package/dist/src/helpers/index.js.map +1 -1
- package/dist/src/services/publish/actors/upload.js +1 -1
- package/dist/src/services/publish/actors/upload.js.map +1 -1
- package/package.json +1 -1
- package/dist/src/ItemProperty/service/actors/saveValueToDb/saveImageSrc.d.ts +0 -5
- package/dist/src/ItemProperty/service/actors/saveValueToDb/saveImageSrc.d.ts.map +0 -1
- package/dist/src/ItemProperty/service/actors/saveValueToDb/saveImageSrc.js.map +0 -1
|
@@ -36,7 +36,7 @@ export declare abstract class BaseItemProperty<PropertyType> implements IItemPro
|
|
|
36
36
|
getService(): import("xstate").ActorRef<import("xstate").MachineSnapshot<any, import("xstate").AnyEventObject, {
|
|
37
37
|
[x: string]: import("xstate").ActorRefFromLogic<import("xstate").CallbackActorLogic<import("xstate").EventObject, import("@/types").FromCallbackInput<any, import("xstate").EventObject>, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").CallbackActorLogic<import("xstate").EventObject, import("@/types").FromCallbackInput<any>, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").CallbackActorLogic<import("xstate").EventObject, import("@/types").FromCallbackInput<any, import("@/types").SaveValueToDbEvent>, import("xstate").EventObject>> | undefined;
|
|
38
38
|
}, "initializing" | "idle" | "waitingForDb" | "hydratingFromDb" | "resolvingRelatedValue" | "resolvingRemoteStorage" | {
|
|
39
|
-
saving: "analyzingInput" | "doneSaving" | "
|
|
39
|
+
saving: "analyzingInput" | "doneSaving" | "savingImage" | "savingRelation" | "savingItemStorage";
|
|
40
40
|
}, string, import("xstate").NonReducibleUnknown, import("xstate").MetaObject, {
|
|
41
41
|
readonly id: "itemProperty";
|
|
42
42
|
readonly initial: "waitingForDb";
|
|
@@ -146,7 +146,7 @@ export declare abstract class BaseItemProperty<PropertyType> implements IItemPro
|
|
|
146
146
|
readonly saveValueToDbSuccess: {
|
|
147
147
|
readonly target: "doneSaving";
|
|
148
148
|
};
|
|
149
|
-
readonly
|
|
149
|
+
readonly saveImage: "savingImage";
|
|
150
150
|
readonly saveRelation: "savingRelation";
|
|
151
151
|
readonly saveItemStorage: "savingItemStorage";
|
|
152
152
|
};
|
|
@@ -161,12 +161,12 @@ export declare abstract class BaseItemProperty<PropertyType> implements IItemPro
|
|
|
161
161
|
};
|
|
162
162
|
};
|
|
163
163
|
};
|
|
164
|
-
readonly
|
|
164
|
+
readonly savingImage: {
|
|
165
165
|
readonly on: {
|
|
166
|
-
readonly
|
|
166
|
+
readonly saveImageSuccess: "doneSaving";
|
|
167
167
|
};
|
|
168
168
|
readonly invoke: {
|
|
169
|
-
readonly src: "
|
|
169
|
+
readonly src: "saveImage";
|
|
170
170
|
readonly input: ({ context, event }: {
|
|
171
171
|
context: any;
|
|
172
172
|
event: any;
|
|
@@ -229,7 +229,7 @@ export declare abstract class BaseItemProperty<PropertyType> implements IItemPro
|
|
|
229
229
|
get localStoragePath(): string | void;
|
|
230
230
|
get versionLocalId(): string | undefined;
|
|
231
231
|
get status(): "initializing" | "idle" | "waitingForDb" | "hydratingFromDb" | "resolvingRelatedValue" | "resolvingRemoteStorage" | {
|
|
232
|
-
saving: "analyzingInput" | "doneSaving" | "
|
|
232
|
+
saving: "analyzingInput" | "doneSaving" | "savingImage" | "savingRelation" | "savingItemStorage";
|
|
233
233
|
};
|
|
234
234
|
get alias(): string | undefined;
|
|
235
235
|
get value(): any;
|
|
@@ -72,7 +72,7 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
72
72
|
let { refResolvedDisplayValue, refResolvedValue } = firstRow;
|
|
73
73
|
let propertyValueProcessed = propertyValueFromDb;
|
|
74
74
|
if (propertyRecordSchema &&
|
|
75
|
-
propertyRecordSchema.refValueType === '
|
|
75
|
+
propertyRecordSchema.refValueType === 'Image') {
|
|
76
76
|
let shouldReadFromFile = true;
|
|
77
77
|
if (refResolvedValue &&
|
|
78
78
|
refResolvedDisplayValue &&
|
|
@@ -94,7 +94,7 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
94
94
|
let dir = localStorageDir;
|
|
95
95
|
if (!dir &&
|
|
96
96
|
propertyRecordSchema &&
|
|
97
|
-
propertyRecordSchema.refValueType === '
|
|
97
|
+
propertyRecordSchema.refValueType === 'Image') {
|
|
98
98
|
dir = 'images';
|
|
99
99
|
}
|
|
100
100
|
dir = dir.replace(/^\//, '');
|
|
@@ -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 path from 'path'\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 if (\n propertyRecordSchema &&\n propertyRecordSchema.ref &&\n propertyRecordSchema.dataType === 'Relation' &&\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 isRelation =\n propertyRecordSchema &&\n propertyRecordSchema.ref &&\n propertyRecordSchema.dataType === 'Relation'\n\n const whereClauses = []\n\n if (isRelation) {\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 localStorageDir,\n } = firstRow\n\n let { refResolvedDisplayValue, refResolvedValue } = firstRow\n\n let propertyValueProcessed: string | string[] | undefined | null =\n propertyValueFromDb\n\n\n if (\n propertyRecordSchema &&\n propertyRecordSchema.refValueType === 'ImageSrc'\n ) {\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 })\n\n // Check if the status is in the 200-299 range\n if (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 propertyRecordSchema &&\n propertyRecordSchema.refValueType === 'ImageSrc'\n ) {\n dir = 'images'\n }\n\n dir = dir!.replace(/^\\//, '')\n\n if (\n !refResolvedValue &&\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 files = await fs.promises.readdir(dirPath)\n const matchingFiles = files.filter((file) => {\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 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 })\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 { Item } = await import(`@/browser/Item`)\n const item = await Item.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":";;;;;;;;;;;;;;;AAWe,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;AAElC,IAAA,IACE,oBAAoB;AACpB,QAAA,oBAAoB,CAAC,GAAG;QACxB,oBAAoB,CAAC,QAAQ,KAAK,UAAU;AAC5C,QAAA,CAAC,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,EAC/B;AACA,QAAA,YAAY,GAAG,eAAe,GAAG,IAAI;;AAGvC,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,eAAe,GAAG,KAAK;;AAGxC,IAAA,MAAM,cAAc,GAAG,YAAW;AAChC,QAAA,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,EAAE;QAE/B,MAAM,UAAU,GACd,oBAA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AAG,MAAM,OAAO,gCAAgB,CAAC;AAC/C,YAAA,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC;gBAC3B,WAAW;gBACX,SAAS;AACV,aAAA,CAAC;YACF,IAAI,IAAI,EAAE;AACR,gBAAA,MAAM,QAAQ,GAAG,CAAA,OAAA,EAAU,eAAe,CAAI,CAAA,EAAA,gBAAgB,EAAE;gBAChE,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,UAAU,CAAC,QAAQ,CAAC;gBAEzD,IAAI,CAAC,MAAM,EAAE;oBACX;;gBAGF,MAAM,WAAW,GAAG,MAAM,eAAe,CAAC,gBAAgB,CAAC,QAAQ,CAAC;gBACpE,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC;AAC9C,gBAAA,QAAQ,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,WAAW,EAAE,CAAC;gBAClE;;;AAGN,KAAC;AAED,IAAA,cAAc,EAAE,CAAC,IAAI,CAAC,MAAK;AACzB,QAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,sBAAsB,EAAE,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 path from 'path'\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 if (\n propertyRecordSchema &&\n propertyRecordSchema.ref &&\n propertyRecordSchema.dataType === 'Relation' &&\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 isRelation =\n propertyRecordSchema &&\n propertyRecordSchema.ref &&\n propertyRecordSchema.dataType === 'Relation'\n\n const whereClauses = []\n\n if (isRelation) {\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 localStorageDir,\n } = firstRow\n\n let { refResolvedDisplayValue, refResolvedValue } = firstRow\n\n let propertyValueProcessed: string | string[] | undefined | null =\n propertyValueFromDb\n\n\n if (\n propertyRecordSchema &&\n propertyRecordSchema.refValueType === 'Image'\n ) {\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 })\n\n // Check if the status is in the 200-299 range\n if (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 propertyRecordSchema &&\n propertyRecordSchema.refValueType === 'Image'\n ) {\n dir = 'images'\n }\n\n dir = dir!.replace(/^\\//, '')\n\n if (\n !refResolvedValue &&\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 files = await fs.promises.readdir(dirPath)\n const matchingFiles = files.filter((file) => {\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 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 })\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 { Item } = await import(`@/browser/Item`)\n const item = await Item.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":";;;;;;;;;;;;;;;AAWe,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;AAElC,IAAA,IACE,oBAAoB;AACpB,QAAA,oBAAo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AACJ,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveRelatedValue.d.ts","sourceRoot":"","sources":["../../../../../src/ItemProperty/service/actors/resolveRelatedValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAgB,
|
|
1
|
+
{"version":3,"file":"resolveRelatedValue.d.ts","sourceRoot":"","sources":["../../../../../src/ItemProperty/service/actors/resolveRelatedValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAgB,MAAgB,QAAQ,CAAA;AAG5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAWpD,eAAO,MAAM,mBAAmB,oGA6L9B,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fromCallback } from 'xstate';
|
|
2
|
-
import {
|
|
2
|
+
import { convertTxIdToImage } from '../../../helpers/index.js';
|
|
3
3
|
import debug from 'debug';
|
|
4
4
|
import { getStorageTransactionIdForSeedUid } from '../../../db/read/getStorageTransactionIdForSeedUid.js';
|
|
5
5
|
import { getRelationValueData } from '../../../db/read/getRelationValueData.js';
|
|
@@ -58,7 +58,7 @@ const resolveRelatedValue = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
58
58
|
});
|
|
59
59
|
return true;
|
|
60
60
|
}
|
|
61
|
-
const contentUrl = await
|
|
61
|
+
const contentUrl = await convertTxIdToImage(storageTransactionId);
|
|
62
62
|
if (contentUrl) {
|
|
63
63
|
seedUidToContentUrl.set(propertyValue, contentUrl);
|
|
64
64
|
}
|
|
@@ -113,7 +113,7 @@ const resolveRelatedValue = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
113
113
|
if (typeof propertyValueFromDb === 'string') {
|
|
114
114
|
// Check files for a filename that matches the propertyValue
|
|
115
115
|
if (propertyRecordSchema &&
|
|
116
|
-
propertyRecordSchema.refValueType === '
|
|
116
|
+
propertyRecordSchema.refValueType === 'Image') {
|
|
117
117
|
let contentUrl;
|
|
118
118
|
if (storageTransactionIdToContentUrl.has(propertyValueFromDb)) {
|
|
119
119
|
contentUrl =
|
|
@@ -244,7 +244,7 @@ const resolveRelatedValue = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
244
244
|
// storageId,
|
|
245
245
|
// )
|
|
246
246
|
//
|
|
247
|
-
// const contentUrl = await
|
|
247
|
+
// const contentUrl = await convertTxIdToImage(storageId)
|
|
248
248
|
//
|
|
249
249
|
// if (!contentUrl) {
|
|
250
250
|
// throw new Error(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveRelatedValue.js","sources":["../../../../../../src/ItemProperty/service/actors/resolveRelatedValue.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { BaseFileManager, convertTxIdToImageSrc } 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 convertTxIdToImageSrc(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 === 'ImageSrc'\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 convertTxIdToImageSrc(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// }"],"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;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GAAG,CAAC,eAAe,CAAC,IAAI,CAAC;AACtC,4BAAA,gCAAgC,CAAC,GAAG,CAClC,mBAAmB,EACnB,UAAU,CACX;;;oBAIL,IAAI,UAAU,EAAE;AACd,wBAAA,QAAQ,CAAC;AACP,4BAAA,IAAI,EAAE,eAAe;AACrB,4BAAA,WAAW,EAAE,UAAU;AACxB,yBAAA,CAAC;AACF,wBAAA,QAAQ,CAAC;AACP,4BAAA,IAAI,EAAE,8BAA8B;AACpC,4BAAA,uBAAuB,EAAE,UAAU;AACpC,yBAAA,CAAC;AACF,wBAAA,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;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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,QAAQ,CAAC;AACP,4BAAA,IAAI,EAAE,8BAA8B;AACpC,4BAAA,uBAAuB,EAAE,UAAU;AACpC,yBAAA,CAAC;AACF,wBAAA,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;;;;"}
|
|
@@ -20,7 +20,7 @@ const analyzeInput = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
|
20
20
|
const _analyzeInput = async () => {
|
|
21
21
|
let propertyName = propertyNameRaw;
|
|
22
22
|
if (propertyRecordSchema.refValueType &&
|
|
23
|
-
propertyRecordSchema.refValueType !== '
|
|
23
|
+
propertyRecordSchema.refValueType !== 'Image' &&
|
|
24
24
|
propertyRecordSchema.dataType === 'Relation') {
|
|
25
25
|
sendBack({
|
|
26
26
|
type: 'saveRelation',
|
|
@@ -28,10 +28,10 @@ const analyzeInput = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
|
28
28
|
});
|
|
29
29
|
return false;
|
|
30
30
|
}
|
|
31
|
-
if (propertyRecordSchema.refValueType === '
|
|
32
|
-
propertyRecordSchema.dataType === '
|
|
31
|
+
if (propertyRecordSchema.refValueType === 'Image' ||
|
|
32
|
+
propertyRecordSchema.dataType === 'Image') {
|
|
33
33
|
sendBack({
|
|
34
|
-
type: '
|
|
34
|
+
type: 'saveImage',
|
|
35
35
|
newValue,
|
|
36
36
|
});
|
|
37
37
|
return false;
|
|
@@ -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 !== '
|
|
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":";;;;;AAaa,MAAA,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,WAAW,EACX,cAAc,EACd,UAAU,EACV,aAAa,EAAE,aAAa,EAC5B,oBAAoB,EACpB,SAAS,GACV,GAAG,OAAO;AAEX,IAAA,IAAI,EAAE,SAAS,EAAE,GAAG,OAAO;AAE3B,IAAA,IAAI,QAA+B;IAEnC,IAAI,KAAK,EAAE;AACT,QAAA,QAAQ,GAAG,KAAK,CAAC,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,SAAS,GAAG,aAAa,CAAC,EAAE;;;AAIhC,QAAA,MAAM,MAAM,GAAG,MAAM,uBAAuB,CAAC;YAC3C,OAAO;YACP,YAAY;YACZ,QAAQ;YACR,WAAW;YACX,cAAc;YACd,UAAU;YACV,SAAS;YACT,SAAS;AACV,SAAA,CAAC;AAEF,QAAA,IAAI,cAAc,GAAoC;AACpD,YAAA,aAAa,EAAE,QAAQ;SACxB;QAED,IAAI,OAAO,EAAE;AACX,YAAA,cAAc,CAAC,OAAO,GAAG,OAAO;;QAGlC,IAAI,SAAS,EAAE;AACb,YAAA,cAAc,CAAC,SAAS,GAAG,SAAS;;AAGtC,QAAA,IAAI,CAAC,OAAO,IAAI,MAAM,EAAE,OAAO,EAAE;AAC/B,YAAA,cAAc,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO;;AAGzC,QAAA,IAAI,CAAC,SAAS,IAAI,MAAM,EAAE,SAAS,EAAE;AACnC,YAAA,cAAc,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS;;AAG7C,QAAA,QAAQ,CAAC;AACP,YAAA,IAAI,EAAE,eAAe;AACrB,YAAA,GAAG,cAAc;AAClB,SAAA,CAAC;AAEF,QAAA,OAAO,IAAI;AACb,KAAC;AAED,IAAA,aAAa,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,KAAI;QAC9B,IAAI,MAAM,EAAE;AACV,YAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,sBAAsB,EAAE,CAAC;;AAE9C,KAAC,CAAC;AACJ,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/ItemProperty/service/actors/saveValueToDb/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/ItemProperty/service/actors/saveValueToDb/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { EventObject } from 'xstate';
|
|
2
|
+
import { FromCallbackInput } from '@/types/machines';
|
|
3
|
+
import { SaveValueToDbEvent } from '@/types/property';
|
|
4
|
+
export declare const saveImage: import("xstate").CallbackActorLogic<EventObject, FromCallbackInput<any, SaveValueToDbEvent>, EventObject>;
|
|
5
|
+
//# sourceMappingURL=saveImage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"saveImage.d.ts","sourceRoot":"","sources":["../../../../../../src/ItemProperty/service/actors/saveValueToDb/saveImage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAgB,MAAM,QAAQ,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAGL,kBAAkB,EACnB,MAAM,kBAAkB,CAAA;AA+CzB,eAAO,MAAM,SAAS,2GA2LpB,CAAA"}
|
|
@@ -32,7 +32,7 @@ const fetchImage = async (url) => {
|
|
|
32
32
|
return base64;
|
|
33
33
|
};
|
|
34
34
|
let imageSchemaUid;
|
|
35
|
-
const
|
|
35
|
+
const saveImage = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
36
36
|
const { localId, propertyName: propertyNameRaw, propertyValue: existingValue, propertyRecordSchema, modelName, seedLocalId, seedUid, versionLocalId, versionUid, } = context;
|
|
37
37
|
let { schemaUid } = context;
|
|
38
38
|
let newValue;
|
|
@@ -43,7 +43,7 @@ const saveImageSrc = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
|
43
43
|
sendBack({ type: 'saveValueToDbSuccess' });
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
|
-
const
|
|
46
|
+
const _saveImage = async () => {
|
|
47
47
|
let propertyName = propertyNameRaw;
|
|
48
48
|
if (!propertyNameRaw.endsWith('Id')) {
|
|
49
49
|
propertyName = `${propertyName}Id`;
|
|
@@ -169,10 +169,10 @@ const saveImageSrc = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
|
169
169
|
schemaUid,
|
|
170
170
|
});
|
|
171
171
|
};
|
|
172
|
-
|
|
173
|
-
sendBack({ type: '
|
|
172
|
+
_saveImage().then(() => {
|
|
173
|
+
sendBack({ type: 'saveImageSuccess' });
|
|
174
174
|
});
|
|
175
175
|
});
|
|
176
176
|
|
|
177
|
-
export {
|
|
178
|
-
//# sourceMappingURL=
|
|
177
|
+
export { saveImage };
|
|
178
|
+
//# sourceMappingURL=saveImage.js.map
|
|
@@ -0,0 +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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uB;AACvB,gBAAA,gBAAgB,EAAE,QAAQ;AAC1B,gBAEA,eAAe,EAAE,SAElB,CAAA,CAAC;;AAGJ,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,KAAC;AAED,IAAA,UAAU,EAAE,CAAC,IAAI,CAAC,MAAK;AACrB,QAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC;AACxC,KAAC,CAAC;AACJ,CAAC;;;;"}
|
|
@@ -22,9 +22,9 @@ const saveRelation = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
|
22
22
|
if (newValue instanceof File) {
|
|
23
23
|
newValueType = 'file';
|
|
24
24
|
}
|
|
25
|
-
if (propertyRecordSchema.dataType === '
|
|
25
|
+
if (propertyRecordSchema.dataType === 'Image') {
|
|
26
26
|
sendBack({
|
|
27
|
-
type: '
|
|
27
|
+
type: 'saveImage',
|
|
28
28
|
newValue,
|
|
29
29
|
newValueType,
|
|
30
30
|
});
|
|
@@ -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 === '
|
|
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":";;;AASa,MAAA,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;;AAGjD,IAAA,IAAI,QAA+B;IAEnC,IAAI,KAAK,EAAE;AACT,QAAA,QAAQ,GAAG,KAAK,CAAC,QAAQ;;AAG3B,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;;AAGpC,QAAA,IAAI,YAAY;AAEhB,QAAA,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;AAChC,YAAA,YAAY,GAAG,qBAAqB,CAAC,QAAQ,CAAC;;AAGhD,QAAA,IAAI,QAAQ,YAAY,IAAI,EAAE;YAC5B,YAAY,GAAG,MAAM;;AAGvB,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;;AAGd,QAAA,OAAO,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCb,KAAC;AAED,IAAA,aAAa,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,KAAI;QAC9B,IAAI,MAAM,EAAE;AACV,YAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,qBAAqB,EAAE,CAAC;;AAE7C,KAAC,CAAC;AACJ,CAAC;;;;"}
|
|
@@ -17,8 +17,8 @@ export declare const propertyMachine: import("xstate").StateMachine<any, import(
|
|
|
17
17
|
logic: import("xstate").CallbackActorLogic<import("xstate").EventObject, import("@/types").FromCallbackInput<any, import("@/types").SaveValueToDbEvent>, import("xstate").EventObject>;
|
|
18
18
|
id: string | undefined;
|
|
19
19
|
};
|
|
20
|
-
|
|
21
|
-
src: "
|
|
20
|
+
saveImage: {
|
|
21
|
+
src: "saveImage";
|
|
22
22
|
logic: import("xstate").CallbackActorLogic<import("xstate").EventObject, import("@/types").FromCallbackInput<any, import("@/types").SaveValueToDbEvent>, import("xstate").EventObject>;
|
|
23
23
|
id: string | undefined;
|
|
24
24
|
};
|
|
@@ -48,7 +48,7 @@ export declare const propertyMachine: import("xstate").StateMachine<any, import(
|
|
|
48
48
|
id: string | undefined;
|
|
49
49
|
};
|
|
50
50
|
}>, never, never, never, "initializing" | "idle" | "waitingForDb" | "hydratingFromDb" | "resolvingRelatedValue" | "resolvingRemoteStorage" | {
|
|
51
|
-
saving: "analyzingInput" | "doneSaving" | "
|
|
51
|
+
saving: "analyzingInput" | "doneSaving" | "savingImage" | "savingRelation" | "savingItemStorage";
|
|
52
52
|
}, string, any, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").MetaObject, {
|
|
53
53
|
readonly id: "itemProperty";
|
|
54
54
|
readonly initial: "waitingForDb";
|
|
@@ -158,7 +158,7 @@ export declare const propertyMachine: import("xstate").StateMachine<any, import(
|
|
|
158
158
|
readonly saveValueToDbSuccess: {
|
|
159
159
|
readonly target: "doneSaving";
|
|
160
160
|
};
|
|
161
|
-
readonly
|
|
161
|
+
readonly saveImage: "savingImage";
|
|
162
162
|
readonly saveRelation: "savingRelation";
|
|
163
163
|
readonly saveItemStorage: "savingItemStorage";
|
|
164
164
|
};
|
|
@@ -173,12 +173,12 @@ export declare const propertyMachine: import("xstate").StateMachine<any, import(
|
|
|
173
173
|
};
|
|
174
174
|
};
|
|
175
175
|
};
|
|
176
|
-
readonly
|
|
176
|
+
readonly savingImage: {
|
|
177
177
|
readonly on: {
|
|
178
|
-
readonly
|
|
178
|
+
readonly saveImageSuccess: "doneSaving";
|
|
179
179
|
};
|
|
180
180
|
readonly invoke: {
|
|
181
|
-
readonly src: "
|
|
181
|
+
readonly src: "saveImage";
|
|
182
182
|
readonly input: ({ context, event }: {
|
|
183
183
|
context: any;
|
|
184
184
|
event: any;
|
|
@@ -5,7 +5,7 @@ import { initialize } from './actors/initialize.js';
|
|
|
5
5
|
import { resolveRelatedValue } from './actors/resolveRelatedValue.js';
|
|
6
6
|
import { hydrateFromDb } from './actors/hydrateFromDb.js';
|
|
7
7
|
import { analyzeInput } from './actors/saveValueToDb/analyzeInput.js';
|
|
8
|
-
import {
|
|
8
|
+
import { saveImage } from './actors/saveValueToDb/saveImage.js';
|
|
9
9
|
import { saveRelation } from './actors/saveValueToDb/saveRelation.js';
|
|
10
10
|
import { saveItemStorage } from './actors/saveValueToDb/saveItemStorage.js';
|
|
11
11
|
|
|
@@ -25,7 +25,7 @@ const propertyMachine = setup({
|
|
|
25
25
|
resolveRelatedValue,
|
|
26
26
|
resolveRemoteStorage,
|
|
27
27
|
analyzeInput,
|
|
28
|
-
|
|
28
|
+
saveImage,
|
|
29
29
|
saveRelation,
|
|
30
30
|
saveItemStorage,
|
|
31
31
|
},
|
|
@@ -132,7 +132,7 @@ const propertyMachine = setup({
|
|
|
132
132
|
saveValueToDbSuccess: {
|
|
133
133
|
target: 'doneSaving',
|
|
134
134
|
},
|
|
135
|
-
|
|
135
|
+
saveImage: 'savingImage',
|
|
136
136
|
saveRelation: 'savingRelation',
|
|
137
137
|
saveItemStorage: 'savingItemStorage',
|
|
138
138
|
},
|
|
@@ -141,12 +141,12 @@ const propertyMachine = setup({
|
|
|
141
141
|
input: ({ context, event }) => ({ context, event }),
|
|
142
142
|
},
|
|
143
143
|
},
|
|
144
|
-
|
|
144
|
+
savingImage: {
|
|
145
145
|
on: {
|
|
146
|
-
|
|
146
|
+
saveImageSuccess: 'doneSaving',
|
|
147
147
|
},
|
|
148
148
|
invoke: {
|
|
149
|
-
src: '
|
|
149
|
+
src: 'saveImage',
|
|
150
150
|
input: ({ context, event }) => ({ context, event }),
|
|
151
151
|
},
|
|
152
152
|
},
|
|
@@ -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
|
|
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,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A;;;;;;;;;;;AAYF,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sources":["../../../../src/helpers/constants.ts"],"sourcesContent":["import {\n AttestationRequestData,\n ZERO_BYTES,\n ZERO_BYTES32,\n ZERO_ADDRESS,\n} from '@ethereum-attestation-service/eas-sdk'\n\n\nexport const SCHEMA_NJK = 'schema.njk'\nexport const SCHEMA_TS = 'schema.ts'\n\nexport const INTERNAL_DATA_TYPES = {\n Text: {\n eas: 'string',\n },\n Number: {\n eas: 'uint8',\n },\n
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../../../src/helpers/constants.ts"],"sourcesContent":["import {\n AttestationRequestData,\n ZERO_BYTES,\n ZERO_BYTES32,\n ZERO_ADDRESS,\n} from '@ethereum-attestation-service/eas-sdk'\n\n\nexport const SCHEMA_NJK = 'schema.njk'\nexport const SCHEMA_TS = 'schema.ts'\n\nexport const INTERNAL_DATA_TYPES = {\n Text: {\n eas: 'string',\n },\n Number: {\n eas: 'uint8',\n },\n Image: {\n eas: 'string',\n },\n Relation: {\n eas: 'bytes32',\n },\n List: {\n eas: 'bytes32[]',\n },\n FileSrc: {\n eas: 'string',\n },\n Json: {\n eas: 'string',\n },\n Blob: {\n eas: 'bytes32',\n },\n}\n\nexport const internalPropertyNames = [\n 'localId',\n 'uid',\n 'seedLocalId',\n 'seedUid',\n 'schemaUid',\n 'attestationCreatedAt',\n 'createdAt',\n 'updatedAt',\n 'versionsCount',\n 'lastVersionPublishedAt',\n 'latestVersionLocalId',\n 'versionLocalId',\n 'lastLocalUpdateAt',\n 'storageTransactionId',\n 'versionUid',\n 'refSeedType',\n 'refValueType',\n 'refResolvedValue',\n 'refResolvedDisplayValue',\n 'type',\n]\n\nexport const VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA =\n '0x13c0fd59d69dbce40501a41f8b37768d26dd2e2bb0cad64615334d84f7b9bdf6'\n\nexport const defaultAttestationData: AttestationRequestData = {\n recipient: ZERO_ADDRESS,\n revocable: true,\n value: BigInt(0),\n refUID: ZERO_BYTES32,\n expirationTime: BigInt(0),\n data: ZERO_BYTES,\n}\n\nexport enum ImageSize {\n EXTRA_SMALL = 480,\n SMALL = 760,\n MEDIUM = 1024,\n LARGE = 1440,\n EXTRA_LARGE = 1920,\n}\n\nexport const CLIENT_NOT_INITIALIZED = 'ClientManager is not initialized. Please call init() first.'\n\nexport const INIT_SCRIPT_SUCCESS_MESSAGE = '[Seed Protocol] Finished running init script'\n"],"names":[],"mappings":";;AAQO,MAAM,UAAU,GAAG;AACnB,MAAM,SAAS,GAAG;AAEZ,MAAA,mBAAmB,GAAG;AACjC,IAAA,IAAI,EAAE;AACJ,QAAA,GAAG,EAAE,QAAQ;AACd,KAAA;AACD,IAAA,MAAM,EAAE;AACN,QAAA,GAAG,EAAE,OAAO;AACb,KAAA;AACD,IAAA,KAAK,EAAE;AACL,QAAA,GAAG,EAAE,QAAQ;AACd,KAAA;AACD,IAAA,QAAQ,EAAE;AACR,QAAA,GAAG,EAAE,SAAS;AACf,KAAA;AACD,IAAA,IAAI,EAAE;AACJ,QAAA,GAAG,EAAE,WAAW;AACjB,KAAA;AACD,IAAA,OAAO,EAAE;AACP,QAAA,GAAG,EAAE,QAAQ;AACd,KAAA;AACD,IAAA,IAAI,EAAE;AACJ,QAAA,GAAG,EAAE,QAAQ;AACd,KAAA;AACD,IAAA,IAAI,EAAE;AACJ,QAAA,GAAG,EAAE,SAAS;AACf,KAAA;;AAGU,MAAA,qBAAqB,GAAG;IACnC,SAAS;IACT,KAAK;IACL,aAAa;IACb,SAAS;IACT,WAAW;IACX,sBAAsB;IACtB,WAAW;IACX,WAAW;IACX,eAAe;IACf,wBAAwB;IACxB,sBAAsB;IACtB,gBAAgB;IAChB,mBAAmB;IACnB,sBAAsB;IACtB,YAAY;IACZ,aAAa;IACb,cAAc;IACd,kBAAkB;IAClB,yBAAyB;IACzB,MAAM;;AAGD,MAAM,mCAAmC,GAC9C;AAEW,MAAA,sBAAsB,GAA2B;AAC5D,IAAA,SAAS,EAAE,YAAY;AACvB,IAAA,SAAS,EAAE,IAAI;AACf,IAAA,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;AAChB,IAAA,MAAM,EAAE,YAAY;AACpB,IAAA,cAAc,EAAE,MAAM,CAAC,CAAC,CAAC;AACzB,IAAA,IAAI,EAAE,UAAU;;IAGN;AAAZ,CAAA,UAAY,SAAS,EAAA;AACnB,IAAA,SAAA,CAAA,SAAA,CAAA,aAAA,CAAA,GAAA,GAAA,CAAA,GAAA,aAAiB;AACjB,IAAA,SAAA,CAAA,SAAA,CAAA,OAAA,CAAA,GAAA,GAAA,CAAA,GAAA,OAAW;AACX,IAAA,SAAA,CAAA,SAAA,CAAA,QAAA,CAAA,GAAA,IAAA,CAAA,GAAA,QAAa;AACb,IAAA,SAAA,CAAA,SAAA,CAAA,OAAA,CAAA,GAAA,IAAA,CAAA,GAAA,OAAY;AACZ,IAAA,SAAA,CAAA,SAAA,CAAA,aAAA,CAAA,GAAA,IAAA,CAAA,GAAA,aAAkB;AACpB,CAAC,EANW,SAAS,KAAT,SAAS,GAMpB,EAAA,CAAA,CAAA;AAEM,MAAM,sBAAsB,GAAG;AAE/B,MAAM,2BAA2B,GAAG;;;;"}
|
|
@@ -12,7 +12,7 @@ const getSegmentedItemProperties = (item) => {
|
|
|
12
12
|
const isItemStorage = itemProperty.propertyDef.storageType &&
|
|
13
13
|
itemProperty.propertyDef.storageType === 'ItemStorage';
|
|
14
14
|
itemProperty.propertyDef.dataType === 'Relation' &&
|
|
15
|
-
itemProperty.propertyDef.refValueType === '
|
|
15
|
+
itemProperty.propertyDef.refValueType === 'Image';
|
|
16
16
|
const isStorageTransaction = itemProperty.propertyName === 'storageTransactionId';
|
|
17
17
|
if (itemProperty.propertyDef.dataType === 'Relation') {
|
|
18
18
|
itemRelationProperties.push(itemProperty);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSegmentedItemProperties.js","sources":["../../../../src/helpers/getSegmentedItemProperties.ts"],"sourcesContent":["import { UploadProperty } from '@/db/read/getPublishUploads'\nimport { IItem } from '@/interfaces'\n\nexport const getSegmentedItemProperties = (item: IItem<any>) => {\n const itemBasicProperties = []\n const itemRelationProperties = []\n const itemListProperties = []\n const itemUploadProperties: UploadProperty[] = []\n const itemStorageProperties = []\n let itemStorageTransactionProperty: UploadProperty | undefined\n\n for (const itemProperty of Object.values(item.properties)) {\n if (!itemProperty.propertyDef) {\n continue\n }\n\n const isItemStorage =\n itemProperty.propertyDef.storageType &&\n itemProperty.propertyDef.storageType === 'ItemStorage'\n\n const
|
|
1
|
+
{"version":3,"file":"getSegmentedItemProperties.js","sources":["../../../../src/helpers/getSegmentedItemProperties.ts"],"sourcesContent":["import { UploadProperty } from '@/db/read/getPublishUploads'\nimport { IItem } from '@/interfaces'\n\nexport const getSegmentedItemProperties = (item: IItem<any>) => {\n const itemBasicProperties = []\n const itemRelationProperties = []\n const itemListProperties = []\n const itemUploadProperties: UploadProperty[] = []\n const itemStorageProperties = []\n let itemStorageTransactionProperty: UploadProperty | undefined\n\n for (const itemProperty of Object.values(item.properties)) {\n if (!itemProperty.propertyDef) {\n continue\n }\n\n const isItemStorage =\n itemProperty.propertyDef.storageType &&\n itemProperty.propertyDef.storageType === 'ItemStorage'\n\n const isImage =\n itemProperty.propertyDef.dataType === 'Relation' &&\n itemProperty.propertyDef.refValueType === 'Image'\n\n const isStorageTransaction =\n itemProperty.propertyName === 'storageTransactionId'\n\n if (itemProperty.propertyDef.dataType === 'Relation') {\n itemRelationProperties.push(itemProperty)\n continue\n }\n\n if (itemProperty.propertyDef.dataType === 'List') {\n itemListProperties.push(itemProperty)\n continue\n }\n\n if (isItemStorage) {\n itemStorageProperties.push(itemProperty)\n continue\n }\n\n if (isStorageTransaction) {\n itemStorageTransactionProperty = { itemProperty, childProperties: [] }\n continue\n }\n\n itemBasicProperties.push(itemProperty)\n }\n\n if (itemStorageTransactionProperty && itemStorageProperties.length > 0) {\n itemStorageTransactionProperty.childProperties = itemStorageProperties\n }\n\n if (itemStorageTransactionProperty) {\n itemUploadProperties.push(itemStorageTransactionProperty)\n }\n\n return {\n itemBasicProperties,\n itemRelationProperties,\n itemListProperties,\n itemUploadProperties,\n }\n}\n"],"names":[],"mappings":"AAGa,MAAA,0BAA0B,GAAG,CAAC,IAAgB,KAAI;IAC7D,MAAM,mBAAmB,GAAG,EAAE;IAC9B,MAAM,sBAAsB,GAAG,EAAE;IACjC,MAAM,kBAAkB,GAAG,EAAE;IAC7B,MAAM,oBAAoB,GAAqB,EAAE;IACjD,MAAM,qBAAqB,GAAG,EAAE;AAChC,IAAA,IAAI,8BAA0D;AAE9D,IAAA,KAAK,MAAM,YAAY,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;AACzD,QAAA,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE;YAC7B;;AAGF,QAAA,MAAM,aAAa,GACjB,YAAY,CAAC,WAAW,CAAC,WAAW;AACpC,YAAA,YAAY,CAAC,WAAW,CAAC,WAAW,KAAK,aAAa;QAGtD,YAAY,CAAC,WAAW,CAAC,QAAQ,KAAK,UAAU;AAChD,YAAA,YAAY,CAAC,WAAW,CAAC,YAAY,KAAK;AAE5C,QAAA,MAAM,oBAAoB,GACxB,YAAY,CAAC,YAAY,KAAK,sBAAsB;QAEtD,IAAI,YAAY,CAAC,WAAW,CAAC,QAAQ,KAAK,UAAU,EAAE;AACpD,YAAA,sBAAsB,CAAC,IAAI,CAAC,YAAY,CAAC;YACzC;;QAGF,IAAI,YAAY,CAAC,WAAW,CAAC,QAAQ,KAAK,MAAM,EAAE;AAChD,YAAA,kBAAkB,CAAC,IAAI,CAAC,YAAY,CAAC;YACrC;;QAGF,IAAI,aAAa,EAAE;AACjB,YAAA,qBAAqB,CAAC,IAAI,CAAC,YAAY,CAAC;YACxC;;QAGF,IAAI,oBAAoB,EAAE;YACxB,8BAA8B,GAAG,EAAE,YAAY,EAAE,eAAe,EAAE,EAAE,EAAE;YACtE;;AAGF,QAAA,mBAAmB,CAAC,IAAI,CAAC,YAAY,CAAC;;IAGxC,IAAI,8BAA8B,IAAI,qBAAqB,CAAC,MAAM,GAAG,CAAC,EAAE;AACtE,QAAA,8BAA8B,CAAC,eAAe,GAAG,qBAAqB;;IAGxE,IAAI,8BAA8B,EAAE;AAClC,QAAA,oBAAoB,CAAC,IAAI,CAAC,8BAA8B,CAAC;;IAG3D,OAAO;QACL,mBAAmB;QACnB,sBAAsB;QACtB,kBAAkB;QAClB,oBAAoB;KACrB;AACH;;;;"}
|
|
@@ -9,7 +9,7 @@ export declare const identifyString: (str: string) => "json" | "text" | "base64"
|
|
|
9
9
|
export declare const getMimeType: (base64: string) => string | null;
|
|
10
10
|
export declare const getCorrectId: GetCorrectId;
|
|
11
11
|
export declare const getDataTypeFromString: (data: string) => "imageBase64" | "base64" | "url" | null;
|
|
12
|
-
export declare const
|
|
12
|
+
export declare const convertTxIdToImage: (txId: string) => Promise<string | undefined>;
|
|
13
13
|
export declare const getExecutionTime: (task: any, args: any) => Promise<number>;
|
|
14
14
|
export declare const capitalizeFirstLetter: (string: string) => string;
|
|
15
15
|
export declare const parseEasRelationPropertyName: (easPropertyName: string) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAG9C,cAAc,mCAAmC,CAAA;AACjD,cAAc,2BAA2B,CAAA;AACzC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,+BAA+B,CAAA;AAM7C,eAAO,MAAM,UAAU,QAAO,MAE7B,CAAA;AAED,eAAO,MAAM,WAAW,QAAS,MAAM,WAEtC,CAAA;AAED,eAAO,MAAM,cAAc,QAAS,MAAM,iEA2BzC,CAAA;AAED,eAAO,MAAM,WAAW,WAAY,MAAM,kBAWzC,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,YAe1B,CAAA;AAED,eAAO,MAAM,qBAAqB,SAC1B,MAAM,KACX,aAAa,GAAG,QAAQ,GAAG,KAAK,GAAG,IAwBrC,CAAA;AAED,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAG9C,cAAc,mCAAmC,CAAA;AACjD,cAAc,2BAA2B,CAAA;AACzC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,+BAA+B,CAAA;AAM7C,eAAO,MAAM,UAAU,QAAO,MAE7B,CAAA;AAED,eAAO,MAAM,WAAW,QAAS,MAAM,WAEtC,CAAA;AAED,eAAO,MAAM,cAAc,QAAS,MAAM,iEA2BzC,CAAA;AAED,eAAO,MAAM,WAAW,WAAY,MAAM,kBAWzC,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,YAe1B,CAAA;AAED,eAAO,MAAM,qBAAqB,SAC1B,MAAM,KACX,aAAa,GAAG,QAAQ,GAAG,KAAK,GAAG,IAwBrC,CAAA;AAED,eAAO,MAAM,kBAAkB,SACvB,MAAM,KACX,OAAO,CAAC,MAAM,GAAG,SAAS,CAc5B,CAAA;AAED,eAAO,MAAM,gBAAgB,2CAI5B,CAAA;AAED,eAAO,MAAM,qBAAqB,WAAY,MAAM,WACF,CAAA;AAElD,eAAO,MAAM,4BAA4B,oBAAqB,MAAM;;;;CAiBnE,CAAA;AAED,eAAO,MAAM,cAAc,WACjB,MAAM,GAAG,IAAI,GAAG,SAAS,QAC3B,UAAU,GAAG,SAAS,KAC3B,OAAO,CAAC,MAAM,CAkBhB,CAAA;AAED,eAAO,MAAM,QAAQ,gBAAiB,WAAW,KAAG,OAwBnD,CAAA"}
|
|
@@ -58,11 +58,11 @@ const getDataTypeFromString = (data) => {
|
|
|
58
58
|
}
|
|
59
59
|
return null;
|
|
60
60
|
};
|
|
61
|
-
const
|
|
61
|
+
const convertTxIdToImage = async (txId) => {
|
|
62
62
|
const imageFilePath = `/files/images/${txId}`;
|
|
63
63
|
const fileExists = await BaseFileManager.pathExists(imageFilePath);
|
|
64
64
|
if (!fileExists) {
|
|
65
|
-
logger(`[ItemView] [
|
|
65
|
+
logger(`[ItemView] [updateImage] ${imageFilePath} does not exist`);
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
68
68
|
const buffer = await BaseFileManager.readFileAsBuffer(imageFilePath);
|
|
@@ -97,5 +97,5 @@ const getContentHash = async (base64, uint) => {
|
|
|
97
97
|
return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
98
98
|
};
|
|
99
99
|
|
|
100
|
-
export { BaseFileManager,
|
|
100
|
+
export { BaseFileManager, convertTxIdToImage, generateId, getContentHash, getCorrectId, getDataTypeFromString, getMimeType, parseEasRelationPropertyName, toSnakeCase };
|
|
101
101
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/helpers/index.ts"],"sourcesContent":["import { customAlphabet } from 'nanoid'\nimport * as nanoIdDictionary from 'nanoid-dictionary'\nimport debug from 'debug'\nimport { GetCorrectId } from '@/types/helpers'\nimport { GetCorrectIdReturn } from '@/types/helpers'\nimport { BaseFileManager } from './FileManager/BaseFileManager'\nexport * from './ArweaveClient/BaseArweaveClient'\nexport * from './EasClient/BaseEasClient'\nexport * from './QueryClient/BaseQueryClient'\nexport * from './FileManager/BaseFileManager'\nconst logger = debug('seedSdk:shared:helpers')\n\n\nconst { alphanumeric } = nanoIdDictionary\n\nexport const generateId = (): string => {\n return customAlphabet(alphanumeric, 10)()\n}\n\nexport const toSnakeCase = (str: string) => {\n return str.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase()\n}\n\nexport const identifyString = (str: string) => {\n try {\n JSON.parse(str)\n return 'json'\n } catch (e) {\n // Not JSON\n }\n\n if (!str) {\n return\n }\n\n if (str.trim().startsWith('<') && str.trim().endsWith('>')) {\n return 'html'\n }\n\n // Simple markdown checks (very naive)\n if (/^#{1,6}\\s|^-{3,}|\\*{3,}|^-{1,2}\\s|\\*\\s/.test(str)) {\n return 'markdown'\n }\n\n if (/^data:image\\/[a-zA-Z]+;base64,[A-Za-z0-9+/]+={0,2}$/.test(str)) {\n return 'base64'\n }\n\n // Default to plain text if unsure\n return 'text'\n}\n\nexport const getMimeType = (base64: string) => {\n if (!base64) {\n return null\n }\n const result = base64.match(/^data:([a-zA-Z0-9]+\\/[a-zA-Z0-9-.+]+).*,/)\n\n if (result && result.length > 1) {\n return result[1]\n } else {\n return null // MIME type could not be determined\n }\n}\n\nexport const getCorrectId: GetCorrectId = (localIdOrUid: string) => {\n const id: GetCorrectIdReturn = {\n localId: undefined,\n uid: undefined,\n }\n if (!localIdOrUid) {\n return id\n }\n if (localIdOrUid.length === 10) {\n id.localId = localIdOrUid\n }\n if (localIdOrUid.startsWith('0x') && localIdOrUid.length === 66) {\n id.uid = localIdOrUid\n }\n return id\n}\n\nexport const getDataTypeFromString = (\n data: string,\n): 'imageBase64' | 'base64' | 'url' | null => {\n const nonImageBase64Regex =\n /^(?!data:image\\/(?:jpeg|png|gif|bmp|webp);base64,)[A-Za-z0-9+/=]+$/\n\n if (nonImageBase64Regex.test(data)) {\n return 'base64'\n }\n\n // Regular expression for base64 (simple version, checking for base64 format)\n const imageBase64Regex = /^data:image\\/[a-zA-Z]+;base64,[A-Za-z0-9+/]+={0,2}$/\n\n if (imageBase64Regex.test(data)) {\n return 'imageBase64'\n }\n\n // Regular expression for URL (simple version, checking for common URL format)\n const urlRegex =\n /^(http:\\/\\/www\\.|https:\\/\\/www\\.|http:\\/\\/|https:\\/\\/)?[a-z0-9]+([\\-\\.]{1}[a-z0-9]+)*\\.[a-z]{2,5}(:[0-9]{1,5})?(\\/.*)?$/\n\n if (urlRegex.test(data)) {\n return 'url'\n }\n\n return null\n}\n\nexport const
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/helpers/index.ts"],"sourcesContent":["import { customAlphabet } from 'nanoid'\nimport * as nanoIdDictionary from 'nanoid-dictionary'\nimport debug from 'debug'\nimport { GetCorrectId } from '@/types/helpers'\nimport { GetCorrectIdReturn } from '@/types/helpers'\nimport { BaseFileManager } from './FileManager/BaseFileManager'\nexport * from './ArweaveClient/BaseArweaveClient'\nexport * from './EasClient/BaseEasClient'\nexport * from './QueryClient/BaseQueryClient'\nexport * from './FileManager/BaseFileManager'\nconst logger = debug('seedSdk:shared:helpers')\n\n\nconst { alphanumeric } = nanoIdDictionary\n\nexport const generateId = (): string => {\n return customAlphabet(alphanumeric, 10)()\n}\n\nexport const toSnakeCase = (str: string) => {\n return str.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase()\n}\n\nexport const identifyString = (str: string) => {\n try {\n JSON.parse(str)\n return 'json'\n } catch (e) {\n // Not JSON\n }\n\n if (!str) {\n return\n }\n\n if (str.trim().startsWith('<') && str.trim().endsWith('>')) {\n return 'html'\n }\n\n // Simple markdown checks (very naive)\n if (/^#{1,6}\\s|^-{3,}|\\*{3,}|^-{1,2}\\s|\\*\\s/.test(str)) {\n return 'markdown'\n }\n\n if (/^data:image\\/[a-zA-Z]+;base64,[A-Za-z0-9+/]+={0,2}$/.test(str)) {\n return 'base64'\n }\n\n // Default to plain text if unsure\n return 'text'\n}\n\nexport const getMimeType = (base64: string) => {\n if (!base64) {\n return null\n }\n const result = base64.match(/^data:([a-zA-Z0-9]+\\/[a-zA-Z0-9-.+]+).*,/)\n\n if (result && result.length > 1) {\n return result[1]\n } else {\n return null // MIME type could not be determined\n }\n}\n\nexport const getCorrectId: GetCorrectId = (localIdOrUid: string) => {\n const id: GetCorrectIdReturn = {\n localId: undefined,\n uid: undefined,\n }\n if (!localIdOrUid) {\n return id\n }\n if (localIdOrUid.length === 10) {\n id.localId = localIdOrUid\n }\n if (localIdOrUid.startsWith('0x') && localIdOrUid.length === 66) {\n id.uid = localIdOrUid\n }\n return id\n}\n\nexport const getDataTypeFromString = (\n data: string,\n): 'imageBase64' | 'base64' | 'url' | null => {\n const nonImageBase64Regex =\n /^(?!data:image\\/(?:jpeg|png|gif|bmp|webp);base64,)[A-Za-z0-9+/=]+$/\n\n if (nonImageBase64Regex.test(data)) {\n return 'base64'\n }\n\n // Regular expression for base64 (simple version, checking for base64 format)\n const imageBase64Regex = /^data:image\\/[a-zA-Z]+;base64,[A-Za-z0-9+/]+={0,2}$/\n\n if (imageBase64Regex.test(data)) {\n return 'imageBase64'\n }\n\n // Regular expression for URL (simple version, checking for common URL format)\n const urlRegex =\n /^(http:\\/\\/www\\.|https:\\/\\/www\\.|http:\\/\\/|https:\\/\\/)?[a-z0-9]+([\\-\\.]{1}[a-z0-9]+)*\\.[a-z]{2,5}(:[0-9]{1,5})?(\\/.*)?$/\n\n if (urlRegex.test(data)) {\n return 'url'\n }\n\n return null\n}\n\nexport const convertTxIdToImage = async (\n txId: string,\n): Promise<string | undefined> => {\n const imageFilePath = `/files/images/${txId}`\n const fileExists = await BaseFileManager.pathExists(imageFilePath)\n if (!fileExists) {\n logger(`[ItemView] [updateImage] ${imageFilePath} does not exist`)\n return\n }\n const buffer = await BaseFileManager.readFileAsBuffer(imageFilePath)\n\n const uint = new Uint8Array(buffer)\n\n const imageBlob = new Blob([uint])\n\n return URL.createObjectURL(imageBlob)\n}\n\nexport const getExecutionTime = async (task, args) => {\n const start = Date.now()\n await task(...args)\n return Date.now() - start\n}\n\nexport const capitalizeFirstLetter = (string: string) =>\n string.charAt(0).toUpperCase() + string.slice(1)\n\nexport const parseEasRelationPropertyName = (easPropertyName: string) => {\n // Split the input string on the first underscore\n const [singularProperty, modelName, idSegment] = easPropertyName.split('_')\n\n // If there are any other parts, assume it is a list (e.g., has 'ids' or other suffix)\n const isList = idSegment === 'ids'\n\n // Create the final property name by pluralizing the singular part\n const propertyName = singularProperty.endsWith('s')\n ? singularProperty\n : singularProperty + 's'\n\n return {\n propertyName, // Plural form of the property name\n modelName, // Model name extracted from the second part\n isList, // True if the property is a list (e.g., 'ids' is present)\n }\n}\n\nexport const getContentHash = async (\n base64: string | null | undefined,\n uint: Uint8Array | undefined,\n): Promise<string> => {\n let data\n\n if (base64 && !uint) {\n const encoder = new TextEncoder()\n data = encoder.encode(base64)\n }\n\n if (uint) {\n data = uint\n }\n\n // Hash the data with SHA-256\n const hashBuffer = await crypto.subtle.digest('SHA-256', data as Uint8Array)\n\n // Convert the ArrayBuffer to a hex string\n const hashArray = Array.from(new Uint8Array(hashBuffer))\n return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('')\n}\n\nexport const isBinary = (arrayBuffer: ArrayBuffer): boolean => {\n const view = new Uint8Array(arrayBuffer);\n\n let nonTextCount = 0;\n const threshold = 0.2; // Adjust as needed (e.g., 20% non-text implies binary)\n\n for (let i = 0; i < view.length; i++) {\n const byte = view[i];\n\n // ASCII printable characters (32-126) and common whitespace (9, 10, 13)\n if (\n (byte >= 32 && byte <= 126) || // Printable ASCII\n byte === 9 || byte === 10 || byte === 13 // Tab, LF, CR\n ) {\n continue;\n }\n\n nonTextCount++;\n if (nonTextCount / view.length > threshold) {\n return true; // More than threshold are non-text bytes\n }\n }\n\n return false; // Fewer than threshold are non-text bytes\n}\n"],"names":[],"mappings":";;;;;;;AAUA,MAAM,MAAM,GAAG,KAAK,CAAC,wBAAwB,CAAC;AAG9C,MAAM,EAAE,YAAY,EAAE,GAAG,gBAAgB;AAElC,MAAM,UAAU,GAAG,MAAa;AACrC,IAAA,OAAO,cAAc,CAAC,YAAY,EAAE,EAAE,CAAC,EAAE;AAC3C;AAEa,MAAA,WAAW,GAAG,CAAC,GAAW,KAAI;IACzC,OAAO,GAAG,CAAC,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC,WAAW,EAAE;AAC9D;AA+Ba,MAAA,WAAW,GAAG,CAAC,MAAc,KAAI;IAC5C,IAAI,CAAC,MAAM,EAAE;AACX,QAAA,OAAO,IAAI;;IAEb,MAAM,MAA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AC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;AACvE;;;;"}
|
|
@@ -24,7 +24,7 @@ const upload = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
24
24
|
continue;
|
|
25
25
|
}
|
|
26
26
|
if (editedProperty.propertyDef.refValueType &&
|
|
27
|
-
editedProperty.propertyDef.refValueType === '
|
|
27
|
+
editedProperty.propertyDef.refValueType === 'Image') {
|
|
28
28
|
const context = editedProperty.getService().getSnapshot().context;
|
|
29
29
|
const imageSeedId = context.propertyValue;
|
|
30
30
|
const { localId, uid } = getCorrectId(imageSeedId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload.js","sources":["../../../../../../src/services/publish/actors/upload.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { FromCallbackInput, PublishMachineContext } from '@/types'\nimport { BaseItem } from '@/Item/BaseItem'\nimport debug from 'debug'\nimport { getCorrectId } from '@/helpers'\n\nconst logger = debug('seedSdk:services:publish:actors:upload')\n\ntype UploadItem = {\n sourceFilePath: string\n fileSize: number\n filename: string\n seedLocalId?: string\n metadataLocalId?: string\n}\n\nexport const upload = fromCallback<\n EventObject,\n FromCallbackInput<PublishMachineContext>\n>(({ sendBack, input: { context } }) => {\n const { localId } = context\n\n const _upload = async () => {\n const item = await BaseItem.find({ seedLocalId: localId })\n\n if (!item) {\n logger('no item with localId', localId)\n return false\n }\n\n const editedProperties = await item.getEditedProperties()\n\n for (const propertyData of editedProperties) {\n if (propertyData.refSeedType === 'image') {\n // Check sha256 of local file against sha256 of remote files\n // If different, add this file to uploadItems\n }\n }\n\n const uploadItems = []\n\n for (const editedPropertyData of editedProperties) {\n const propertyName = editedPropertyData.propertyName\n const editedProperty = item.properties[propertyName]\n\n if (!editedProperty || !editedProperty.propertyDef) {\n continue\n }\n\n if (\n editedProperty.propertyDef.refValueType &&\n editedProperty.propertyDef.refValueType === '
|
|
1
|
+
{"version":3,"file":"upload.js","sources":["../../../../../../src/services/publish/actors/upload.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { FromCallbackInput, PublishMachineContext } from '@/types'\nimport { BaseItem } from '@/Item/BaseItem'\nimport debug from 'debug'\nimport { getCorrectId } from '@/helpers'\n\nconst logger = debug('seedSdk:services:publish:actors:upload')\n\ntype UploadItem = {\n sourceFilePath: string\n fileSize: number\n filename: string\n seedLocalId?: string\n metadataLocalId?: string\n}\n\nexport const upload = fromCallback<\n EventObject,\n FromCallbackInput<PublishMachineContext>\n>(({ sendBack, input: { context } }) => {\n const { localId } = context\n\n const _upload = async () => {\n const item = await BaseItem.find({ seedLocalId: localId })\n\n if (!item) {\n logger('no item with localId', localId)\n return false\n }\n\n const editedProperties = await item.getEditedProperties()\n\n for (const propertyData of editedProperties) {\n if (propertyData.refSeedType === 'image') {\n // Check sha256 of local file against sha256 of remote files\n // If different, add this file to uploadItems\n }\n }\n\n const uploadItems = []\n\n for (const editedPropertyData of editedProperties) {\n const propertyName = editedPropertyData.propertyName\n const editedProperty = item.properties[propertyName]\n\n if (!editedProperty || !editedProperty.propertyDef) {\n continue\n }\n\n if (\n editedProperty.propertyDef.refValueType &&\n editedProperty.propertyDef.refValueType === 'Image'\n ) {\n const context = editedProperty.getService().getSnapshot().context\n const imageSeedId = context.propertyValue\n const { localId, uid } = getCorrectId(imageSeedId)\n }\n\n if (\n editedProperty.propertyDef.storageType === 'ItemStorage' &&\n editedProperty.propertyDef.localStorageDir\n ) {\n }\n }\n\n if (uploadItems.length === 0) {\n return true\n }\n\n // const turbo = TurboFactory.unauthenticated()\n\n // turbo.uploadSignedDataItem()\n //\n // const { id, owner, dataCaches, fastFinalityIndexes } = await turbo.uploadFile(() => {\n // fileStreamFactory => () => fs.createReadStream(filePath),\n // fileSizeFactory => () => fileSize,\n // });\n return false\n }\n\n _upload().then((isValid) => {\n if (isValid) {\n sendBack({ type: 'uploadSuccess' })\n }\n })\n})\n"],"names":[],"mappings":";;;;;AAMA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WAAW,KAAK,aAAa;AACxD,gBAAA,cAAc,CAAC,WAAW,CAAC,eAAe,EAC1C;;AAIJ,QAAA,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE;AAC5B,YAAA,OAAO,IAAI;;;;;;;;;AAWb,QAAA,OAAO,KAAK;AACd,KAAC;AAED,IAAA,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,OAAO,KAAI;QACzB,IAAI,OAAO,EAAE;AACX,YAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;;AAEvC,KAAC,CAAC;AACJ,CAAC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { EventObject } from 'xstate';
|
|
2
|
-
import { FromCallbackInput } from '@/types/machines';
|
|
3
|
-
import { SaveValueToDbEvent } from '@/types/property';
|
|
4
|
-
export declare const saveImageSrc: import("xstate").CallbackActorLogic<EventObject, FromCallbackInput<any, SaveValueToDbEvent>, EventObject>;
|
|
5
|
-
//# sourceMappingURL=saveImageSrc.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"saveImageSrc.d.ts","sourceRoot":"","sources":["../../../../../../src/ItemProperty/service/actors/saveValueToDb/saveImageSrc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAgB,MAAM,QAAQ,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAGL,kBAAkB,EACnB,MAAM,kBAAkB,CAAA;AA+CzB,eAAO,MAAM,YAAY,2GA2LvB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"saveImageSrc.js","sources":["../../../../../../../src/ItemProperty/service/actors/saveValueToDb/saveImageSrc.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 saveImageSrc = 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 _saveImageSrc = 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 _saveImageSrc().then(() => {\n sendBack({ type: 'saveImageSrcSuccess' })\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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