@seedprotocol/sdk 0.3.7 → 0.3.9

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.
Files changed (97) hide show
  1. package/dist/addModel.js +4 -0
  2. package/dist/addModel.js.map +1 -1
  3. package/dist/main.js +11 -0
  4. package/dist/main.js.map +1 -1
  5. package/dist/src/ItemProperty/BaseItemProperty.d.ts +6 -6
  6. package/dist/src/ItemProperty/index.js +4 -0
  7. package/dist/src/ItemProperty/index.js.map +1 -0
  8. package/dist/src/ItemProperty/service/actors/hydrateFromDb.js +2 -2
  9. package/dist/src/ItemProperty/service/actors/hydrateFromDb.js.map +1 -1
  10. package/dist/src/ItemProperty/service/actors/resolveRelatedValue.d.ts.map +1 -1
  11. package/dist/src/ItemProperty/service/actors/resolveRelatedValue.js +4 -4
  12. package/dist/src/ItemProperty/service/actors/resolveRelatedValue.js.map +1 -1
  13. package/dist/src/ItemProperty/service/actors/saveValueToDb/analyzeInput.js +4 -4
  14. package/dist/src/ItemProperty/service/actors/saveValueToDb/analyzeInput.js.map +1 -1
  15. package/dist/src/ItemProperty/service/actors/saveValueToDb/index.d.ts +1 -1
  16. package/dist/src/ItemProperty/service/actors/saveValueToDb/index.d.ts.map +1 -1
  17. package/dist/src/ItemProperty/service/actors/saveValueToDb/saveImage.d.ts +5 -0
  18. package/dist/src/ItemProperty/service/actors/saveValueToDb/saveImage.d.ts.map +1 -0
  19. package/dist/src/ItemProperty/service/actors/saveValueToDb/{saveImageSrc.js → saveImage.js} +6 -6
  20. package/dist/src/ItemProperty/service/actors/saveValueToDb/saveImage.js.map +1 -0
  21. package/dist/src/ItemProperty/service/actors/saveValueToDb/saveRelation.js +2 -2
  22. package/dist/src/ItemProperty/service/actors/saveValueToDb/saveRelation.js.map +1 -1
  23. package/dist/src/ItemProperty/service/propertyMachine.d.ts +7 -7
  24. package/dist/src/ItemProperty/service/propertyMachine.js +6 -6
  25. package/dist/src/ItemProperty/service/propertyMachine.js.map +1 -1
  26. package/dist/src/browser/db/Db.d.ts.map +1 -1
  27. package/dist/src/browser/db/Db.js +35 -8
  28. package/dist/src/browser/db/Db.js.map +1 -1
  29. package/dist/src/browser/helpers/FileManager.d.ts +2 -0
  30. package/dist/src/browser/helpers/FileManager.d.ts.map +1 -1
  31. package/dist/src/browser/helpers/FileManager.js +20 -8
  32. package/dist/src/browser/helpers/FileManager.js.map +1 -1
  33. package/dist/src/browser/index.d.ts +0 -1
  34. package/dist/src/browser/index.d.ts.map +1 -1
  35. package/dist/src/browser/react/index.d.ts +2 -1
  36. package/dist/src/browser/react/index.d.ts.map +1 -1
  37. package/dist/src/browser/react/model.d.ts +7 -0
  38. package/dist/src/browser/react/model.d.ts.map +1 -0
  39. package/dist/src/browser/react/model.js +20 -0
  40. package/dist/src/browser/react/model.js.map +1 -0
  41. package/dist/src/browser/react/services.js +1 -1
  42. package/dist/src/browser/react/services.js.map +1 -1
  43. package/dist/src/browser/workers/FileDownloader.d.ts.map +1 -1
  44. package/dist/src/browser/workers/FileDownloader.js +3 -1
  45. package/dist/src/browser/workers/FileDownloader.js.map +1 -1
  46. package/dist/src/client/ClientManager.d.ts +21 -12
  47. package/dist/src/client/ClientManager.d.ts.map +1 -1
  48. package/dist/src/client/ClientManager.js +21 -0
  49. package/dist/src/client/ClientManager.js.map +1 -1
  50. package/dist/src/client/actors/saveAppState.d.ts.map +1 -1
  51. package/dist/src/client/actors/saveAppState.js +0 -1
  52. package/dist/src/client/actors/saveAppState.js.map +1 -1
  53. package/dist/src/db/read/getModels.d.ts +2 -0
  54. package/dist/src/db/read/getModels.d.ts.map +1 -0
  55. package/dist/src/events/files/download.d.ts.map +1 -1
  56. package/dist/src/events/files/download.js +0 -1
  57. package/dist/src/events/files/download.js.map +1 -1
  58. package/dist/src/events/files/index.d.ts.map +1 -1
  59. package/dist/src/events/files/index.js +0 -1
  60. package/dist/src/events/files/index.js.map +1 -1
  61. package/dist/src/events/services/allItems.d.ts.map +1 -1
  62. package/dist/src/events/services/allItems.js +0 -1
  63. package/dist/src/events/services/allItems.js.map +1 -1
  64. package/dist/src/helpers/FileManager/BaseFileManager.d.ts +2 -0
  65. package/dist/src/helpers/FileManager/BaseFileManager.d.ts.map +1 -1
  66. package/dist/src/helpers/FileManager/BaseFileManager.js +6 -0
  67. package/dist/src/helpers/FileManager/BaseFileManager.js.map +1 -1
  68. package/dist/src/helpers/constants.d.ts +1 -1
  69. package/dist/src/helpers/constants.js +1 -1
  70. package/dist/src/helpers/constants.js.map +1 -1
  71. package/dist/src/helpers/environment.js +1 -1
  72. package/dist/src/helpers/environment.js.map +1 -1
  73. package/dist/src/helpers/getSegmentedItemProperties.js +1 -1
  74. package/dist/src/helpers/getSegmentedItemProperties.js.map +1 -1
  75. package/dist/src/helpers/index.d.ts +1 -1
  76. package/dist/src/helpers/index.d.ts.map +1 -1
  77. package/dist/src/helpers/index.js +3 -3
  78. package/dist/src/helpers/index.js.map +1 -1
  79. package/dist/src/index.d.ts +8 -1
  80. package/dist/src/index.d.ts.map +1 -1
  81. package/dist/src/node/helpers/FileManager.d.ts +2 -0
  82. package/dist/src/node/helpers/FileManager.d.ts.map +1 -1
  83. package/dist/src/node/helpers/index.d.ts.map +1 -1
  84. package/dist/src/node/helpers/index.js +0 -1
  85. package/dist/src/node/helpers/index.js.map +1 -1
  86. package/dist/src/services/db/actors/migrate.js +1 -1
  87. package/dist/src/services/db/actors/migrate.js.map +1 -1
  88. package/dist/src/services/internal/helpers.js +3 -3
  89. package/dist/src/services/internal/helpers.js.map +1 -1
  90. package/dist/src/services/publish/actors/upload.js +1 -1
  91. package/dist/src/services/publish/actors/upload.js.map +1 -1
  92. package/dist/src/types/model.d.ts +2 -15
  93. package/dist/src/types/model.d.ts.map +1 -1
  94. package/package.json +7 -7
  95. package/dist/src/ItemProperty/service/actors/saveValueToDb/saveImageSrc.d.ts +0 -5
  96. package/dist/src/ItemProperty/service/actors/saveValueToDb/saveImageSrc.d.ts.map +0 -1
  97. package/dist/src/ItemProperty/service/actors/saveValueToDb/saveImageSrc.js.map +0 -1
