@seedprotocol/sdk 0.2.51 → 0.2.52
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-D1TsTBoj.js → ArweaveClient-D5iJisYr.js} +2 -2
- package/dist/{ArweaveClient-DpdXUcVJ.js.map → ArweaveClient-D5iJisYr.js.map} +1 -1
- package/dist/{ArweaveClient-DpdXUcVJ.js → ArweaveClient-HEIIuOfB.js} +2 -2
- package/dist/{ArweaveClient-D1TsTBoj.js.map → ArweaveClient-HEIIuOfB.js.map} +1 -1
- package/dist/{Db-quJxmvHH.js → Db-D-BsZYlN.js} +3 -3
- package/dist/{Db-quJxmvHH.js.map → Db-D-BsZYlN.js.map} +1 -1
- package/dist/{Db-DMJ0v3gO.js → Db-Dpsbk_T7.js} +3 -3
- package/dist/{Db-DMJ0v3gO.js.map → Db-Dpsbk_T7.js.map} +1 -1
- package/dist/{EasClient-ClZDuT3o.js → EasClient-D3wKgt0o.js} +2 -2
- package/dist/{EasClient-DfnGY_2X.js.map → EasClient-D3wKgt0o.js.map} +1 -1
- package/dist/{EasClient-DfnGY_2X.js → EasClient-jqkT2ZBt.js} +2 -2
- package/dist/{EasClient-ClZDuT3o.js.map → EasClient-jqkT2ZBt.js.map} +1 -1
- package/dist/{FileManager-texI7UwL.js → FileManager-4mWYO3Mt.js} +3 -5
- package/dist/FileManager-4mWYO3Mt.js.map +1 -0
- package/dist/{Item-D4n439Ei.js → Item-CqWdJsyg.js} +3 -3
- package/dist/{Item-D4n439Ei.js.map → Item-CqWdJsyg.js.map} +1 -1
- package/dist/{ItemProperty-Be5ymRVT.js → ItemProperty-BpBW3IWx.js} +3 -3
- package/dist/{ItemProperty-Be5ymRVT.js.map → ItemProperty-BpBW3IWx.js.map} +1 -1
- package/dist/{QueryClient-B1HkAaJo.js → QueryClient-CBOP3OoU.js} +2 -2
- package/dist/{QueryClient-B1HkAaJo.js.map → QueryClient-CBOP3OoU.js.map} +1 -1
- package/dist/{QueryClient-BPoc9eBn.js → QueryClient-bKb3SB0W.js} +2 -2
- package/dist/{QueryClient-BPoc9eBn.js.map → QueryClient-bKb3SB0W.js.map} +1 -1
- package/dist/bin.js +5 -5
- package/dist/{constants-5PxfAeqj.js → constants-CIDbABDz.js} +2 -2
- package/dist/{constants-5PxfAeqj.js.map → constants-CIDbABDz.js.map} +1 -1
- package/dist/{index-BeKRizLf.js → index-BRxO1tLl.js} +257 -145
- package/dist/index-BRxO1tLl.js.map +1 -0
- package/dist/{index-BLla2o05.js → index-d8Qsot6w.js} +3 -3
- package/dist/index-d8Qsot6w.js.map +1 -0
- package/dist/main.js +2 -2
- package/dist/package.json +189 -0
- package/dist/{seed.schema.config-CMpV_hyS.js → seed.schema.config-CPRn6KVL.js} +3 -3
- package/dist/{seed.schema.config-CMpV_hyS.js.map → seed.schema.config-CPRn6KVL.js.map} +1 -1
- package/dist/types/src/client/BaseClientManager.d.ts +7 -0
- package/dist/types/src/client/BaseClientManager.d.ts.map +1 -0
- package/dist/types/src/client/actions/setAddresses.d.ts +2 -0
- package/dist/types/src/client/actions/setAddresses.d.ts.map +1 -0
- package/dist/types/src/client/actors/initialize.d.ts +4 -0
- package/dist/types/src/client/actors/initialize.d.ts.map +1 -0
- package/dist/types/src/client/actors/saveAppState.d.ts +5 -0
- package/dist/types/src/client/actors/saveAppState.d.ts.map +1 -0
- package/dist/types/src/client/clientManagerMachine.d.ts +19 -0
- package/dist/types/src/client/clientManagerMachine.d.ts.map +1 -0
- package/dist/types/src/client/index.d.ts +41 -0
- package/dist/types/src/client/index.d.ts.map +1 -0
- package/dist/types/src/client.d.ts.map +1 -1
- package/dist/types/src/node/helpers/FileManager.d.ts.map +1 -1
- package/dist/types/src/services/internal/actors/validateInput.d.ts.map +1 -1
- package/dist/types/src/types/machines.d.ts +5 -0
- package/dist/types/src/types/machines.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/FileManager-texI7UwL.js.map +0 -1
- package/dist/index-BLla2o05.js.map +0 -1
- package/dist/index-BeKRizLf.js.map +0 -1
- package/dist/src/AppStateSchema.ts +0 -10
- package/dist/src/ArweaveClient.ts +0 -13
- package/dist/src/Attestation.ts +0 -21
- package/dist/src/BaseArweaveClient.ts +0 -13
- package/dist/src/BaseDb.ts +0 -35
- package/dist/src/BaseEasClient.ts +0 -13
- package/dist/src/BaseFileManager.ts +0 -56
- package/dist/src/BaseItem.ts +0 -413
- package/dist/src/BaseItemProperty.ts +0 -416
- package/dist/src/BaseQueryClient.ts +0 -13
- package/dist/src/ConfigSchema.ts +0 -15
- package/dist/src/Db.ts +0 -78
- package/dist/src/EasClient.ts +0 -13
- package/dist/src/FileDownloader.ts +0 -63
- package/dist/src/FileManager.ts +0 -57
- package/dist/src/IDb.ts +0 -7
- package/dist/src/IEasClient.ts +0 -2
- package/dist/src/IItem.ts +0 -26
- package/dist/src/IItemProperty.ts +0 -28
- package/dist/src/IQueryClient.ts +0 -4
- package/dist/src/ImageResizer.ts +0 -81
- package/dist/src/Item.ts +0 -12
- package/dist/src/ItemProperty.ts +0 -9
- package/dist/src/MetadataSchema.ts +0 -28
- package/dist/src/ModelSchema.ts +0 -46
- package/dist/src/ModelUidSchema.ts +0 -16
- package/dist/src/PropertyUidSchema.ts +0 -16
- package/dist/src/QueryClient.ts +0 -22
- package/dist/src/Schema.ts +0 -17
- package/dist/src/SeedProtocolSdk.d.ts +0 -19
- package/dist/src/SeedSchema.ts +0 -29
- package/dist/src/VersionSchema.ts +0 -16
- package/dist/src/actors.ts +0 -295
- package/dist/src/addModelsToDb.ts +0 -152
- package/dist/src/allItems.ts +0 -31
- package/dist/src/analyzeInput.ts +0 -144
- package/dist/src/browser.app.db.config.ts +0 -27
- package/dist/src/browser.ts +0 -30
- package/dist/src/checkStatus.ts +0 -50
- package/dist/src/client.ts +0 -148
- package/dist/src/configureFs.ts +0 -94
- package/dist/src/connectToDb.ts +0 -41
- package/dist/src/connectionManager.ts +0 -67
- package/dist/src/constants.ts +0 -125
- package/dist/src/content-hash.ts +0 -30
- package/dist/src/create.ts +0 -39
- package/dist/src/createMetadata.ts +0 -77
- package/dist/src/createNewItem.ts +0 -61
- package/dist/src/createPublishAttempt.ts +0 -16
- package/dist/src/createSeed.ts +0 -31
- package/dist/src/createSeeds.ts +0 -24
- package/dist/src/createVersion.ts +0 -33
- package/dist/src/dbMachine.ts +0 -182
- package/dist/src/deleteItem.ts +0 -19
- package/dist/src/download.ts +0 -202
- package/dist/src/drizzle.ts +0 -78
- package/dist/src/eas.ts +0 -40
- package/dist/src/environment.ts +0 -35
- package/dist/src/eventBus.ts +0 -5
- package/dist/src/events.ts +0 -14
- package/dist/src/fetchDataFromEas.ts +0 -94
- package/dist/src/fetchDbData.ts +0 -19
- package/dist/src/fetchRelatedItems.ts +0 -184
- package/dist/src/fetchSeeds.ts +0 -52
- package/dist/src/fetchVersions.ts +0 -49
- package/dist/src/files.ts +0 -81
- package/dist/src/filesDownload.ts +0 -326
- package/dist/src/fragment-masking.ts +0 -87
- package/dist/src/getExistingItem.ts +0 -60
- package/dist/src/getItem.ts +0 -32
- package/dist/src/getItemData.ts +0 -99
- package/dist/src/getItemProperties.ts +0 -56
- package/dist/src/getItemProperty.ts +0 -34
- package/dist/src/getItems.ts +0 -70
- package/dist/src/getMetadata.ts +0 -40
- package/dist/src/getModelSchemas.ts +0 -89
- package/dist/src/getPropertyData.ts +0 -50
- package/dist/src/getPublishPayload.ts +0 -355
- package/dist/src/getPublishUploads.ts +0 -207
- package/dist/src/getRelationValueData.ts +0 -27
- package/dist/src/getSchemaForItemProperty.ts +0 -68
- package/dist/src/getSchemaForModel.ts +0 -42
- package/dist/src/getSchemaUidForModel.ts +0 -32
- package/dist/src/getSeedData.ts +0 -34
- package/dist/src/getSegmentedItemProperties.ts +0 -65
- package/dist/src/getStorageTransactionIdForSeedUid.ts +0 -38
- package/dist/src/getVersionData.ts +0 -46
- package/dist/src/getVersionsForVersionUids.ts +0 -39
- package/dist/src/globalMachine.ts +0 -280
- package/dist/src/gql.ts +0 -118
- package/dist/src/graphql.ts +0 -3209
- package/dist/src/helpers.ts +0 -273
- package/dist/src/hydrateExistingItem.ts +0 -137
- package/dist/src/hydrateFromDb.ts +0 -270
- package/dist/src/hydrateNewItem.ts +0 -34
- package/dist/src/imageResize.ts +0 -507
- package/dist/src/index.d.ts +0 -5
- package/dist/src/index.ts +0 -4
- package/dist/src/initialize.ts +0 -124
- package/dist/src/internalMachine.ts +0 -238
- package/dist/src/itemMachineAll.ts +0 -157
- package/dist/src/itemMachineSingle.ts +0 -158
- package/dist/src/loadAppDb.ts +0 -47
- package/dist/src/machines.ts +0 -60
- package/dist/src/metadataLatest.ts +0 -34
- package/dist/src/migrate.ts +0 -53
- package/dist/src/model.ts +0 -72
- package/dist/src/modelClass.ts +0 -19
- package/dist/src/node.app.db.config.ts +0 -41
- package/dist/src/prepareDb.ts +0 -29
- package/dist/src/preparePublishRequestData.ts +0 -81
- package/dist/src/processItems.ts +0 -74
- package/dist/src/property.ts +0 -156
- package/dist/src/propertyMachine.ts +0 -202
- package/dist/src/publish.ts +0 -28
- package/dist/src/publishMachine.ts +0 -77
- package/dist/src/queries.ts +0 -13
- package/dist/src/recoverDeletedItem.ts +0 -14
- package/dist/src/reload.ts +0 -33
- package/dist/src/request.ts +0 -45
- package/dist/src/requestAll.ts +0 -157
- package/dist/src/resolveRelatedValue.ts +0 -367
- package/dist/src/resolveRemoteStorage.ts +0 -88
- package/dist/src/saveAppState.ts +0 -19
- package/dist/src/saveConfig.ts +0 -88
- package/dist/src/saveDataToDb.ts +0 -145
- package/dist/src/saveImageSrc.ts +0 -242
- package/dist/src/saveItemStorage.ts +0 -156
- package/dist/src/saveMetadata.ts +0 -18
- package/dist/src/savePublishService.ts +0 -30
- package/dist/src/saveRelation.ts +0 -112
- package/dist/src/seed.schema.config.ts +0 -25
- package/dist/src/seed.ts +0 -10
- package/dist/src/seedProtocol.ts +0 -17
- package/dist/src/services.ts +0 -365
- package/dist/src/sqlWasmClient.ts +0 -88
- package/dist/src/syncDbWithEas.ts +0 -628
- package/dist/src/trash.ts +0 -29
- package/dist/src/ts-to-proto.ts +0 -101
- package/dist/src/types.ts +0 -12
- package/dist/src/updateItemPropertyValue.ts +0 -243
- package/dist/src/updateMachineContext.ts +0 -21
- package/dist/src/updateMetadata.ts +0 -59
- package/dist/src/upload.ts +0 -86
- package/dist/src/validate.ts +0 -45
- package/dist/src/validateInput.ts +0 -47
- package/dist/src/validateItemData.ts +0 -20
- package/dist/src/versionData.ts +0 -24
- package/dist/src/waitForDb.ts +0 -25
- package/dist/src/waitForFiles.ts +0 -34
- package/dist/src/wasm.d.ts +0 -8300
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import { assign, setup } from 'xstate'
|
|
2
|
-
import { createBrowserInspector } from '@statelyai/inspect'
|
|
3
|
-
import {
|
|
4
|
-
DB_NAME_APP,
|
|
5
|
-
INTERNAL_CONFIGURING_FS_SUCCESS,
|
|
6
|
-
INTERNAL_LOADING_APP_DB_SUCCESS,
|
|
7
|
-
INTERNAL_SAVING_CONFIG_SUCCESS,
|
|
8
|
-
INTERNAL_VALIDATING_INPUT_SUCCESS,
|
|
9
|
-
InternalState,
|
|
10
|
-
MachineIds,
|
|
11
|
-
} from './constants'
|
|
12
|
-
import { dbMachine } from '@/services/db/dbMachine'
|
|
13
|
-
import debug from 'debug'
|
|
14
|
-
import { validateInput } from '@/services/internal/actors/validateInput'
|
|
15
|
-
import { prepareDb } from '@/services/internal/actors/prepareDb'
|
|
16
|
-
import { configureFs } from '@/services/internal/actors/configureFs'
|
|
17
|
-
import { saveConfig } from '@/services/internal/actors/saveConfig'
|
|
18
|
-
import { loadAppDb } from '@/services/internal/actors/loadAppDb'
|
|
19
|
-
import { InternalMachineContext } from '@/types'
|
|
20
|
-
import { waitForFiles } from './actors/waitForFiles'
|
|
21
|
-
|
|
22
|
-
const logger = debug('app:services:internal:machine')
|
|
23
|
-
|
|
24
|
-
const { inspect } = createBrowserInspector({
|
|
25
|
-
autoStart: false,
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
const {
|
|
29
|
-
IDLE,
|
|
30
|
-
VALIDATING_INPUT,
|
|
31
|
-
SAVING_CONFIG,
|
|
32
|
-
CONFIGURING_FS,
|
|
33
|
-
LOADING_APP_DB,
|
|
34
|
-
} = InternalState
|
|
35
|
-
|
|
36
|
-
// Create the state machine
|
|
37
|
-
export const internalMachine = setup({
|
|
38
|
-
types: {
|
|
39
|
-
context: {} as Partial<InternalMachineContext>,
|
|
40
|
-
input: {} as Partial<InternalMachineContext> | undefined,
|
|
41
|
-
},
|
|
42
|
-
actors: {
|
|
43
|
-
prepareDb,
|
|
44
|
-
validateInput,
|
|
45
|
-
waitForFiles,
|
|
46
|
-
configureFs,
|
|
47
|
-
loadAppDb,
|
|
48
|
-
saveConfig,
|
|
49
|
-
},
|
|
50
|
-
}).createMachine({
|
|
51
|
-
id: MachineIds.INTERNAL,
|
|
52
|
-
initial: IDLE,
|
|
53
|
-
context: ({ input }) => {
|
|
54
|
-
return {
|
|
55
|
-
...input,
|
|
56
|
-
error: undefined,
|
|
57
|
-
hasFiles: false,
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
states: {
|
|
61
|
-
[IDLE]: {
|
|
62
|
-
on: {
|
|
63
|
-
reValidate: VALIDATING_INPUT,
|
|
64
|
-
init: {
|
|
65
|
-
target: VALIDATING_INPUT,
|
|
66
|
-
actions: [
|
|
67
|
-
assign({
|
|
68
|
-
appDbService: ({ spawn }) =>
|
|
69
|
-
spawn(dbMachine, {
|
|
70
|
-
input: {
|
|
71
|
-
dbName: DB_NAME_APP,
|
|
72
|
-
},
|
|
73
|
-
}),
|
|
74
|
-
}),
|
|
75
|
-
],
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
meta: {
|
|
79
|
-
displayText: 'Waiting for something to happen ...',
|
|
80
|
-
percentComplete: 0,
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
[VALIDATING_INPUT]: {
|
|
84
|
-
on: {
|
|
85
|
-
[INTERNAL_VALIDATING_INPUT_SUCCESS]: {
|
|
86
|
-
target: 'preparingDb',
|
|
87
|
-
actions: assign({
|
|
88
|
-
endpoints: ({ event }) => event.endpoints,
|
|
89
|
-
addresses: ({ event }) => event.addresses,
|
|
90
|
-
filesDir: ({ event }) => event.filesDir,
|
|
91
|
-
arweaveDomain: ({ event }) => event.arweaveDomain,
|
|
92
|
-
}),
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
invoke: {
|
|
96
|
-
src: 'validateInput',
|
|
97
|
-
input: ({ context, event }) => ({ context, event }),
|
|
98
|
-
},
|
|
99
|
-
meta: {
|
|
100
|
-
displayText: 'Validating input',
|
|
101
|
-
percentComplete: 20,
|
|
102
|
-
},
|
|
103
|
-
tags: ['loading'],
|
|
104
|
-
},
|
|
105
|
-
preparingDb: {
|
|
106
|
-
on: {
|
|
107
|
-
prepareDbSuccess: {
|
|
108
|
-
target: CONFIGURING_FS,
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
invoke: {
|
|
112
|
-
src: 'prepareDb',
|
|
113
|
-
input: ({ context, event }) => ({ context, event }),
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
waitingForFiles: {
|
|
117
|
-
on: {
|
|
118
|
-
filesReceived: {
|
|
119
|
-
target: LOADING_APP_DB,
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
invoke: {
|
|
123
|
-
src: 'waitForFiles',
|
|
124
|
-
input: ({ context, event }) => ({ context, event }),
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
[CONFIGURING_FS]: {
|
|
128
|
-
on: {
|
|
129
|
-
[INTERNAL_CONFIGURING_FS_SUCCESS]: {
|
|
130
|
-
target: LOADING_APP_DB,
|
|
131
|
-
actions: assign({ hasFiles: true }),
|
|
132
|
-
},
|
|
133
|
-
shouldWaitForFiles: {
|
|
134
|
-
target: 'waitingForFiles',
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
invoke: {
|
|
138
|
-
src: 'configureFs',
|
|
139
|
-
input: ({ context, event }) => ({ context, event }),
|
|
140
|
-
},
|
|
141
|
-
meta: {
|
|
142
|
-
displayText: 'Downloading app files',
|
|
143
|
-
percentComplete: 30,
|
|
144
|
-
},
|
|
145
|
-
tags: ['loading'],
|
|
146
|
-
},
|
|
147
|
-
[LOADING_APP_DB]: {
|
|
148
|
-
on: {
|
|
149
|
-
[INTERNAL_LOADING_APP_DB_SUCCESS]: {
|
|
150
|
-
target: SAVING_CONFIG,
|
|
151
|
-
actions: () => {
|
|
152
|
-
logger('[sdk] [internal/index] App DB loaded!')
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
invoke: {
|
|
157
|
-
src: 'loadAppDb',
|
|
158
|
-
input: ({ context, event }) => ({ context, event }),
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
// Save developer's config to DB
|
|
162
|
-
[SAVING_CONFIG]: {
|
|
163
|
-
on: {
|
|
164
|
-
[INTERNAL_SAVING_CONFIG_SUCCESS]: 'ready',
|
|
165
|
-
},
|
|
166
|
-
invoke: {
|
|
167
|
-
src: 'saveConfig',
|
|
168
|
-
input: ({ context, event }) => ({ context, event }),
|
|
169
|
-
},
|
|
170
|
-
meta: {
|
|
171
|
-
displayText: 'Saving configuration',
|
|
172
|
-
percentComplete: 80,
|
|
173
|
-
},
|
|
174
|
-
tags: ['loading'],
|
|
175
|
-
},
|
|
176
|
-
ready: {
|
|
177
|
-
entry: () => {
|
|
178
|
-
logger('[sdk] [internal/index] Ready!')
|
|
179
|
-
},
|
|
180
|
-
meta: {
|
|
181
|
-
displayText: "Crossing the t's ...",
|
|
182
|
-
percentComplete: 90,
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
error: {
|
|
186
|
-
on: {
|
|
187
|
-
retry: {
|
|
188
|
-
target: CONFIGURING_FS,
|
|
189
|
-
actions: assign({ error: undefined }),
|
|
190
|
-
},
|
|
191
|
-
},
|
|
192
|
-
entry: () => {
|
|
193
|
-
logger('[sdk] [internal/index] Error!')
|
|
194
|
-
},
|
|
195
|
-
meta: {
|
|
196
|
-
displayText: 'Whoops! Something went wrong.',
|
|
197
|
-
percentComplete: null,
|
|
198
|
-
},
|
|
199
|
-
tags: ['error'],
|
|
200
|
-
},
|
|
201
|
-
},
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
// const internalService = createActor(internalMachine, {
|
|
205
|
-
// input: {},
|
|
206
|
-
// inspect: (inspEvent) => {
|
|
207
|
-
// if (inspEvent.type === '@xstate.snapshot') {
|
|
208
|
-
// if (
|
|
209
|
-
// inspEvent.event &&
|
|
210
|
-
// inspEvent.event.snapshot &&
|
|
211
|
-
// inspEvent.event.snapshot.value
|
|
212
|
-
// ) {
|
|
213
|
-
// logger(
|
|
214
|
-
// `[internalService] ${inspEvent.event.snapshot.value}`,
|
|
215
|
-
// inspEvent,
|
|
216
|
-
// )
|
|
217
|
-
// return
|
|
218
|
-
// }
|
|
219
|
-
//
|
|
220
|
-
// if (inspEvent.snapshot && inspEvent.snapshot.value) {
|
|
221
|
-
// logger(`[internalService] ${inspEvent.snapshot.value}`, inspEvent)
|
|
222
|
-
// return
|
|
223
|
-
// }
|
|
224
|
-
//
|
|
225
|
-
// // logger(`[internalService] Uncaught event`, inspEvent)
|
|
226
|
-
// }
|
|
227
|
-
// },
|
|
228
|
-
// })
|
|
229
|
-
|
|
230
|
-
// internalService.subscribe((snapshot) => {
|
|
231
|
-
// globalService.send({ type: INTERNAL_SERVICE_SNAPSHOT, snapshot })
|
|
232
|
-
// })
|
|
233
|
-
//
|
|
234
|
-
// internalService.on(CHILD_SNAPSHOT, (emitted) => {
|
|
235
|
-
// globalService.send({ ...emitted })
|
|
236
|
-
// })
|
|
237
|
-
|
|
238
|
-
// internalService.start()
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { assign, setup } from 'xstate'
|
|
2
|
-
import { MachineIds } from '@/services/internal/constants'
|
|
3
|
-
import { AllItemsMachineContext } from '@/types'
|
|
4
|
-
import { eventEmitter } from '@/eventBus'
|
|
5
|
-
import { initialize } from '../allItems/actors/initialize'
|
|
6
|
-
import { fetchDbData } from '../allItems/actors/fetchDbData'
|
|
7
|
-
import { fetchSeeds } from '../allItems/actors/fetchSeeds'
|
|
8
|
-
import { fetchVersions } from '../allItems/actors/fetchVersions'
|
|
9
|
-
import { fetchRelatedItems } from '../allItems/actors/fetchRelatedItems'
|
|
10
|
-
import { processItems } from '../allItems/actors/processItems'
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export const itemMachineAll = setup({
|
|
14
|
-
types: {
|
|
15
|
-
context: {} as Partial<AllItemsMachineContext>,
|
|
16
|
-
input: {} as Partial<AllItemsMachineContext> | undefined,
|
|
17
|
-
},
|
|
18
|
-
actors: {
|
|
19
|
-
initialize,
|
|
20
|
-
fetchDbData,
|
|
21
|
-
fetchSeeds,
|
|
22
|
-
fetchVersions,
|
|
23
|
-
fetchRelatedItems,
|
|
24
|
-
processItems,
|
|
25
|
-
},
|
|
26
|
-
}).createMachine({
|
|
27
|
-
id: MachineIds.ALL_ITEMS,
|
|
28
|
-
initial: 'uninitialized',
|
|
29
|
-
context: ({ input }) => input as AllItemsMachineContext,
|
|
30
|
-
on: {
|
|
31
|
-
updateTimes: {
|
|
32
|
-
actions: assign({
|
|
33
|
-
times: ({ event }) => event.times,
|
|
34
|
-
}),
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
states: {
|
|
38
|
-
idle: {
|
|
39
|
-
entry: ({ self, context }) => {
|
|
40
|
-
eventEmitter.emit('service.saveState.request', {
|
|
41
|
-
state: self.getPersistedSnapshot(),
|
|
42
|
-
serviceId: `${MachineIds.ALL_ITEMS}_${context.modelName}`,
|
|
43
|
-
})
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
uninitialized: {
|
|
47
|
-
on: {
|
|
48
|
-
modelsFound: {
|
|
49
|
-
target: 'initializing',
|
|
50
|
-
actions: assign({
|
|
51
|
-
modelAddedToDb: true,
|
|
52
|
-
}),
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
initializing: {
|
|
57
|
-
on: {
|
|
58
|
-
initializeSuccess: {
|
|
59
|
-
target: 'fetchingSeeds',
|
|
60
|
-
actions: assign({
|
|
61
|
-
modelName: ({ event }) => event.modelName,
|
|
62
|
-
modelNameLowercase: ({ event }) => event.modelNameLowercase,
|
|
63
|
-
modelNamePlural: ({ event }) => event.modelNamePlural,
|
|
64
|
-
queryVariables: ({ event }) => event.queryVariables,
|
|
65
|
-
}),
|
|
66
|
-
},
|
|
67
|
-
modelsNotFound: 'idle',
|
|
68
|
-
},
|
|
69
|
-
invoke: {
|
|
70
|
-
src: 'initialize',
|
|
71
|
-
input: ({ context }) => ({ context }),
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
fetchingSeeds: {
|
|
75
|
-
on: {
|
|
76
|
-
fetchSeedsSuccess: {
|
|
77
|
-
target: 'fetchingVersions',
|
|
78
|
-
actions: assign({
|
|
79
|
-
itemSeeds: ({ event }) => event.itemSeeds,
|
|
80
|
-
}),
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
invoke: {
|
|
84
|
-
src: 'fetchSeeds',
|
|
85
|
-
input: ({ context }) => ({ context }),
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
fetchingVersions: {
|
|
89
|
-
on: {
|
|
90
|
-
fetchVersionsSuccess: {
|
|
91
|
-
target: 'fetchingRelatedItems',
|
|
92
|
-
actions: assign({
|
|
93
|
-
itemVersions: ({ event }) => event.itemVersions,
|
|
94
|
-
}),
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
invoke: {
|
|
98
|
-
src: 'fetchVersions',
|
|
99
|
-
input: ({ context }) => ({ context }),
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
fetchingRelatedItems: {
|
|
103
|
-
on: {
|
|
104
|
-
fetchRelatedItemsSuccess: {
|
|
105
|
-
target: 'processingItems',
|
|
106
|
-
actions: assign({
|
|
107
|
-
relatedProperties: ({ event }) => event.relatedProperties,
|
|
108
|
-
relatedVersionsBySeedUid: ({ event }) =>
|
|
109
|
-
event.relatedVersionsBySeedUid,
|
|
110
|
-
relatedVersionsBySchemaUid: ({ event }) =>
|
|
111
|
-
event.relatedVersionsBySchemaUid,
|
|
112
|
-
schemaUidsByModelName: ({ event }) => event.schemaUidsByModelName,
|
|
113
|
-
mostRecentPropertiesBySeedUid: ({ event }) =>
|
|
114
|
-
event.mostRecentPropertiesBySeedUid,
|
|
115
|
-
}),
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
invoke: {
|
|
119
|
-
src: 'fetchRelatedItems',
|
|
120
|
-
input: ({ context }) => ({ context }),
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
processingItems: {
|
|
124
|
-
on: {
|
|
125
|
-
processItemsSuccess: 'idle',
|
|
126
|
-
itemCreated: {
|
|
127
|
-
actions: assign({
|
|
128
|
-
items: ({ context, event }) => {
|
|
129
|
-
if (context && context.items) {
|
|
130
|
-
const foundItem = context.items.find((item) => {
|
|
131
|
-
if (!item.versionLocalId) {
|
|
132
|
-
return false
|
|
133
|
-
}
|
|
134
|
-
return (
|
|
135
|
-
item.versionLocalId === event.item.versionLocalId ||
|
|
136
|
-
item.versionUid === event.item.versionUid
|
|
137
|
-
)
|
|
138
|
-
})
|
|
139
|
-
if (foundItem) {
|
|
140
|
-
return context.items
|
|
141
|
-
}
|
|
142
|
-
return [...context.items, event.item]
|
|
143
|
-
}
|
|
144
|
-
if (context && !context.items) {
|
|
145
|
-
return [event.item]
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
}),
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
invoke: {
|
|
152
|
-
src: 'processItems',
|
|
153
|
-
input: ({ context, self }) => ({ context, self }),
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
})
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { assign, setup } from 'xstate'
|
|
2
|
-
import { MachineIds } from '@/services/internal/constants'
|
|
3
|
-
import { ItemMachineContext } from '@/types'
|
|
4
|
-
import { waitForDb } from './actors/waitForDb'
|
|
5
|
-
import { initialize } from './actors/initialize'
|
|
6
|
-
import { hydrateExistingItem } from './actors/hydrateExistingItem'
|
|
7
|
-
import { hydrateNewItem } from './actors/hydrateNewItem'
|
|
8
|
-
import { fetchDataFromEas } from './actors/fetchDataFromEas'
|
|
9
|
-
import { reload } from './actors/reload'
|
|
10
|
-
import { IItemProperty } from '@/interfaces'
|
|
11
|
-
|
|
12
|
-
export const itemMachineSingle = setup({
|
|
13
|
-
types: {
|
|
14
|
-
context: {} as ItemMachineContext<any>,
|
|
15
|
-
input: {},
|
|
16
|
-
},
|
|
17
|
-
actors: {
|
|
18
|
-
waitForDb,
|
|
19
|
-
initialize,
|
|
20
|
-
hydrateExistingItem,
|
|
21
|
-
hydrateNewItem,
|
|
22
|
-
fetchDataFromEas,
|
|
23
|
-
reload,
|
|
24
|
-
},
|
|
25
|
-
}).createMachine({
|
|
26
|
-
id: MachineIds.ITEM,
|
|
27
|
-
initial: 'waitingForDb',
|
|
28
|
-
context: ({ input }) => input as ItemMachineContext<any>,
|
|
29
|
-
on: {
|
|
30
|
-
updatedPropertiesBySchemaUid: {
|
|
31
|
-
actions: assign({
|
|
32
|
-
propertiesBySchemaUid: ({ event }) => event.propertiesBySchemaUid,
|
|
33
|
-
}),
|
|
34
|
-
},
|
|
35
|
-
updatePropertiesMetadata: {
|
|
36
|
-
actions: assign({
|
|
37
|
-
propertiesMetadata: ({ event }) => event.propertiesMetadata,
|
|
38
|
-
}),
|
|
39
|
-
},
|
|
40
|
-
updateProperties: {
|
|
41
|
-
actions: assign({
|
|
42
|
-
propertiesUpdatedAt: Date.now(),
|
|
43
|
-
}),
|
|
44
|
-
},
|
|
45
|
-
updateValue: {
|
|
46
|
-
actions: assign(({ event, context }) => {
|
|
47
|
-
let { propertyInstances } = context
|
|
48
|
-
if (!propertyInstances) {
|
|
49
|
-
propertyInstances = new Map<string, IItemProperty<any>>()
|
|
50
|
-
}
|
|
51
|
-
const { propertyName, propertyValue } = event
|
|
52
|
-
|
|
53
|
-
if (!propertyInstances.has(propertyName)) {
|
|
54
|
-
return {
|
|
55
|
-
[propertyName]: propertyValue,
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
const propertyInstance = propertyInstances.get(
|
|
59
|
-
propertyName,
|
|
60
|
-
) as IItemProperty<any>
|
|
61
|
-
|
|
62
|
-
propertyInstance.value = propertyValue
|
|
63
|
-
propertyInstances.set(propertyName, propertyInstance)
|
|
64
|
-
// TODO: use immer here
|
|
65
|
-
return {
|
|
66
|
-
propertyInstances,
|
|
67
|
-
}
|
|
68
|
-
}),
|
|
69
|
-
},
|
|
70
|
-
addPropertyInstance: {
|
|
71
|
-
actions: assign(({ context, event }) => {
|
|
72
|
-
const propertyInstances =
|
|
73
|
-
context.propertyInstances || new Map<string, IItemProperty<any>>()
|
|
74
|
-
propertyInstances.set(event.propertyName, event.propertyInstance)
|
|
75
|
-
return {
|
|
76
|
-
propertyInstances,
|
|
77
|
-
}
|
|
78
|
-
}),
|
|
79
|
-
},
|
|
80
|
-
reload: '.reloading',
|
|
81
|
-
},
|
|
82
|
-
states: {
|
|
83
|
-
idle: {},
|
|
84
|
-
waitingForDb: {
|
|
85
|
-
on: {
|
|
86
|
-
waitForDbSuccess: 'initializing',
|
|
87
|
-
},
|
|
88
|
-
invoke: {
|
|
89
|
-
src: 'waitForDb',
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
initializing: {
|
|
93
|
-
on: {
|
|
94
|
-
hasExistingItem: {
|
|
95
|
-
target: 'idle',
|
|
96
|
-
actions: assign({
|
|
97
|
-
modelTableName: ({ event }) => event.modelTableName,
|
|
98
|
-
modelNamePlural: ({ event }) => event.modelNamePlural,
|
|
99
|
-
modelName: ({ event }) => event.modelName,
|
|
100
|
-
existingItem: ({ event }) => event.existingItem,
|
|
101
|
-
}),
|
|
102
|
-
},
|
|
103
|
-
isNewItem: {
|
|
104
|
-
target: 'idle',
|
|
105
|
-
actions: assign({
|
|
106
|
-
modelTableName: ({ event }) => event.modelTableName,
|
|
107
|
-
modelNamePlural: ({ event }) => event.modelNamePlural,
|
|
108
|
-
modelName: ({ event }) => event.modelName,
|
|
109
|
-
}),
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
invoke: {
|
|
113
|
-
src: 'initialize',
|
|
114
|
-
input: ({ context, event }) => ({ context, event }),
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
hydratingExistingItem: {
|
|
118
|
-
on: {
|
|
119
|
-
hydrateExistingItemSuccess: 'idle',
|
|
120
|
-
hydrateExistingItemFailure: 'destroying',
|
|
121
|
-
},
|
|
122
|
-
invoke: {
|
|
123
|
-
src: 'hydrateExistingItem',
|
|
124
|
-
input: ({ event, context }) => ({ event, context }),
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
hydratingNewItem: {
|
|
128
|
-
on: {
|
|
129
|
-
hydrateNewItemSuccess: 'idle',
|
|
130
|
-
},
|
|
131
|
-
invoke: {
|
|
132
|
-
src: 'hydrateNewItem',
|
|
133
|
-
input: ({ context }) => ({ context }),
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
fetchingRemoteData: {
|
|
137
|
-
on: {
|
|
138
|
-
fetchRemoteDataSuccess: 'idle',
|
|
139
|
-
},
|
|
140
|
-
invoke: {
|
|
141
|
-
src: 'fetchRemoteData',
|
|
142
|
-
input: ({ context }) => ({ context }),
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
reloading: {
|
|
146
|
-
on: {
|
|
147
|
-
reloadSuccess: 'idle',
|
|
148
|
-
},
|
|
149
|
-
invoke: {
|
|
150
|
-
src: 'reload',
|
|
151
|
-
input: ({ context }) => ({ context }),
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
|
-
destroying: {
|
|
155
|
-
type: 'final',
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
})
|
package/dist/src/loadAppDb.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { EventObject, fromCallback, Subscription } from 'xstate'
|
|
2
|
-
import {
|
|
3
|
-
DB_NAME_APP,
|
|
4
|
-
DB_ON_SNAPSHOT,
|
|
5
|
-
INTERNAL_LOADING_APP_DB_SUCCESS,
|
|
6
|
-
} from '@/services/internal/constants'
|
|
7
|
-
import debug from 'debug'
|
|
8
|
-
import { FromCallbackInput, InternalMachineContext } from '@/types'
|
|
9
|
-
|
|
10
|
-
const logger = debug('app:services:internal:actors:loadAppDb')
|
|
11
|
-
|
|
12
|
-
export const loadAppDb = fromCallback<
|
|
13
|
-
EventObject,
|
|
14
|
-
FromCallbackInput<InternalMachineContext>
|
|
15
|
-
>(({ sendBack, input: { context } }) => {
|
|
16
|
-
const { appDbService } = context
|
|
17
|
-
|
|
18
|
-
let subscription: Subscription | undefined
|
|
19
|
-
|
|
20
|
-
const _loadAppDb = async (): Promise<void> => {
|
|
21
|
-
return new Promise((resolve) => {
|
|
22
|
-
if (appDbService.getSnapshot().value === 'ready') {
|
|
23
|
-
return resolve()
|
|
24
|
-
}
|
|
25
|
-
subscription = appDbService.subscribe({
|
|
26
|
-
next: (snapshot) => {
|
|
27
|
-
if (snapshot.value === 'ready') {
|
|
28
|
-
return resolve()
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
sendBack({ type: DB_ON_SNAPSHOT, dbName: DB_NAME_APP, snapshot })
|
|
32
|
-
},
|
|
33
|
-
})
|
|
34
|
-
})
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
_loadAppDb().then(() => {
|
|
38
|
-
sendBack({ type: INTERNAL_LOADING_APP_DB_SUCCESS })
|
|
39
|
-
logger('[sdk] [internal/actors] Successfully loaded app DB')
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
return () => {
|
|
43
|
-
if (subscription) {
|
|
44
|
-
subscription.unsubscribe()
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
})
|
package/dist/src/machines.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { Endpoints, Environment, ModelClassType } from './index'
|
|
2
|
-
import { ActorRefFrom } from 'xstate'
|
|
3
|
-
import { PublishRequestData } from './seedProtocol'
|
|
4
|
-
|
|
5
|
-
export type DbServiceContext = {
|
|
6
|
-
dbName: string
|
|
7
|
-
dbId?: string
|
|
8
|
-
dirName: string
|
|
9
|
-
drizzleDb?: any
|
|
10
|
-
pathToDb?: string
|
|
11
|
-
pathToDir?: string
|
|
12
|
-
pathToDbDir?: string
|
|
13
|
-
hasFiles?: boolean
|
|
14
|
-
error?: string
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type InternalMachineContext = {
|
|
18
|
-
error?: string
|
|
19
|
-
endpoints: Endpoints
|
|
20
|
-
addresses: string[]
|
|
21
|
-
filesDir?: string
|
|
22
|
-
arweaveDomain?: string
|
|
23
|
-
environment: string
|
|
24
|
-
hasFiles: boolean
|
|
25
|
-
seedDbService: any
|
|
26
|
-
appDbService: any
|
|
27
|
-
sdkDbService: any
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export type GlobalMachineContext = {
|
|
31
|
-
isInitialized?: boolean
|
|
32
|
-
addedModelRecordsToDb?: boolean
|
|
33
|
-
environment?: Environment
|
|
34
|
-
endpoints?: Endpoints
|
|
35
|
-
addresses?: string[]
|
|
36
|
-
models?: { [key: string]: ModelClassType }
|
|
37
|
-
internalService?: ActorRefFrom<any>
|
|
38
|
-
publishItemService?: ActorRefFrom<any>
|
|
39
|
-
arweaveDomain?: string
|
|
40
|
-
filesDir?: string
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type PublishMachineContext = PublishRequestData & {
|
|
44
|
-
status: string
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export type GetSchemaForModelEvent = {
|
|
48
|
-
type: 'getSchemaForModel'
|
|
49
|
-
modelName: string
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export type HydrateExistingItemEvent = {
|
|
53
|
-
type: 'hydrateExistingItem'
|
|
54
|
-
existingItem: any
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export type FromCallbackInput<T, P = undefined> = {
|
|
58
|
-
context: T
|
|
59
|
-
event?: P
|
|
60
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { and, eq, getTableColumns, or, SQL, sql } from 'drizzle-orm'
|
|
2
|
-
import { BaseDb } from '@/db/Db/BaseDb'
|
|
3
|
-
import { metadata } from '@/seedSchema'
|
|
4
|
-
|
|
5
|
-
export const getMetadataLatest = ({seedLocalId, seedUid}: {seedLocalId?: string, seedUid?: string}) => {
|
|
6
|
-
const appDb = BaseDb.getAppDb()
|
|
7
|
-
|
|
8
|
-
const whereClauses: SQL[] = []
|
|
9
|
-
|
|
10
|
-
if (seedLocalId) {
|
|
11
|
-
whereClauses.push(eq(metadata.seedLocalId, seedLocalId))
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (seedUid) {
|
|
15
|
-
whereClauses.push(eq(metadata.seedUid, seedUid))
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const metadataColumns = getTableColumns(metadata)
|
|
19
|
-
|
|
20
|
-
return appDb.$with('metadataLatest').as(
|
|
21
|
-
appDb
|
|
22
|
-
.select({
|
|
23
|
-
...metadataColumns,
|
|
24
|
-
rowNum: sql.raw(`
|
|
25
|
-
ROW_NUMBER() OVER (
|
|
26
|
-
PARTITION BY property_name
|
|
27
|
-
ORDER BY COALESCE(created_at, attestation_created_at) DESC
|
|
28
|
-
)
|
|
29
|
-
`).as('rowNum')
|
|
30
|
-
})
|
|
31
|
-
.from(metadata)
|
|
32
|
-
.where(and(...whereClauses))
|
|
33
|
-
)
|
|
34
|
-
}
|