@seedprotocol/sdk 0.2.51 → 0.2.53
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-Bh_lvrAN.js} +6 -3
- package/dist/Db-Bh_lvrAN.js.map +1 -0
- package/dist/{Db-DMJ0v3gO.js → Db-DqBP6XK2.js} +3 -3
- package/dist/{Db-DMJ0v3gO.js.map → Db-DqBP6XK2.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-COP3FuaU.js} +3 -3
- package/dist/{Item-D4n439Ei.js.map → Item-COP3FuaU.js.map} +1 -1
- package/dist/{ItemProperty-Be5ymRVT.js → ItemProperty-BFn9wM65.js} +3 -3
- package/dist/{ItemProperty-Be5ymRVT.js.map → ItemProperty-BFn9wM65.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-BLla2o05.js → index-C4xqqsLw.js} +3 -3
- package/dist/index-C4xqqsLw.js.map +1 -0
- package/dist/{index-BeKRizLf.js → index-CLvyWg5f.js} +257 -145
- package/dist/index-CLvyWg5f.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-Bao3o6wu.js} +3 -3
- package/dist/{seed.schema.config-CMpV_hyS.js.map → seed.schema.config-Bao3o6wu.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/db/Db.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/Db-quJxmvHH.js.map +0 -1
- 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
package/dist/src/migrate.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { EventObject, fromCallback } from 'xstate'
|
|
2
|
-
import { DbServiceContext, FromCallbackInput, SqliteWasmResult } from '@/types'
|
|
3
|
-
import {
|
|
4
|
-
BROWSER_FS_TOP_DIR,
|
|
5
|
-
DB_MIGRATING_SUCCESS,
|
|
6
|
-
} from '@/services/internal/constants'
|
|
7
|
-
import debug from 'debug'
|
|
8
|
-
import { BaseDb } from '@/db/Db/BaseDb'
|
|
9
|
-
import fs from '@zenfs/core'
|
|
10
|
-
import { FileManager } from '@/browser/helpers/FileManager'
|
|
11
|
-
|
|
12
|
-
const logger = debug('app:services:db:actors:migrate')
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export const migrate = fromCallback<
|
|
17
|
-
EventObject,
|
|
18
|
-
FromCallbackInput<DbServiceContext>
|
|
19
|
-
>(({ sendBack, input: { context } }) => {
|
|
20
|
-
const { pathToDbDir, dbId, dbName } = context
|
|
21
|
-
|
|
22
|
-
logger('[db/actors] migrate context', context)
|
|
23
|
-
|
|
24
|
-
let journalExists = false
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const _checkForFiles = async (): Promise<void> => {
|
|
28
|
-
const journalPath = `/${pathToDbDir}/meta/_journal.json`
|
|
29
|
-
|
|
30
|
-
journalExists = await fs.promises.exists(journalPath)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (!journalExists) {
|
|
34
|
-
await FileManager.waitForFile(journalPath, 500, 60000)
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const _migrate = async (): Promise<void> => {
|
|
39
|
-
await BaseDb.migrate(pathToDbDir, dbName, dbId)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
_checkForFiles()
|
|
43
|
-
.then(() => {
|
|
44
|
-
if (journalExists) {
|
|
45
|
-
return _migrate()
|
|
46
|
-
}
|
|
47
|
-
})
|
|
48
|
-
.then(() => {
|
|
49
|
-
sendBack({ type: DB_MIGRATING_SUCCESS, dbName })
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
return () => { }
|
|
53
|
-
})
|
package/dist/src/model.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { PropertyStates, PropertyValue } from './property'
|
|
2
|
-
import { Actor, AnyActorLogic } from 'xstate'
|
|
3
|
-
import { Static } from '@sinclair/typebox'
|
|
4
|
-
import { IModelClass, TModelSchema } from '@/schema'
|
|
5
|
-
import { BaseItem } from '@/Item/BaseItem'
|
|
6
|
-
|
|
7
|
-
export type ModelDefinitions = {
|
|
8
|
-
[modelName: string]: ModelClassType
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type ModelStatus = (propName: string) => keyof PropertyStates
|
|
12
|
-
|
|
13
|
-
export type ExcludedKeys = 'states' | 'status'
|
|
14
|
-
|
|
15
|
-
type ExcludeKeys<T, K> = {
|
|
16
|
-
[P in keyof T as Exclude<P, K>]: T[P]
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type ModelClassType = {
|
|
20
|
-
originalConstructor: () => void
|
|
21
|
-
schema: ModelSchema
|
|
22
|
-
schemaUid?: string
|
|
23
|
-
create: (values: ModelValues<any>) => Promise<BaseItem<any>>
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export type ModelValues<T extends Record<string, any>> = BaseItem<any> & {
|
|
27
|
-
schema: ModelSchema
|
|
28
|
-
ModelClass?: ModelClassType
|
|
29
|
-
[key: string & keyof T]: PropertyValue
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export type StatesMap<T> = Map<string, Actor<T extends AnyActorLogic ? T : never>>
|
|
33
|
-
|
|
34
|
-
// export type ModelSchema = {
|
|
35
|
-
// [key: string]: TObject
|
|
36
|
-
// }
|
|
37
|
-
|
|
38
|
-
export type ModelSchema = Partial<Static<typeof TModelSchema>>
|
|
39
|
-
|
|
40
|
-
export type ModelConstructor = <
|
|
41
|
-
T extends { new(...args: any[]): IModelClass },
|
|
42
|
-
>(
|
|
43
|
-
constructor: T,
|
|
44
|
-
) => T & IModelClass
|
|
45
|
-
|
|
46
|
-
// export type ModelConstructor = Static<TModelConstructor>
|
|
47
|
-
|
|
48
|
-
export interface ModelProperty {
|
|
49
|
-
propertyLocalId?: string
|
|
50
|
-
name: string
|
|
51
|
-
dataType:
|
|
52
|
-
| 'string'
|
|
53
|
-
| 'bytes32'
|
|
54
|
-
| 'uint8'
|
|
55
|
-
| 'uint256'
|
|
56
|
-
| 'bool'
|
|
57
|
-
| 'address'
|
|
58
|
-
| 'bytes'
|
|
59
|
-
| 'int8'
|
|
60
|
-
| 'int256'
|
|
61
|
-
| 'int'
|
|
62
|
-
| 'bytes32[]'
|
|
63
|
-
modelSchemaUids: string[]
|
|
64
|
-
modelLocalId?: string
|
|
65
|
-
schemaName?: string
|
|
66
|
-
schemaUid: string
|
|
67
|
-
schemaDefinition: string
|
|
68
|
-
relatedModelSchemaUid?: string
|
|
69
|
-
relatedModelLocalId?: string
|
|
70
|
-
createdAt?: number
|
|
71
|
-
updatedAt?: number
|
|
72
|
-
}
|
package/dist/src/modelClass.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ModelClassType } from '@/types'
|
|
2
|
-
|
|
3
|
-
const modelStore = new Map<string, ModelClassType>()
|
|
4
|
-
|
|
5
|
-
export const getModels = (): Record<string, ModelClassType> => {
|
|
6
|
-
return Object.fromEntries(modelStore)
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const getModel = (modelName: string): ModelClassType | undefined => {
|
|
10
|
-
return modelStore.get(modelName)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const getModelNames = (): string[] => {
|
|
14
|
-
return Array.from(modelStore.keys())
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const setModel = (modelName: string, model: ModelClassType) => {
|
|
18
|
-
modelStore.set(modelName, model)
|
|
19
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'drizzle-kit'
|
|
2
|
-
import dotenv from 'dotenv'
|
|
3
|
-
import process from 'node:process'
|
|
4
|
-
import path from 'path'
|
|
5
|
-
import { DrizzleConfig } from 'drizzle-orm'
|
|
6
|
-
|
|
7
|
-
dotenv.config()
|
|
8
|
-
|
|
9
|
-
let sdkRoot = './node_modules/@seedprotocol/sdk'
|
|
10
|
-
|
|
11
|
-
if (process.env.IS_SEED_DEV) {
|
|
12
|
-
sdkRoot = './src'
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
let dotSeedDir = path.join(process.cwd(), '.seed')
|
|
16
|
-
|
|
17
|
-
if (process.env.IS_SEED_DEV) {
|
|
18
|
-
dotSeedDir = path.join(
|
|
19
|
-
process.cwd(),
|
|
20
|
-
'__tests__',
|
|
21
|
-
'__mocks__',
|
|
22
|
-
'browser',
|
|
23
|
-
'project',
|
|
24
|
-
'.seed',
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
let schemaDir = `${sdkRoot}/dist/seedSchema/*.ts`
|
|
29
|
-
|
|
30
|
-
if (process.env.IS_SEED_DEV) {
|
|
31
|
-
schemaDir = `${sdkRoot}/seedSchema/*.ts`
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export default defineConfig({
|
|
35
|
-
schema: schemaDir,
|
|
36
|
-
dialect: 'sqlite',
|
|
37
|
-
out: `${dotSeedDir}/db`,
|
|
38
|
-
dbCredentials: {
|
|
39
|
-
url: `${dotSeedDir}/db/app_db.sqlite3`,
|
|
40
|
-
},
|
|
41
|
-
}) as DrizzleConfig
|
package/dist/src/prepareDb.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { BaseDb } from '@/db/Db/BaseDb'
|
|
2
|
-
import { InternalMachineContext } from '@/types'
|
|
3
|
-
import { FromCallbackInput } from '@/types'
|
|
4
|
-
import { EventObject, fromCallback } from 'xstate'
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export const prepareDb = fromCallback<
|
|
8
|
-
EventObject,
|
|
9
|
-
FromCallbackInput<InternalMachineContext>
|
|
10
|
-
>(({ sendBack, input: { context } }) => {
|
|
11
|
-
const { filesDir } = context
|
|
12
|
-
|
|
13
|
-
if (!filesDir) {
|
|
14
|
-
throw new Error('filesDir is required')
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const _prepareDb = async (): Promise<void> => {
|
|
18
|
-
const manager = await BaseDb.prepareDb(filesDir)
|
|
19
|
-
if (manager) {
|
|
20
|
-
sendBack({ type: 'prepareDbSuccess', manager })
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
_prepareDb().then(() => {
|
|
26
|
-
return
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
})
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { EventObject, fromCallback } from 'xstate'
|
|
2
|
-
import { FromCallbackInput, PublishMachineContext } from '@/types'
|
|
3
|
-
import { models as modelsTable, modelUids } from '@/seedSchema'
|
|
4
|
-
import { BaseDb } from '@/db/Db/BaseDb'
|
|
5
|
-
import { eq } from 'drizzle-orm'
|
|
6
|
-
import { getModelSchemas } from '@/db/read/getModelSchemas'
|
|
7
|
-
import { BaseItem } from '@/Item/BaseItem'
|
|
8
|
-
|
|
9
|
-
export const preparePublishRequestData = fromCallback<
|
|
10
|
-
EventObject,
|
|
11
|
-
FromCallbackInput<PublishMachineContext>
|
|
12
|
-
>(({ sendBack, input: { context } }) => {
|
|
13
|
-
const { localId } = context
|
|
14
|
-
|
|
15
|
-
const _preparePublishRequestData = async () => {
|
|
16
|
-
const item = await BaseItem.find({ seedLocalId: localId })
|
|
17
|
-
|
|
18
|
-
if (!item) {
|
|
19
|
-
return false
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const appDb = BaseDb.getAppDb()
|
|
23
|
-
|
|
24
|
-
const modelsRows = await appDb
|
|
25
|
-
.select({
|
|
26
|
-
modelName: modelsTable.name,
|
|
27
|
-
schemaUid: modelUids.uid,
|
|
28
|
-
})
|
|
29
|
-
.from(modelsTable)
|
|
30
|
-
.leftJoin(modelUids, eq(modelUids.modelId, modelsTable.id))
|
|
31
|
-
.where(eq(modelsTable.name, 'Version'))
|
|
32
|
-
|
|
33
|
-
if (!modelsRows || modelsRows.length === 0) {
|
|
34
|
-
sendBack({ type: 'preparePublishRequestDataError' })
|
|
35
|
-
return false
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const versionSchemaUid = modelsRows[0].schemaUid
|
|
39
|
-
|
|
40
|
-
const editedProperties = await item.getEditedProperties()
|
|
41
|
-
|
|
42
|
-
const { modelSchemas, schemaStringToModelRecord } = await getModelSchemas({
|
|
43
|
-
sdkConfigDb: appDb,
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
// const dataEncoder = new SchemaEncoder(modelProperty.schemaDefinition,)
|
|
47
|
-
// const encodedData = dataEncoder.encodeData(data,)
|
|
48
|
-
//
|
|
49
|
-
// itemData.listOfAttestations.push({
|
|
50
|
-
// schema : modelProperty.schemaUid,
|
|
51
|
-
// data : [
|
|
52
|
-
// {
|
|
53
|
-
// ...defaultAttestationData,
|
|
54
|
-
// data : encodedData,
|
|
55
|
-
// },
|
|
56
|
-
// ],
|
|
57
|
-
// },)
|
|
58
|
-
|
|
59
|
-
const publishRequestData = {
|
|
60
|
-
seedIsRevocable: false,
|
|
61
|
-
seedSchemaUid: item.schemaUid,
|
|
62
|
-
seedUid: item.seedUid,
|
|
63
|
-
versionSchemaUid,
|
|
64
|
-
versionUid: item.latestVersionUid,
|
|
65
|
-
listOfAttestations: [],
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
sendBack({
|
|
69
|
-
type: 'updateContext',
|
|
70
|
-
...publishRequestData,
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
return true
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
_preparePublishRequestData().then((success) => {
|
|
77
|
-
if (success) {
|
|
78
|
-
sendBack({ type: 'preparePublishRequestDataSuccess' })
|
|
79
|
-
}
|
|
80
|
-
})
|
|
81
|
-
})
|
package/dist/src/processItems.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { EventObject, fromCallback } from 'xstate'
|
|
2
|
-
import { AllItemsMachineContext, FromCallbackInput } from '@/types'
|
|
3
|
-
import { Attestation } from '@/graphql/gql/graphql'
|
|
4
|
-
import { eventEmitter } from '@/eventBus'
|
|
5
|
-
|
|
6
|
-
export const processItems = fromCallback<
|
|
7
|
-
EventObject,
|
|
8
|
-
FromCallbackInput<AllItemsMachineContext>
|
|
9
|
-
>(
|
|
10
|
-
({ sendBack, input: { context } }) => {
|
|
11
|
-
const {
|
|
12
|
-
itemVersions,
|
|
13
|
-
itemSeeds,
|
|
14
|
-
ModelClass,
|
|
15
|
-
schemaUidsByModelName,
|
|
16
|
-
mostRecentPropertiesBySeedUid,
|
|
17
|
-
times,
|
|
18
|
-
// relatedProperties,
|
|
19
|
-
// relatedVersionsBySchemaUid,
|
|
20
|
-
// relatedVersionsBySeedUid,
|
|
21
|
-
} = context
|
|
22
|
-
|
|
23
|
-
if (!itemVersions || !itemSeeds) {
|
|
24
|
-
throw new Error('No itemVersions or itemSeeds found')
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const _processItems = async () => {
|
|
28
|
-
// For each itemSeed, find all the Versions
|
|
29
|
-
for (const itemSeed of itemSeeds.slice(8, 16)) {
|
|
30
|
-
const versionsForSeed = itemVersions.filter(
|
|
31
|
-
(version) => version.refUID === itemSeed.id,
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
if (versionsForSeed.length === 0) {
|
|
35
|
-
continue
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Find the most recent Version for each Seed
|
|
39
|
-
const recentVersionsMap: { [seedId: string]: Attestation } = {}
|
|
40
|
-
versionsForSeed.forEach((version: Attestation) => {
|
|
41
|
-
const existingVersion = recentVersionsMap[version.refUID]
|
|
42
|
-
if (
|
|
43
|
-
!existingVersion ||
|
|
44
|
-
new Date(version.timeCreated * 1000) >
|
|
45
|
-
new Date(existingVersion.timeCreated * 1000)
|
|
46
|
-
) {
|
|
47
|
-
recentVersionsMap[version.refUID] = version
|
|
48
|
-
}
|
|
49
|
-
})
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
_processItems().then(() => {
|
|
54
|
-
sendBack({ type: 'processItemsSuccess' })
|
|
55
|
-
const modelName = ModelClass.originalConstructor.name
|
|
56
|
-
eventEmitter.emit('item.requestAll', {
|
|
57
|
-
modelName,
|
|
58
|
-
})
|
|
59
|
-
eventEmitter.emit('service.save', {
|
|
60
|
-
modelName,
|
|
61
|
-
})
|
|
62
|
-
sendBack({
|
|
63
|
-
type: 'updateTimes',
|
|
64
|
-
times: {
|
|
65
|
-
...times,
|
|
66
|
-
processItems: {
|
|
67
|
-
start: null,
|
|
68
|
-
end: Date.now(),
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
})
|
|
72
|
-
})
|
|
73
|
-
},
|
|
74
|
-
)
|
package/dist/src/property.ts
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { useImmer } from 'use-immer'
|
|
2
|
-
import { Item } from '@/browser/Item'
|
|
3
|
-
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
4
|
-
import { useSelector } from '@xstate/react'
|
|
5
|
-
import debug from 'debug'
|
|
6
|
-
import { eventEmitter } from '@/eventBus'
|
|
7
|
-
import { ItemProperty } from '@/browser/ItemProperty/ItemProperty'
|
|
8
|
-
import { useGlobalServiceStatus } from '@/browser/react/services'
|
|
9
|
-
import { IItemProperty } from '@/interfaces'
|
|
10
|
-
|
|
11
|
-
const logger = debug('app:react:property')
|
|
12
|
-
|
|
13
|
-
type UseItemPropertyProps = {
|
|
14
|
-
propertyName: string
|
|
15
|
-
seedLocalId?: string
|
|
16
|
-
seedUid?: string
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
type UseItemPropertyReturn = {
|
|
20
|
-
property: IItemProperty<any> | undefined
|
|
21
|
-
isInitialized: boolean
|
|
22
|
-
value: any
|
|
23
|
-
status: string
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
type UseItemProperty = (props: UseItemPropertyProps | undefined) => UseItemPropertyReturn
|
|
27
|
-
|
|
28
|
-
export const useItemProperty: UseItemProperty = (props = {
|
|
29
|
-
propertyName: '',
|
|
30
|
-
seedLocalId: '',
|
|
31
|
-
seedUid: '',
|
|
32
|
-
}) => {
|
|
33
|
-
|
|
34
|
-
const { propertyName, seedLocalId, seedUid } = props
|
|
35
|
-
|
|
36
|
-
const [property, setProperty] = useState<IItemProperty<any> | undefined>()
|
|
37
|
-
const [isInitialized, setIsInitialized] = useState(false)
|
|
38
|
-
|
|
39
|
-
const { internalStatus } = useGlobalServiceStatus()
|
|
40
|
-
|
|
41
|
-
const isReadingDb = useRef(false)
|
|
42
|
-
|
|
43
|
-
const value = useSelector(property?.getService(), (snapshot) => {
|
|
44
|
-
if (!snapshot || !snapshot.context) {
|
|
45
|
-
return
|
|
46
|
-
}
|
|
47
|
-
return snapshot.context.renderValue || snapshot.context.propertyValue
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
const status = useSelector(
|
|
51
|
-
property?.getService(),
|
|
52
|
-
(snapshot) => snapshot?.value as string,
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
const readFromDb = useCallback(async () => {
|
|
56
|
-
if (
|
|
57
|
-
internalStatus !== 'ready' ||
|
|
58
|
-
isReadingDb.current ||
|
|
59
|
-
(!seedLocalId && !seedUid)
|
|
60
|
-
) {
|
|
61
|
-
return
|
|
62
|
-
}
|
|
63
|
-
isReadingDb.current = true
|
|
64
|
-
const foundProperty = await ItemProperty.find({
|
|
65
|
-
propertyName,
|
|
66
|
-
seedLocalId,
|
|
67
|
-
seedUid,
|
|
68
|
-
})
|
|
69
|
-
if (!foundProperty) {
|
|
70
|
-
logger(
|
|
71
|
-
`[useItemPropertyTest] [readFromDb] no property found for Item.${seedLocalId}.${propertyName}`,
|
|
72
|
-
)
|
|
73
|
-
isReadingDb.current = false
|
|
74
|
-
return
|
|
75
|
-
}
|
|
76
|
-
if (foundProperty.status === 'waitingForDb') {
|
|
77
|
-
foundProperty.getService().send({ type: 'waitForDbSuccess' })
|
|
78
|
-
}
|
|
79
|
-
setProperty(foundProperty)
|
|
80
|
-
setIsInitialized(true)
|
|
81
|
-
isReadingDb.current = false
|
|
82
|
-
}, [internalStatus, props])
|
|
83
|
-
|
|
84
|
-
const listenerRef = useRef(readFromDb)
|
|
85
|
-
|
|
86
|
-
useEffect(() => {
|
|
87
|
-
listenerRef.current = readFromDb
|
|
88
|
-
}, [readFromDb, props])
|
|
89
|
-
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
if (internalStatus === 'ready') {
|
|
92
|
-
readFromDb()
|
|
93
|
-
}
|
|
94
|
-
}, [internalStatus])
|
|
95
|
-
|
|
96
|
-
useEffect(() => {
|
|
97
|
-
eventEmitter.addListener(
|
|
98
|
-
`property.${seedUid || seedLocalId}.${propertyName}.update`,
|
|
99
|
-
() => {
|
|
100
|
-
listenerRef.current()
|
|
101
|
-
},
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
return () => {
|
|
105
|
-
eventEmitter.removeListener(
|
|
106
|
-
`property.${seedUid || seedLocalId}.${propertyName}.update`,
|
|
107
|
-
)
|
|
108
|
-
}
|
|
109
|
-
}, [])
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
property,
|
|
113
|
-
isInitialized,
|
|
114
|
-
value,
|
|
115
|
-
status,
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
export const useItemProperties = (item?: Item<any>) => {
|
|
119
|
-
const [propertyObj, setPropertyObj] = useImmer({})
|
|
120
|
-
const [isListening, setIsListening] = useState(false)
|
|
121
|
-
|
|
122
|
-
const updatePropertyObj = useCallback(
|
|
123
|
-
(event) => {
|
|
124
|
-
if (!item) {
|
|
125
|
-
console.error('[XXXXXX] [updatePropertyObj] no item when expected')
|
|
126
|
-
return
|
|
127
|
-
}
|
|
128
|
-
const { propertyName, propertyValue } = event
|
|
129
|
-
if (!propertyName) {
|
|
130
|
-
return
|
|
131
|
-
}
|
|
132
|
-
setPropertyObj((draft) => {
|
|
133
|
-
draft[propertyName] = propertyValue
|
|
134
|
-
})
|
|
135
|
-
},
|
|
136
|
-
[item],
|
|
137
|
-
)
|
|
138
|
-
|
|
139
|
-
useEffect(() => {
|
|
140
|
-
if (!item) {
|
|
141
|
-
return
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const eventKey = `item.${item.seedLocalId}.property.update`
|
|
145
|
-
|
|
146
|
-
eventEmitter.addListener(eventKey, updatePropertyObj)
|
|
147
|
-
|
|
148
|
-
return () => {
|
|
149
|
-
eventEmitter.removeListener(eventKey, updatePropertyObj)
|
|
150
|
-
}
|
|
151
|
-
}, [item])
|
|
152
|
-
|
|
153
|
-
return {
|
|
154
|
-
properties: propertyObj,
|
|
155
|
-
}
|
|
156
|
-
}
|