@seedprotocol/sdk 0.2.43 → 0.2.45
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/{ArweaveClient-BXD_aTsx.js → ArweaveClient-CoFomTCN.js} +2 -2
- package/dist/{ArweaveClient-CkcZD_QE.js.map → ArweaveClient-CoFomTCN.js.map} +1 -1
- package/dist/{ArweaveClient-CkcZD_QE.js → ArweaveClient-DQrXvrNN.js} +2 -2
- package/dist/{ArweaveClient-BXD_aTsx.js.map → ArweaveClient-DQrXvrNN.js.map} +1 -1
- package/dist/{Db-Bug4efsE.js → Db-BlgPVb_Z.js} +156 -166
- package/dist/Db-BlgPVb_Z.js.map +1 -0
- package/dist/{Db-B4XyOmGy.js → Db-gw_uZA_e.js} +34 -43
- package/dist/{Db-B4XyOmGy.js.map → Db-gw_uZA_e.js.map} +1 -1
- package/dist/{EasClient-BNwSwDTO.js → EasClient-CBu9ENAi.js} +2 -2
- package/dist/{EasClient-epqE9aWI.js.map → EasClient-CBu9ENAi.js.map} +1 -1
- package/dist/{EasClient-epqE9aWI.js → EasClient-sCbTHcO8.js} +2 -2
- package/dist/{EasClient-BNwSwDTO.js.map → EasClient-sCbTHcO8.js.map} +1 -1
- package/dist/FileManager-BNqJl6Bz.js +781 -0
- package/dist/FileManager-BNqJl6Bz.js.map +1 -0
- package/dist/FileManager-COOp89Mj.js +38 -0
- package/dist/FileManager-COOp89Mj.js.map +1 -0
- package/dist/{Item-vjJTzf1d.js → Item-BO38NUjz.js} +9 -12
- package/dist/{Item-vjJTzf1d.js.map → Item-BO38NUjz.js.map} +1 -1
- package/dist/{ItemProperty-DJpbernm.js → ItemProperty-8H7B05zy.js} +9 -12
- package/dist/{ItemProperty-DJpbernm.js.map → ItemProperty-8H7B05zy.js.map} +1 -1
- package/dist/{QueryClient-Ckl99FYC.js → QueryClient-BBaE-LKI.js} +2 -2
- package/dist/{QueryClient-Ckl99FYC.js.map → QueryClient-BBaE-LKI.js.map} +1 -1
- package/dist/{QueryClient-Do0C7Jnt.js → QueryClient-C-ZzUnWq.js} +2 -2
- package/dist/{QueryClient-Do0C7Jnt.js.map → QueryClient-C-ZzUnWq.js.map} +1 -1
- package/dist/bin.js +28 -27
- package/dist/bin.js.map +1 -1
- package/dist/{constants-BakHTrB9.js → constants-Dgv-tSO3.js} +76 -41
- package/dist/constants-Dgv-tSO3.js.map +1 -0
- package/dist/{index-DcPIAiHD.js → index-CsbUKGXp.js} +1330 -1571
- package/dist/index-CsbUKGXp.js.map +1 -0
- package/dist/{index-BWIn7kWN.js → index-Km3L1_LR.js} +9 -12
- package/dist/index-Km3L1_LR.js.map +1 -0
- package/dist/main.js +7 -10
- package/dist/main.js.map +1 -1
- package/dist/node/codegen/templates/index.njk +0 -4
- package/dist/{seed.schema.config-DGcg6TCS.js → seed.schema.config-Dn_1QbD7.js} +9 -11
- package/dist/seed.schema.config-Dn_1QbD7.js.map +1 -0
- package/dist/seedSchema/index.ts +0 -2
- package/dist/src/BaseFileManager.ts +31 -2
- package/dist/src/BaseItem.ts +4 -3
- package/dist/src/BaseItemProperty.ts +2 -2
- package/dist/src/FileDownloader.ts +63 -0
- package/dist/src/FileManager.ts +37 -6
- package/dist/src/ImageResizer.ts +84 -0
- package/dist/src/analyzeInput.ts +22 -2
- package/dist/src/configureFs.ts +18 -5
- package/dist/src/constants.ts +67 -60
- package/dist/src/createMetadata.ts +27 -2
- package/dist/src/dbMachine.ts +6 -0
- package/dist/src/download.ts +48 -203
- package/dist/src/filesDownload.ts +326 -0
- package/dist/src/getItem.ts +5 -0
- package/dist/src/getPublishPayload.ts +15 -8
- package/dist/src/getPublishUploads.ts +0 -27
- package/dist/src/helpers.ts +7 -15
- package/dist/src/hydrateFromDb.ts +4 -1
- package/dist/src/imageResize.ts +507 -0
- package/dist/src/internalMachine.ts +16 -0
- package/dist/src/migrate.ts +0 -24
- package/dist/src/model.ts +6 -5
- package/dist/src/saveImageSrc.ts +15 -1
- package/dist/src/syncDbWithEas.ts +0 -90
- package/dist/src/updateItemPropertyValue.ts +16 -3
- package/dist/src/validate.ts +6 -3
- package/dist/src/waitForDb.ts +18 -17
- package/dist/src/waitForFiles.ts +9 -8
- package/dist/types/src/Item/BaseItem.d.ts +2 -2
- package/dist/types/src/Item/BaseItem.d.ts.map +1 -1
- package/dist/types/src/ItemProperty/BaseItemProperty.d.ts +2 -2
- package/dist/types/src/ItemProperty/BaseItemProperty.d.ts.map +1 -1
- package/dist/types/src/ItemProperty/service/actors/hydrateFromDb.d.ts.map +1 -1
- package/dist/types/src/ItemProperty/service/actors/saveValueToDb/analyzeInput.d.ts.map +1 -1
- package/dist/types/src/ItemProperty/service/actors/saveValueToDb/saveImageSrc.d.ts.map +1 -1
- package/dist/types/src/browser/db/Db.d.ts.map +1 -1
- package/dist/types/src/browser/helpers/FileManager.d.ts +5 -1
- package/dist/types/src/browser/helpers/FileManager.d.ts.map +1 -1
- package/dist/types/src/browser/workers/FileDownloader.d.ts +8 -0
- package/dist/types/src/browser/workers/FileDownloader.d.ts.map +1 -0
- package/dist/types/src/browser/workers/ImageResizer.d.ts +9 -0
- package/dist/types/src/browser/workers/ImageResizer.d.ts.map +1 -0
- package/dist/types/src/browser/workers/content-hash.d.ts.map +1 -0
- package/dist/types/src/browser/workers/filesDownload.d.ts +3 -0
- package/dist/types/src/browser/workers/filesDownload.d.ts.map +1 -0
- package/dist/types/src/browser/workers/imageResize.d.ts +3 -0
- package/dist/types/src/browser/workers/imageResize.d.ts.map +1 -0
- package/dist/types/src/db/read/getItem.d.ts.map +1 -1
- package/dist/types/src/db/read/getPublishPayload.d.ts.map +1 -1
- package/dist/types/src/db/read/getPublishUploads.d.ts.map +1 -1
- package/dist/types/src/db/write/createMetadata.d.ts.map +1 -1
- package/dist/types/src/db/write/updateItemPropertyValue.d.ts +5 -1
- package/dist/types/src/db/write/updateItemPropertyValue.d.ts.map +1 -1
- package/dist/types/src/events/files/download.d.ts.map +1 -1
- package/dist/types/src/events/files/index.d.ts.map +1 -1
- package/dist/types/src/events/item/syncDbWithEas.d.ts.map +1 -1
- package/dist/types/src/helpers/FileManager/BaseFileManager.d.ts +6 -0
- package/dist/types/src/helpers/FileManager/BaseFileManager.d.ts.map +1 -1
- package/dist/types/src/helpers/constants.d.ts +7 -0
- package/dist/types/src/helpers/constants.d.ts.map +1 -1
- package/dist/types/src/helpers/files.d.ts +1 -1
- package/dist/types/src/helpers/files.d.ts.map +1 -1
- package/dist/types/src/node/helpers/FileManager.d.ts +5 -0
- package/dist/types/src/node/helpers/FileManager.d.ts.map +1 -1
- package/dist/types/src/schema/model/index.d.ts +2 -2
- package/dist/types/src/schema/model/index.d.ts.map +1 -1
- package/dist/types/src/seedSchema/index.d.ts +0 -2
- package/dist/types/src/seedSchema/index.d.ts.map +1 -1
- package/dist/types/src/services/allItems/actors/initialize.d.ts.map +1 -1
- package/dist/types/src/services/db/actors/migrate.d.ts.map +1 -1
- package/dist/types/src/services/db/actors/validate.d.ts.map +1 -1
- package/dist/types/src/services/db/dbMachine.d.ts +10 -0
- package/dist/types/src/services/db/dbMachine.d.ts.map +1 -1
- package/dist/types/src/services/internal/actors/configureFs.d.ts.map +1 -1
- package/dist/types/src/services/internal/actors/waitForFiles.d.ts +4 -0
- package/dist/types/src/services/internal/actors/waitForFiles.d.ts.map +1 -0
- package/dist/types/src/services/internal/constants.d.ts +2 -2
- package/dist/types/src/services/internal/constants.d.ts.map +1 -1
- package/dist/types/src/services/internal/helpers.d.ts.map +1 -1
- package/dist/types/src/services/internal/internalMachine.d.ts +10 -0
- package/dist/types/src/services/internal/internalMachine.d.ts.map +1 -1
- package/dist/types/src/types/fileManager.d.ts +15 -0
- package/dist/types/src/types/fileManager.d.ts.map +1 -0
- package/dist/types/src/types/model.d.ts +6 -5
- package/dist/types/src/types/model.d.ts.map +1 -1
- package/package.json +5 -3
- package/dist/Db-Bug4efsE.js.map +0 -1
- package/dist/FileManager-CXk83EW5.js +0 -16
- package/dist/FileManager-CXk83EW5.js.map +0 -1
- package/dist/FileManager-DXi-X7r5.js +0 -28
- package/dist/FileManager-DXi-X7r5.js.map +0 -1
- package/dist/constants-BakHTrB9.js.map +0 -1
- package/dist/content-hash.js +0 -27
- package/dist/content-hash.js.map +0 -1
- package/dist/index-BWIn7kWN.js.map +0 -1
- package/dist/index-DcPIAiHD.js.map +0 -1
- package/dist/seed.schema.config-DGcg6TCS.js.map +0 -1
- package/dist/types/__tests__/__mocks__/browser/project/schema.d.ts +0 -52
- package/dist/types/__tests__/__mocks__/browser/project/schema.d.ts.map +0 -1
- package/dist/types/__tests__/__mocks__/node/schema.d.ts +0 -52
- package/dist/types/__tests__/__mocks__/node/schema.d.ts.map +0 -1
- package/dist/types/__tests__/browser/db/drizzle.test.d.ts +0 -2
- package/dist/types/__tests__/browser/db/drizzle.test.d.ts.map +0 -1
- package/dist/types/__tests__/browser/property/propertyMachine.test.d.ts +0 -2
- package/dist/types/__tests__/browser/property/propertyMachine.test.d.ts.map +0 -1
- package/dist/types/__tests__/browser/react/index.test.d.ts +0 -2
- package/dist/types/__tests__/browser/react/index.test.d.ts.map +0 -1
- package/dist/types/__tests__/dist/exports.test.d.ts +0 -2
- package/dist/types/__tests__/dist/exports.test.d.ts.map +0 -1
- package/dist/types/__tests__/fs/index.test.d.ts +0 -2
- package/dist/types/__tests__/fs/index.test.d.ts.map +0 -1
- package/dist/types/__tests__/index.test.d.ts +0 -2
- package/dist/types/__tests__/index.test.d.ts.map +0 -1
- package/dist/types/__tests__/node/Item/Item.test.d.ts +0 -2
- package/dist/types/__tests__/node/Item/Item.test.d.ts.map +0 -1
- package/dist/types/__tests__/node/setup.d.ts +0 -2
- package/dist/types/__tests__/node/setup.d.ts.map +0 -1
- package/dist/types/__tests__/scripts/bin.test.d.ts +0 -2
- package/dist/types/__tests__/scripts/bin.test.d.ts.map +0 -1
- package/dist/types/__tests__/setup.d.ts +0 -2
- package/dist/types/__tests__/setup.d.ts.map +0 -1
- package/dist/types/src/workers/content-hash.d.ts.map +0 -1
- /package/dist/types/src/{workers → browser/workers}/content-hash.d.ts +0 -0
package/dist/src/constants.ts
CHANGED
|
@@ -1,72 +1,79 @@
|
|
|
1
|
+
const ENV = (typeof process !== 'undefined' && process.env)
|
|
2
|
+
? process.env
|
|
3
|
+
: (typeof window !== 'undefined' && (window as any).env)
|
|
4
|
+
? (window as any).env
|
|
5
|
+
: {};
|
|
6
|
+
|
|
7
|
+
|
|
1
8
|
const MACHINE_ID_SCOPE = '@seedSdk'
|
|
2
9
|
|
|
3
10
|
export enum MachineIds {
|
|
4
|
-
GLOBAL
|
|
5
|
-
INTERNAL
|
|
6
|
-
DB
|
|
7
|
-
EAS
|
|
8
|
-
ITEM
|
|
9
|
-
ALL_ITEMS
|
|
10
|
-
MODEL
|
|
11
|
+
GLOBAL = `${MACHINE_ID_SCOPE}/global`,
|
|
12
|
+
INTERNAL = `${MACHINE_ID_SCOPE}/internal`,
|
|
13
|
+
DB = `${MACHINE_ID_SCOPE}/db`,
|
|
14
|
+
EAS = `${MACHINE_ID_SCOPE}/eas`,
|
|
15
|
+
ITEM = `${MACHINE_ID_SCOPE}/item`,
|
|
16
|
+
ALL_ITEMS = `${MACHINE_ID_SCOPE}/allItems`,
|
|
17
|
+
MODEL = `${MACHINE_ID_SCOPE}/model`,
|
|
11
18
|
FILE_SYSTEM = `${MACHINE_ID_SCOPE}/fileSystem`,
|
|
12
19
|
}
|
|
13
20
|
|
|
14
21
|
const { INTERNAL, DB, GLOBAL, EAS, MODEL } = MachineIds
|
|
15
22
|
|
|
16
23
|
export enum GlobalState {
|
|
17
|
-
UNINITIALIZED
|
|
18
|
-
INITIALIZING
|
|
19
|
-
INITIALIZED
|
|
20
|
-
PUBLISHING_ITEM
|
|
24
|
+
UNINITIALIZED = 'uninitialized',
|
|
25
|
+
INITIALIZING = 'initializing',
|
|
26
|
+
INITIALIZED = 'initialized',
|
|
27
|
+
PUBLISHING_ITEM = 'publishingItem',
|
|
21
28
|
ADDING_MODELS_TO_DB = 'addingModelsToDb',
|
|
22
29
|
}
|
|
23
30
|
|
|
24
31
|
const {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} = GlobalState
|
|
32
|
+
UNINITIALIZED,
|
|
33
|
+
INITIALIZING,
|
|
34
|
+
INITIALIZED,
|
|
35
|
+
PUBLISHING_ITEM,
|
|
36
|
+
ADDING_MODELS_TO_DB,
|
|
37
|
+
} = GlobalState
|
|
31
38
|
|
|
32
39
|
export enum InternalState {
|
|
33
|
-
IDLE
|
|
34
|
-
INITIALIZING
|
|
40
|
+
IDLE = 'idle',
|
|
41
|
+
INITIALIZING = 'initializing',
|
|
35
42
|
VALIDATING_INPUT = 'validatingInput',
|
|
36
|
-
CONFIGURING_FS
|
|
37
|
-
LOADING_SEED_DB
|
|
38
|
-
SAVING_CONFIG
|
|
39
|
-
LOADING_APP_DB
|
|
40
|
-
LOADING_SDK_DB
|
|
43
|
+
CONFIGURING_FS = 'configuringFs',
|
|
44
|
+
LOADING_SEED_DB = 'loadingSeedDb',
|
|
45
|
+
SAVING_CONFIG = 'savingConfig',
|
|
46
|
+
LOADING_APP_DB = 'loadingAppDb',
|
|
47
|
+
LOADING_SDK_DB = 'loadingSdkDb',
|
|
41
48
|
}
|
|
42
49
|
|
|
43
50
|
const { VALIDATING_INPUT, CONFIGURING_FS, LOADING_SEED_DB, LOADING_APP_DB } =
|
|
44
|
-
|
|
51
|
+
InternalState
|
|
45
52
|
|
|
46
53
|
export enum DbState {
|
|
47
|
-
CHECKING_STATUS
|
|
54
|
+
CHECKING_STATUS = 'checkingStatus',
|
|
48
55
|
WAITING_FOR_FILES = 'waitingForFiles',
|
|
49
|
-
VALIDATING
|
|
50
|
-
CONNECTING_TO_DB
|
|
56
|
+
VALIDATING = 'validating',
|
|
57
|
+
CONNECTING_TO_DB = 'connectingToDb',
|
|
51
58
|
// FETCHING_MIGRATIONS = 'fetchingMigrations',
|
|
52
|
-
MIGRATING
|
|
59
|
+
MIGRATING = 'migrating',
|
|
53
60
|
}
|
|
54
61
|
|
|
55
62
|
const {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
} = DbState
|
|
63
|
+
CHECKING_STATUS,
|
|
64
|
+
VALIDATING,
|
|
65
|
+
CONNECTING_TO_DB,
|
|
66
|
+
WAITING_FOR_FILES,
|
|
67
|
+
MIGRATING,
|
|
68
|
+
} = DbState
|
|
62
69
|
|
|
63
70
|
export enum PublishMachineStates {
|
|
64
|
-
VALIDATING_ITEM_DATA
|
|
65
|
-
CREATING_PUBLISH_ATTEMPT
|
|
66
|
-
UPLOADING
|
|
71
|
+
VALIDATING_ITEM_DATA = 'validatingItemData',
|
|
72
|
+
CREATING_PUBLISH_ATTEMPT = 'creatingPublishAttempt',
|
|
73
|
+
UPLOADING = 'uploading',
|
|
67
74
|
PREPARING_PUBLISH_REQUEST_DATA = 'preparingPublishRequestData',
|
|
68
|
-
PUBLISHING
|
|
69
|
-
IDLE
|
|
75
|
+
PUBLISHING = 'publishing',
|
|
76
|
+
IDLE = 'idle',
|
|
70
77
|
}
|
|
71
78
|
|
|
72
79
|
export const INTERNAL_VALIDATING_INPUT_SUCCESS = `${INTERNAL}.${VALIDATING_INPUT}.success`
|
|
@@ -83,36 +90,36 @@ export const INTERNAL_LOADING_APP_DB_FAILURE = `${INTERNAL}.${LOADING_APP_DB}.fa
|
|
|
83
90
|
export const INTERNAL_SAVING_CONFIG_SUCCESS = `${INTERNAL}.savingConfig.success`
|
|
84
91
|
export const INTERNAL_SAVING_CONFIG_FAILURE = `${INTERNAL}.savingConfig.failure`
|
|
85
92
|
|
|
86
|
-
export const GLOBAL_GETTING_SEED_CLASS_SUCCESS
|
|
87
|
-
export const GLOBAL_INITIALIZING_SEND_CONFIG
|
|
88
|
-
export const GLOBAL_INITIALIZING_INTERNAL_SERVICE_READY
|
|
93
|
+
export const GLOBAL_GETTING_SEED_CLASS_SUCCESS = `${GLOBAL}.${PUBLISHING_ITEM}.success`
|
|
94
|
+
export const GLOBAL_INITIALIZING_SEND_CONFIG = `${GLOBAL}.${INITIALIZING}.sendConfig`
|
|
95
|
+
export const GLOBAL_INITIALIZING_INTERNAL_SERVICE_READY = `${GLOBAL}.${INITIALIZING}.internalServiceReady`
|
|
89
96
|
export const GLOBAL_INITIALIZING_CREATE_ALL_ITEMS_SERVICES = `${GLOBAL}.${INITIALIZING}.createAllItemsServices`
|
|
90
|
-
export const GLOBAL_ADDING_MODELS_TO_DB_SUCCESS
|
|
97
|
+
export const GLOBAL_ADDING_MODELS_TO_DB_SUCCESS = `${GLOBAL}.${ADDING_MODELS_TO_DB}.success`
|
|
91
98
|
|
|
92
|
-
export const DB_CHECK_STATUS_UPDATE_PATHS
|
|
93
|
-
export const DB_CHECK_STATUS_EXISTS
|
|
99
|
+
export const DB_CHECK_STATUS_UPDATE_PATHS = `${DB}.${CHECKING_STATUS}.updatePaths`
|
|
100
|
+
export const DB_CHECK_STATUS_EXISTS = `${DB}.${CHECKING_STATUS}.exists`
|
|
94
101
|
export const DB_CHECK_STATUS_DOES_NOT_EXIST = `${DB}.${CHECKING_STATUS}.doesNotExist`
|
|
95
|
-
export const DB_CHECK_STATUS_FAILURE
|
|
102
|
+
export const DB_CHECK_STATUS_FAILURE = `${DB}.${CHECKING_STATUS}.failure`
|
|
96
103
|
|
|
97
|
-
export const DB_VALIDATING_SUCCESS
|
|
98
|
-
export const DB_VALIDATING_WAIT
|
|
99
|
-
export const DB_MIGRATING_WAIT
|
|
100
|
-
export const DB_MIGRATING_SUCCESS
|
|
101
|
-
export const DB_CREATING_SUCCESS
|
|
104
|
+
export const DB_VALIDATING_SUCCESS = `${DB}.${VALIDATING}.success`
|
|
105
|
+
export const DB_VALIDATING_WAIT = `${DB}.${VALIDATING}.wait`
|
|
106
|
+
export const DB_MIGRATING_WAIT = `${DB}.${MIGRATING}.wait`
|
|
107
|
+
export const DB_MIGRATING_SUCCESS = `${DB}.${MIGRATING}.success`
|
|
108
|
+
export const DB_CREATING_SUCCESS = `${DB}.${CONNECTING_TO_DB}.success`
|
|
102
109
|
export const DB_WAITING_FOR_FILES_RECEIVED = `${DB}.${WAITING_FOR_FILES}.filesReceived`
|
|
103
|
-
export const DB_ON_SNAPSHOT
|
|
104
|
-
export const CHILD_SNAPSHOT
|
|
110
|
+
export const DB_ON_SNAPSHOT = `${DB}.onSnapshot`
|
|
111
|
+
export const CHILD_SNAPSHOT = 'childSnapshot'
|
|
105
112
|
|
|
106
113
|
export const INTERNAL_SERVICE_SNAPSHOT = 'internalServiceSnapshot'
|
|
107
114
|
|
|
108
|
-
export const DB_NAME_APP
|
|
115
|
+
export const DB_NAME_APP = 'app_db'
|
|
109
116
|
export const BROWSER_FS_TOP_DIR = 'app-files'
|
|
110
117
|
|
|
111
118
|
export const EAS_ENDPOINT =
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
119
|
+
ENV.NEXT_PUBLIC_EAS_ENDPOINT ||
|
|
120
|
+
ENV.EAS_ENDPOINT ||
|
|
121
|
+
'https://optimism-sepolia.easscan.org/graphql'
|
|
115
122
|
|
|
116
|
-
export const ARWEAVE_HOST
|
|
117
|
-
|
|
123
|
+
export const ARWEAVE_HOST =
|
|
124
|
+
ENV.NEXT_PUBLIC_ARWEAVE_HOST || 'arweave.net'
|
|
118
125
|
export const ARWEAVE_ENDPOINT = `https://${ARWEAVE_HOST}/graphql`
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { metadata, MetadataType } from '@/seedSchema'
|
|
2
|
-
import { generateId } from '@/helpers'
|
|
2
|
+
import { BaseEasClient, BaseQueryClient, generateId } from '@/helpers'
|
|
3
3
|
import { PropertyType } from '@/types'
|
|
4
4
|
import { BaseDb } from '../Db/BaseDb'
|
|
5
|
+
import { GET_SCHEMA_BY_NAME, GET_SCHEMAS } from '@/Item/queries'
|
|
6
|
+
import { INTERNAL_DATA_TYPES } from '@/helpers/constants'
|
|
5
7
|
|
|
6
8
|
type CreateMetadata = (
|
|
7
9
|
metadataValues: Partial<MetadataType>,
|
|
@@ -20,15 +22,38 @@ export const createMetadata: CreateMetadata = async (
|
|
|
20
22
|
metadataValues.modelType = metadataValues.modelName.toLowerCase()
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
const isItemStorage = propertyRecordSchema && propertyRecordSchema.storageType === 'ItemStorage'
|
|
26
|
+
|
|
23
27
|
if (
|
|
24
28
|
propertyRecordSchema &&
|
|
25
29
|
propertyRecordSchema.localStorageDir &&
|
|
26
|
-
|
|
30
|
+
isItemStorage
|
|
27
31
|
) {
|
|
28
32
|
metadataValues.refResolvedValue = `${metadataValues.seedUid || metadataValues.seedLocalId}${propertyRecordSchema.filenameSuffix}`
|
|
29
33
|
metadataValues.refValueType = 'file'
|
|
30
34
|
}
|
|
31
35
|
|
|
36
|
+
if (!isItemStorage && !metadataValues.schemaUid && propertyRecordSchema) {
|
|
37
|
+
const queryClient = BaseQueryClient.getQueryClient()
|
|
38
|
+
const easClient = BaseEasClient.getEasClient()
|
|
39
|
+
|
|
40
|
+
const easDataType = INTERNAL_DATA_TYPES[propertyRecordSchema.dataType].eas
|
|
41
|
+
|
|
42
|
+
const queryResult = await queryClient.fetchQuery({
|
|
43
|
+
queryKey: [`getSchemaByName${metadataValues.propertyName}`],
|
|
44
|
+
queryFn: async () =>
|
|
45
|
+
easClient.request(GET_SCHEMA_BY_NAME, {
|
|
46
|
+
where: {
|
|
47
|
+
schema: {
|
|
48
|
+
equals: `${easDataType} ${metadataValues.propertyName}`,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
}),
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
metadataValues.schemaUid = queryResult.data[0].schema
|
|
55
|
+
}
|
|
56
|
+
|
|
32
57
|
return appDb
|
|
33
58
|
.insert(metadata)
|
|
34
59
|
.values({
|
package/dist/src/dbMachine.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { checkStatus } from '@/services/db/actors/checkStatus'
|
|
|
17
17
|
import { connectToDb } from '@/services/db/actors/connectToDb'
|
|
18
18
|
import { validate } from '@/services/db/actors/validate'
|
|
19
19
|
import { migrate } from '@/services/db/actors/migrate'
|
|
20
|
+
import { waitForFiles } from './actors/waitForFiles'
|
|
20
21
|
|
|
21
22
|
const logger = debug('app:services:db:machine')
|
|
22
23
|
|
|
@@ -38,6 +39,7 @@ const dbMachine = setup({
|
|
|
38
39
|
validate,
|
|
39
40
|
connectToDb,
|
|
40
41
|
migrate,
|
|
42
|
+
waitForFiles,
|
|
41
43
|
},
|
|
42
44
|
}).createMachine({
|
|
43
45
|
id: MachineIds.DB,
|
|
@@ -146,6 +148,10 @@ const dbMachine = setup({
|
|
|
146
148
|
},
|
|
147
149
|
[DB_MIGRATING_SUCCESS]: 'ready',
|
|
148
150
|
},
|
|
151
|
+
invoke: {
|
|
152
|
+
src: 'waitForFiles',
|
|
153
|
+
input: ({ context }) => ({ context }),
|
|
154
|
+
},
|
|
149
155
|
},
|
|
150
156
|
[MIGRATING]: {
|
|
151
157
|
on: {
|
package/dist/src/download.ts
CHANGED
|
@@ -6,10 +6,7 @@ import { appState } from '@/seedSchema'
|
|
|
6
6
|
import { eq } from 'drizzle-orm'
|
|
7
7
|
import { getAddressesFromDb } from '@/helpers/db'
|
|
8
8
|
import {
|
|
9
|
-
|
|
10
|
-
getMimeType,
|
|
11
|
-
identifyString,
|
|
12
|
-
isBinary,
|
|
9
|
+
BaseFileManager,
|
|
13
10
|
} from '@/helpers'
|
|
14
11
|
import { GET_FILES_METADATA } from '@/schema/file/queries'
|
|
15
12
|
import debug from 'debug'
|
|
@@ -47,7 +44,9 @@ export const downloadAllFilesBinaryRequestHandler = async () => {
|
|
|
47
44
|
const globalService = getGlobalService()
|
|
48
45
|
const internalService = globalService.getSnapshot().context.internalService
|
|
49
46
|
if (internalService) {
|
|
50
|
-
await waitFor(internalService, (snapshot) =>
|
|
47
|
+
await waitFor(internalService, (snapshot) => {
|
|
48
|
+
return snapshot.value === 'ready'
|
|
49
|
+
})
|
|
51
50
|
addresses = await getAddressesFromDb()
|
|
52
51
|
}
|
|
53
52
|
}
|
|
@@ -102,37 +101,46 @@ export const downloadAllFilesBinaryRequestHandler = async () => {
|
|
|
102
101
|
return []
|
|
103
102
|
}
|
|
104
103
|
|
|
105
|
-
|
|
106
|
-
const json = JSON.parse(fileMetadata.decodedDataJson)
|
|
107
|
-
const transactionId = json[0].value.value
|
|
108
|
-
|
|
109
|
-
const excludedTransactionsQuery = await appDb
|
|
104
|
+
const excludedTransactionsQuery = await appDb
|
|
110
105
|
.select()
|
|
111
106
|
.from(appState)
|
|
112
107
|
.where(eq(appState.key, 'excludedTransactions'))
|
|
113
108
|
|
|
114
|
-
|
|
109
|
+
let excludedTransactions = new Set<string>()
|
|
115
110
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
111
|
+
if (excludedTransactionsQuery && excludedTransactionsQuery.length === 1) {
|
|
112
|
+
const valueString = excludedTransactionsQuery[0].value
|
|
113
|
+
if (valueString) {
|
|
114
|
+
const excludedTransactionsArray = JSON.parse(valueString)
|
|
115
|
+
excludedTransactions = new Set(excludedTransactionsArray)
|
|
122
116
|
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const transactionIds = []
|
|
123
120
|
|
|
121
|
+
for (const fileMetadata of filesMetadata) {
|
|
122
|
+
const json = JSON.parse(fileMetadata.decodedDataJson)
|
|
123
|
+
const transactionId = json[0].value.value
|
|
124
124
|
if (excludedTransactions.has(transactionId)) {
|
|
125
125
|
continue
|
|
126
126
|
}
|
|
127
|
+
transactionIds.push(transactionId)
|
|
128
|
+
}
|
|
127
129
|
|
|
128
|
-
|
|
130
|
+
const arweave = getArweave()
|
|
129
131
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
132
|
+
if (!arweave) {
|
|
133
|
+
console.warn(
|
|
134
|
+
'[fetchAll/actors] [fetchAllBinaryData] arweave not available',
|
|
135
|
+
)
|
|
136
|
+
return []
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const arweaveClient = BaseArweaveClient.getArweaveClient()
|
|
140
|
+
|
|
141
|
+
const transactionIdsToDownload = []
|
|
142
|
+
|
|
143
|
+
for (const transactionId of transactionIds) {
|
|
136
144
|
|
|
137
145
|
try {
|
|
138
146
|
const res = await fetch(
|
|
@@ -153,9 +161,7 @@ export const downloadAllFilesBinaryRequestHandler = async () => {
|
|
|
153
161
|
|
|
154
162
|
continue
|
|
155
163
|
}
|
|
156
|
-
|
|
157
|
-
const arweaveClient = BaseArweaveClient.getArweaveClient()
|
|
158
|
-
|
|
164
|
+
|
|
159
165
|
const { tags: tagsResult } = await queryClient.fetchQuery({
|
|
160
166
|
queryKey: ['getTransactionTags', transactionId],
|
|
161
167
|
queryFn: async () =>
|
|
@@ -182,186 +188,25 @@ export const downloadAllFilesBinaryRequestHandler = async () => {
|
|
|
182
188
|
}
|
|
183
189
|
}
|
|
184
190
|
|
|
185
|
-
|
|
186
|
-
queryKey: ['fetchTransaction', transactionId],
|
|
187
|
-
queryFn: async () => {
|
|
188
|
-
const response = await fetch(
|
|
189
|
-
`https://${ARWEAVE_HOST}/raw/${transactionId}`,
|
|
190
|
-
)
|
|
191
|
-
|
|
192
|
-
const arrayBuffer = await response.arrayBuffer()
|
|
193
|
-
if (isBinary(arrayBuffer)) {
|
|
194
|
-
return arrayBuffer
|
|
195
|
-
}
|
|
191
|
+
transactionIdsToDownload.push(transactionId)
|
|
196
192
|
|
|
197
|
-
|
|
198
|
-
const text = decoder.decode(arrayBuffer)
|
|
193
|
+
|
|
199
194
|
|
|
200
|
-
return text
|
|
201
|
-
},
|
|
202
|
-
networkMode: 'offlineFirst',
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
let dataString
|
|
206
|
-
let arrayBuffer
|
|
207
|
-
|
|
208
|
-
if (data instanceof ArrayBuffer) {
|
|
209
|
-
arrayBuffer = data
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if (typeof data === 'string') {
|
|
213
|
-
dataString = data
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// const dataString = await arweave.transactions.getData(transactionId, {
|
|
217
|
-
// decode: true,
|
|
218
|
-
// string: true,
|
|
219
|
-
// })
|
|
220
|
-
|
|
221
|
-
if (!dataString && !arrayBuffer) {
|
|
222
|
-
logger(
|
|
223
|
-
`[fetchAll/actors] [fetchAllBinaryData] transaction ${transactionId} data not found`,
|
|
224
|
-
)
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
if (dataString && dataString.startsWith('===FILE_SEPARATOR===')) {
|
|
228
|
-
const dataStringParts = dataString
|
|
229
|
-
.split('===FILE_SEPARATOR===')
|
|
230
|
-
.slice(1)
|
|
231
|
-
|
|
232
|
-
if (dataStringParts.length % 2 !== 0) {
|
|
233
|
-
throw new Error('Input array must have an even number of elements.')
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
for (let i = 0; i < dataStringParts.length; i += 2) {
|
|
237
|
-
const contentType = dataStringParts[i]
|
|
238
|
-
const content = dataStringParts[i + 1]
|
|
239
|
-
if (contentType === 'html') {
|
|
240
|
-
const fileName = `${transactionId}.html`
|
|
241
|
-
fs.writeFileSync(`/files/html/${fileName}`, content)
|
|
242
|
-
}
|
|
243
|
-
if (contentType === 'json') {
|
|
244
|
-
const fileName = `${transactionId}.json`
|
|
245
|
-
fs.writeFileSync(`/files/json/${fileName}`, content)
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
continue
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (!dataString && arrayBuffer) {
|
|
253
|
-
await fs.writeFileSync(
|
|
254
|
-
`/files/images/${transactionId}`,
|
|
255
|
-
new Uint8Array(arrayBuffer),
|
|
256
|
-
)
|
|
257
|
-
continue
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if (!dataString) {
|
|
261
|
-
continue
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
let contentType = identifyString(dataString)
|
|
265
|
-
if (
|
|
266
|
-
contentType !== 'json' &&
|
|
267
|
-
contentType !== 'base64' &&
|
|
268
|
-
contentType !== 'html'
|
|
269
|
-
) {
|
|
270
|
-
const possibleImageType = getDataTypeFromString(dataString)
|
|
271
|
-
if (!possibleImageType) {
|
|
272
|
-
logger(
|
|
273
|
-
`[fetchAll/actors] [fetchAllBinaryData] transaction ${transactionId} data not in expected format: ${possibleImageType}`,
|
|
274
|
-
)
|
|
275
|
-
continue
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
contentType = possibleImageType
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
if (contentType === 'url') {
|
|
282
|
-
const url = dataString as string
|
|
283
|
-
const response = await fetch(url)
|
|
284
|
-
if (!response.ok) {
|
|
285
|
-
throw new Error(`Failed to fetch image: ${response.statusText}`)
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// Get the image as a Blob
|
|
289
|
-
const blob = await response.blob()
|
|
290
|
-
const buffer = await blob.arrayBuffer()
|
|
291
|
-
const bufferUint8Array = new Uint8Array(buffer)
|
|
292
|
-
|
|
293
|
-
// Extract the file extension from the URL
|
|
294
|
-
const extensionMatch = url.match(/\.(jpg|jpeg|png|gif|bmp|webp|svg)$/i)
|
|
295
|
-
if (!extensionMatch) {
|
|
296
|
-
throw new Error(
|
|
297
|
-
'Unable to determine the file extension from the URL.',
|
|
298
|
-
)
|
|
299
|
-
}
|
|
300
|
-
const fileExtension = extensionMatch[0] // e.g., ".jpg"
|
|
301
|
-
|
|
302
|
-
// Set the file name (you can customize this)
|
|
303
|
-
// const fileNameFromUrl = `${transactionId}${fileExtension}`
|
|
304
|
-
|
|
305
|
-
await fs.promises.writeFile(
|
|
306
|
-
`/files/images/${transactionId}`,
|
|
307
|
-
bufferUint8Array,
|
|
308
|
-
{
|
|
309
|
-
encoding: 'binary',
|
|
310
|
-
},
|
|
311
|
-
)
|
|
312
|
-
|
|
313
|
-
continue
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
const mimeType = getMimeType(dataString as string)
|
|
317
|
-
let fileExtension = mimeType
|
|
318
|
-
|
|
319
|
-
if (fileExtension && fileExtension?.startsWith('image')) {
|
|
320
|
-
fileExtension = fileExtension.replace('image/', '')
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
let fileName = transactionId
|
|
324
|
-
|
|
325
|
-
if (contentType === 'base64') {
|
|
326
|
-
if (fileExtension) {
|
|
327
|
-
fileName += `.${fileExtension}`
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
// Remove the Base64 header if it exists (e.g., "data:image/png;base64,")
|
|
331
|
-
const base64Data = dataString.split(',').pop() || ''
|
|
332
|
-
|
|
333
|
-
// Decode the Base64 string to binary
|
|
334
|
-
const binaryString = atob(base64Data)
|
|
335
|
-
const length = binaryString.length
|
|
336
|
-
const binaryData = new Uint8Array(length)
|
|
337
|
-
|
|
338
|
-
for (let i = 0; i < length; i++) {
|
|
339
|
-
binaryData[i] = binaryString.charCodeAt(i)
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
await fs.promises.writeFile(`/files/images/${fileName}`, binaryData, {
|
|
343
|
-
encoding: 'binary',
|
|
344
|
-
})
|
|
345
|
-
|
|
346
|
-
// if (dataUint8Array && dataUint8Array instanceof Uint8Array) {
|
|
347
|
-
// await fs.promises.writeFile(
|
|
348
|
-
// `/files/images/${fileName}`,
|
|
349
|
-
// dataUint8Array,
|
|
350
|
-
// )
|
|
351
|
-
// }
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
if (contentType === 'html') {
|
|
355
|
-
fileName += '.html'
|
|
356
|
-
await fs.promises.writeFile(`/files/html/${fileName}`, dataString)
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
if (contentType === 'json') {
|
|
360
|
-
fileName += '.json'
|
|
361
|
-
await fs.promises.writeFile(`/files/json/${fileName}`, dataString)
|
|
362
|
-
}
|
|
363
195
|
} catch (error) {
|
|
364
196
|
logger(error)
|
|
365
197
|
}
|
|
366
198
|
}
|
|
199
|
+
|
|
200
|
+
console.log('[download] Calling downloadAllFiles with transactionIdsToDownload', transactionIdsToDownload)
|
|
201
|
+
|
|
202
|
+
await BaseFileManager.downloadAllFiles({
|
|
203
|
+
transactionIds: transactionIdsToDownload,
|
|
204
|
+
arweaveHost: ARWEAVE_HOST,
|
|
205
|
+
excludedTransactions,
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
await BaseFileManager.resizeAllImages({
|
|
209
|
+
width: 480,
|
|
210
|
+
height: 480,
|
|
211
|
+
})
|
|
367
212
|
}
|