package/dist/addModel.js CHANGED
@@ -72,6 +72,10 @@ const injectModel = (schemaContent, newModelCode) => {
72
72
  updatedSchema.slice(modelsClosingBracePos);
73
73
  return updatedSchema;
74
74
  };
75
+ if (fileContents.includes(`class ${jsonModel.name}`)) {
76
+ console.error(`Model with name ${jsonModel.name} already exists in the schema`);
77
+ process.exit(0);
78
+ }
75
79
  const newModelCode = generateModelCode({
76
80
  modelName: jsonModel.name,
77
81
  properties: jsonModel.properties,
@@ -1 +1 @@
1
- {"version":3,"file":"addModel.js","sources":["../../scripts/addModel.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport fs from 'fs';\nimport { createDrizzleSchemaFilesFromConfig, generateModelCode } from '../src/node/codegen/drizzle';\n\n// Parse command line arguments\nconst args = process.argv.slice(2);\nconst sourceSchemaFilePath = args[0];\nconst outputFilePath = args[1];\nconst jsonString = args[2];\n\nif (!sourceSchemaFilePath || !outputFilePath || !jsonString) {\n console.error('Usage: npx tsx bin/addModel.ts <source-schema-file-path> <output-file-path> <json-string>');\n process.exit(1);\n}\n\n// Read the contents of the file\nlet fileContents;\ntry {\n fileContents = fs.readFileSync(sourceSchemaFilePath, 'utf-8');\n} catch (error) {\n console.error(`Error reading file at ${sourceSchemaFilePath}:`, error);\n process.exit(1);\n}\n\n// Parse the JSON string\nlet jsonModel;\ntry {\n jsonModel = JSON.parse(jsonString);\n} catch (error) {\n console.error('Invalid JSON string:', error);\n process.exit(1);\n}\n\n/**\n * Simple function to inject a new model after the last model class and update the models object\n * @param {string} schemaContent - The content of the schema file\n * @param {string} newModelCode - The code for the new model to inject\n * @returns {string} The updated schema content\n */\nconst injectModel = (schemaContent: string, newModelCode: string) => {\n // Extract the model name from the new code\n const modelNameMatch = newModelCode.match(/class\\s+(\\w+)/);\n if (!modelNameMatch) {\n throw new Error(\"Could not extract model name from provided code\");\n }\n const modelName = modelNameMatch[1];\n\n // Find the 'const models' position\n const modelsPos = schemaContent.indexOf('const models');\n if (modelsPos === -1) {\n throw new Error(\"Could not find 'const models' in the schema\");\n }\n\n // Find the position of the last model class before 'const models'\n const lastClassPos = schemaContent.lastIndexOf('@Model', modelsPos);\n if (lastClassPos === -1) {\n throw new Error(\"Could not find any model declarations in the schema\");\n }\n\n // Find the end of the last class\n const classEndPos = schemaContent.indexOf('}', lastClassPos);\n if (classEndPos === -1) {\n throw new Error(\"Could not find closing brace of the last model class\");\n }\n\n // Find the position after the last class's closing brace\n const insertModelPos = schemaContent.indexOf('\\n', classEndPos) + 1;\n \n // Insert the new model\n let updatedSchema = \n schemaContent.slice(0, insertModelPos) + \n \"\\n\" + newModelCode + \"\\n\\n\" + \n schemaContent.slice(insertModelPos);\n \n // Find the closing brace of the models object\n const modelsClosingBracePos = updatedSchema.indexOf('}', updatedSchema.indexOf('const models'));\n \n // Add the new model to the models object\n updatedSchema = \n updatedSchema.slice(0, modelsClosingBracePos) + \n ` ${modelName},\\n` + \n updatedSchema.slice(modelsClosingBracePos);\n \n return updatedSchema;\n}\n\nconst newModelCode = generateModelCode({\n modelName: jsonModel.name,\n properties: jsonModel.properties,\n});\n\nconst updatedSchema = injectModel(fileContents, newModelCode);\n\n// Write the new table file\ntry {\n fs.writeFileSync(outputFilePath, updatedSchema, 'utf-8');\n console.log(`Wrote updated schema file to ${outputFilePath}`);\n} catch (error) {\n console.error('Error writing Drizzle table file:', error);\n process.exit(1);\n} \n"],"names":[],"mappings":";;;;AAKA;AACA,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AAClC,MAAM,oBAAoB,GAAG,IAAI,CAAC,CAAC,CAAC;AACpC,MAAM,cAAc,GAAG,IAAI,CAAC,CAAC,CAAC;AAC9B,MAAM,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC;AAE1B,IAAI,CAAC,oBAAoB,IAAI,CAAC,cAAc,IAAI,CAAC,UAAU,EAAE;AAC3D,IAAA,OAAO,CAAC,KAAK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":["../../scripts/addModel.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport fs from 'fs';\nimport { generateModelCode } from '../src/node/codegen/drizzle';\n\n// Parse command line arguments\nconst args = process.argv.slice(2);\nconst sourceSchemaFilePath = args[0];\nconst outputFilePath = args[1];\nconst jsonString = args[2];\n\nif (!sourceSchemaFilePath || !outputFilePath || !jsonString) {\n console.error('Usage: npx tsx bin/addModel.ts <source-schema-file-path> <output-file-path> <json-string>');\n process.exit(1);\n}\n\n// Read the contents of the file\nlet fileContents;\ntry {\n fileContents = fs.readFileSync(sourceSchemaFilePath, 'utf-8');\n} catch (error) {\n console.error(`Error reading file at ${sourceSchemaFilePath}:`, error);\n process.exit(1);\n}\n\n// Parse the JSON string\nlet jsonModel;\ntry {\n jsonModel = JSON.parse(jsonString);\n} catch (error) {\n console.error('Invalid JSON string:', error);\n process.exit(1);\n}\n\n/**\n * Simple function to inject a new model after the last model class and update the models object\n * @param {string} schemaContent - The content of the schema file\n * @param {string} newModelCode - The code for the new model to inject\n * @returns {string} The updated schema content\n */\nconst injectModel = (schemaContent: string, newModelCode: string) => {\n // Extract the model name from the new code\n const modelNameMatch = newModelCode.match(/class\\s+(\\w+)/);\n if (!modelNameMatch) {\n throw new Error(\"Could not extract model name from provided code\");\n }\n const modelName = modelNameMatch[1];\n\n // Find the 'const models' position\n const modelsPos = schemaContent.indexOf('const models');\n if (modelsPos === -1) {\n throw new Error(\"Could not find 'const models' in the schema\");\n }\n\n // Find the position of the last model class before 'const models'\n const lastClassPos = schemaContent.lastIndexOf('@Model', modelsPos);\n if (lastClassPos === -1) {\n throw new Error(\"Could not find any model declarations in the schema\");\n }\n\n // Find the end of the last class\n const classEndPos = schemaContent.indexOf('}', lastClassPos);\n if (classEndPos === -1) {\n throw new Error(\"Could not find closing brace of the last model class\");\n }\n\n // Find the position after the last class's closing brace\n const insertModelPos = schemaContent.indexOf('\\n', classEndPos) + 1;\n \n // Insert the new model\n let updatedSchema = \n schemaContent.slice(0, insertModelPos) + \n \"\\n\" + newModelCode + \"\\n\\n\" + \n schemaContent.slice(insertModelPos);\n \n // Find the closing brace of the models object\n const modelsClosingBracePos = updatedSchema.indexOf('}', updatedSchema.indexOf('const models'));\n \n // Add the new model to the models object\n updatedSchema = \n updatedSchema.slice(0, modelsClosingBracePos) + \n ` ${modelName},\\n` + \n updatedSchema.slice(modelsClosingBracePos);\n \n return updatedSchema;\n}\n\nif (fileContents.includes(`class ${jsonModel.name}`)) {\n console.error(`Model with name ${jsonModel.name} already exists in the schema`);\n process.exit(0);\n}\n\nconst newModelCode = generateModelCode({\n modelName: jsonModel.name,\n properties: jsonModel.properties,\n});\n\nconst updatedSchema = injectModel(fileContents, newModelCode);\n\n// Write the new table file\ntry {\n fs.writeFileSync(outputFilePath, updatedSchema, 'utf-8');\n console.log(`Wrote updated schema file to ${outputFilePath}`);\n} catch (error) {\n console.error('Error writing Drizzle table file:', error);\n process.exit(1);\n} \n"],"names":[],"mappings":";;;;AAKA;AACA,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AAClC,MAAM,oBAAoB,GAAG,IAAI,CAAC,CAAC,CAAC;AACpC,MAAM,cAAc,GAAG,IAAI,CAAC,CAAC,CAAC;AAC9B,MAAM,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC;AAE1B,IAAI,CAAC,oBAAoB,IAAI,CAAC,cAAc,IAAI,CAAC,UAAU,EAAE;AAC3D,IAAA,OAAO,CAAC,KAAK,CAAC,2FAA2F,CAAC;AAC1G,IAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AACjB;AAEA;AACA,IAAI,YAAY;AAChB,IAAI;IACF,YAAY,GAAG,EAAE,CAAC,YAAY,CAAC,oBAAoB,EAAE,OAAO,CAAC;AAC/D;AAAE,OAAO,KAAK,EAAE;IACd,OAAO,CAAC,KAAK,CAAC,CAAA,sBAAA,EAAyB,oBAAoB,CAAG,CAAA,CAAA,EAAE,KAAK,CAAC;AACt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{ Boolean, Date, Image, Json, List, Number, Property, Relation, Text } from './src/schema/property/index.js';
5
5
  export { Item } from './src/Item/index.js';
6
+ export { ItemProperty } from './src/ItemProperty/index.js';
6
7
  export { useCreateItem, useItem, useItems, usePublishItem } from './src/browser/react/item.js';
7
8
  export { useItemProperties, useItemProperty } from './src/browser/react/property.js';
8
9
  export { useGlobalServiceStatus, usePersistedSnapshots, useService, useServices } from './src/browser/react/services.js';
9
10
  import './src/browser/react/db.js';
10
11
  export { useDeleteItem } from './src/browser/react/trash.js';
12
+ export { useModels } from './src/browser/react/model.js';
13
+ export { FileManager as FileManagerBrowser } from './src/browser/helpers/FileManager.js';
14
+ export { Db as DbBrowser } from './src/browser/db/Db.js';
15
+ export { seeds } from './src/seedSchema/SeedSchema.js';
16
+ export { versions } from './src/seedSchema/VersionSchema.js';
17
+ export { metadata } from './src/seedSchema/MetadataSchema.js';
18
+ import './src/seedSchema/AppStateSchema.js';
19
+ export { models } from './src/seedSchema/ModelSchema.js';
20
+ import './src/seedSchema/ModelUidSchema.js';
21
+ export { getModel, getModelNames, getModels } from './src/stores/modelClass.js';
11
22
  export { getCorrectId } from './src/helpers/index.js';
12
23
  export { eventEmitter } from './src/eventBus.js';
13
24
  export { withSeed } from './src/node/webpack/index.js';
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"main.js","sources":["../../src/index.ts"],"sourcesContent":["import { enableMapSet } from 'immer'\n\nexport {\n Model,\n Property,\n Image,\n List,\n Text,\n Json,\n Relation,\n Boolean,\n Number,\n Date,\n} from './schema'\n\n// export { type IItem, type IItemProperty } from './interfaces'\nexport { Item } from './Item'\n// export { ItemProperty } from './ItemProperty'\n// export { Db } from './db/Db'\n\nexport {\n useItems,\n useItem,\n useItemProperties,\n useCreateItem,\n useItemProperty,\n useDeleteItem,\n useGlobalServiceStatus,\n usePublishItem,\n usePersistedSnapshots,\n useServices,\n useService,\n} from './browser/react'\n\n// export { getCorrectId, BaseArweaveClient, BaseEasClient, BaseFileManager, BaseQueryClient, } from './helpers'\nexport { getCorrectId, } from './helpers'\n\n// export { getGlobalService } from './services/global/globalMachine'\n\nexport {\n eventEmitter,\n} from './eventBus'\n\nenableMapSet()\n\nexport { withSeed } from './node/webpack'\n\n\nexport { client } from './client'\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AA2CA,YAAY,EAAE"}
1
+ {"version":3,"file":"main.js","sources":["../../src/index.ts"],"sourcesContent":["import { enableMapSet } from 'immer'\n\nexport {\n Model,\n Property,\n Image,\n List,\n Text,\n Json,\n Relation,\n Boolean,\n Number,\n Date,\n} from './schema'\n\nexport { Item } from './Item'\nexport { ItemProperty } from './ItemProperty'\n\nexport {\n useItems,\n useItem,\n useItemProperties,\n useCreateItem,\n useItemProperty,\n useDeleteItem,\n useGlobalServiceStatus,\n usePublishItem,\n usePersistedSnapshots,\n useServices,\n useService,\n useModels,\n} from './browser/react'\n\nexport {FileManager as FileManagerBrowser} from './browser/helpers/FileManager'\nexport {Db as DbBrowser} from './browser/db/Db'\n\nexport {models, versions, seeds, metadata, } from './seedSchema'\n\nexport {getModels, getModel, getModelNames,} from './stores/modelClass'\n\nexport { getCorrectId, } from './helpers'\n\nexport {\n eventEmitter,\n} from './eventBus'\n\nenableMapSet()\n\nexport { withSeed } from './node/webpack'\n\nexport type { PublishUpload } from './db/read/getPublishUploads'\n\n\nexport { client } from './client'\n\nexport * from './types'\n\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,YAAY,EAAE"}
@@ -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" | "savingImageSrc" | "savingRelation" | "savingItemStorage";
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 saveImageSrc: "savingImageSrc";
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 savingImageSrc: {
164
+ readonly savingImage: {
165
165
  readonly on: {
166
- readonly saveImageSrcSuccess: "doneSaving";
166
+ readonly saveImageSuccess: "doneSaving";
167
167
  };
168
168
  readonly invoke: {
169
- readonly src: "saveImageSrc";
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" | "savingImageSrc" | "savingRelation" | "savingItemStorage";
232
+ saving: "analyzingInput" | "doneSaving" | "savingImage" | "savingRelation" | "savingItemStorage";
233
233
  };
234
234
  get alias(): string | undefined;
235
235
  get value(): any;
@@ -0,0 +1,4 @@
1
+ let ItemProperty;
2
+
3
+ export { ItemProperty };
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../src/ItemProperty/index.ts"],"sourcesContent":["import { isBrowser } from '@/helpers/environment'\nimport { BaseItemProperty } from '@/ItemProperty/BaseItemProperty'\n\nlet ItemProperty: typeof BaseItemProperty | undefined\n\nexport const initItemProperty = async () => {\n\n if (isBrowser()) {\n ItemProperty = (await import('../browser/ItemProperty/ItemProperty')).ItemProperty\n }\n\n if (!isBrowser()) {\n ItemProperty = (await import('../node/ItemProperty/ItemProperty')).ItemProperty\n }\n}\n\nexport { ItemProperty }"],"names":[],"mappings":"AAGA,IAAI;;;;"}
@@ -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 === 'ImageSrc') {
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 === 'ImageSrc') {
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":[],"m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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,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,KA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AAoB,CAAC,WAAW,KAAK,aAAa,EAClD;YACA,MAAM,EAAE,IAAI,EAAE,GAAG,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 +1 @@
1
- {"version":3,"file":"resolveRelatedValue.d.ts","sourceRoot":"","sources":["../../../../../src/ItemProperty/service/actors/resolveRelatedValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAgB,MAAM,QAAQ,CAAA;AAGlD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAWpD,eAAO,MAAM,mBAAmB,oGA6L9B,CAAA"}
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 { convertTxIdToImageSrc } from '../../../helpers/index.js';
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 convertTxIdToImageSrc(storageTransactionId);
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 === 'ImageSrc') {
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 convertTxIdToImageSrc(storageId)
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;QACtC,IAAI,CAAC,aAAa,IAAI,CAAC,UAAU,IAAI,eAAe,EAAE;YACpD;;AAGF,QAAA,IAAI,WAAW;AAEf,QAAA,IAAI;AACF,YAAA,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC;;QACvC,OAAO,KAAK,EAAE;AACd,YAAA,MAAM,CAAC,CAAA,EAAG,YAAY,CAAA,4BAAA,CAA8B,CAAC;;QAGvD,IAAI,CAAC,WAAW,IAAI,mBAAmB,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE;YAC1D,MAAM,UAAU,GAAG,mBAAmB,CAAC,GAAG,CAAC,aAAa,CAAC;AACzD,YAAA,QAAQ,CAAC;AACP,gBAAA,IAAI,EAAE,eAAe;AACrB,gBAAA,WAAW,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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 savePropertiesToD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A;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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 !== 'ImageSrc' &&
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 === 'ImageSrc' ||
32
- propertyRecordSchema.dataType === 'ImageSrc') {
31
+ if (propertyRecordSchema.refValueType === 'Image' ||
32
+ propertyRecordSchema.dataType === 'Image') {
33
33
  sendBack({
34
- type: 'saveImageSrc',
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 !== 'ImageSrc' &&\n propertyRecordSchema.dataType === 'Relation'\n ) {\n sendBack({\n type: 'saveRelation',\n newValue,\n })\n return false\n }\n\n if (\n propertyRecordSchema.refValueType === 'ImageSrc' ||\n propertyRecordSchema.dataType === 'ImageSrc'\n ) {\n sendBack({\n type: 'saveImageSrc',\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,QAAQ;;AAG3B,IAAA,IAAI,aAAa,KAAK,QAAQ,EAAE;AAC9B,QAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,sBAAsB,EAAE,CAAC;QAC1C;;IAGF,IAAI,CAAC,oBAAoB,EAAE;AACzB,QAAA,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC;;AAGjD,IAAA,MAAM,aAAa,GA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Aa,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
+ {"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 _analy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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,5 +1,5 @@
1
1
  export * from './analyzeInput';
2
- export * from './saveImageSrc';
2
+ export * from './saveImage';
3
3
  export * from './saveRelation';
4
4
  export * from './saveItemStorage';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -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,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA"}
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 saveImageSrc = fromCallback(({ sendBack, input: { context, event } }) => {
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 _saveImageSrc = async () => {
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
- _saveImageSrc().then(() => {
173
- sendBack({ type: 'saveImageSrcSuccess' });
172
+ _saveImage().then(() => {
173
+ sendBack({ type: 'saveImageSuccess' });
174
174
  });
175
175
  });
176
176
 
177
- export { saveImageSrc };
178
- //# sourceMappingURL=saveImageSrc.js.map
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,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AA,WAAW,EAAE,cAAc;AAC3B,gBAAA,YAAY,EAAE,cAAc;gBAC5B,uBAAuB;AACvB,gBAAA,gBAAgB,EAAE,QAAQ;AAC1B,gBAAA,eAAe,EAAE,SAAS;AAC1B,gBAAA,WAAW,EAAE,SAAS;aACvB,EACD,oBAAoB,CACrB;AAED,YAAA,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO;;QAGhC,IAAI,OAAO,EAAE;AACX,YAAA,MAAM,uBAAuB,CAAC;AAC5B,gBAAA,OAAO,EAAE,OAAO;AAChB,gBAAA,YAAY,EAAE,eAAe;AAC7B,gBAAA,QAAQ,EAAE,mBAAmB;gBAC7B,WAAW;gBACX,cAAc;gBACd,SAAS;gBACT,SAAS;AACT,gBAAA,WAAW,EAAE,OAAO;gBACpB,uBAAuB;AACvB,gBAAA,gBAAgB,EAAE,QAAQ;AAC1B,gBAEA,eAAe,EAAE,SAElB,CAAA,CAAC;;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 === 'ImageSrc') {
25
+ if (propertyRecordSchema.dataType === 'Image') {
26
26
  sendBack({
27
- type: 'saveImageSrc',
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 === 'ImageSrc') {\n sendBack({\n type: 'saveImageSrc',\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,UAAU,EAAE;AAChD,YAAA,QAAQ,CAAC;AACP,gBAAA,IAAI,EAAE,cAAc;gBACpB,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;;;;"}
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
- saveImageSrc: {
21
- src: "saveImageSrc";
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" | "savingImageSrc" | "savingRelation" | "savingItemStorage";
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 saveImageSrc: "savingImageSrc";
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 savingImageSrc: {
176
+ readonly savingImage: {
177
177
  readonly on: {
178
- readonly saveImageSrcSuccess: "doneSaving";
178
+ readonly saveImageSuccess: "doneSaving";
179
179
  };
180
180
  readonly invoke: {
181
- readonly src: "saveImageSrc";
181
+ readonly src: "saveImage";
182
182
  readonly input: ({ context, event }: {
183
183
  context: any;
184
184
  event: any;