@seedprotocol/sdk 0.2.0 → 0.2.2
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/Item-EuINlFXI.js +41 -0
- package/dist/Item-EuINlFXI.js.map +1 -0
- package/dist/ItemProperty-l0sNRNKZ.js +2 -0
- package/dist/ItemProperty-l0sNRNKZ.js.map +1 -0
- package/dist/bin.js +1 -2
- package/dist/bin.js.map +1 -1
- package/dist/{constants-B6s6tGup.js → constants-yM3e1D1k.js} +2 -3
- package/dist/constants-yM3e1D1k.js.map +1 -0
- package/dist/{index-B5qzD-bs.js → index-C9eVIXxd.js} +5 -6
- package/dist/index-C9eVIXxd.js.map +1 -0
- package/dist/{index-DaK2dz5P.js → index-DIlkGqpY.js} +221 -223
- package/dist/index-DIlkGqpY.js.map +1 -0
- package/dist/main.js +2 -3
- package/dist/main.js.map +1 -1
- package/dist/{seed.schema.config-DIMmvqJf.js → seed.schema.config-Du8pUTQu.js} +6 -7
- package/dist/seed.schema.config-Du8pUTQu.js.map +1 -0
- package/dist/src/BaseItemProperty.ts +1 -1
- package/dist/src/IItemProperty.ts +1 -1
- package/dist/src/ItemProperty.ts +0 -16
- package/dist/src/SeedProtocolSdk.d.ts +1 -1
- package/dist/src/client.ts +12 -6
- package/dist/src/create.ts +1 -1
- package/dist/src/fetchDbData.ts +7 -4
- package/dist/src/fetchSeeds.ts +5 -2
- package/dist/src/fetchVersions.ts +5 -2
- package/dist/src/getItem.ts +1 -1
- package/dist/src/getPublishPayload.ts +1 -1
- package/dist/src/globalMachine.ts +1 -1
- package/dist/src/hydrateFromDb.ts +1 -1
- package/dist/src/index.ts +4 -21
- package/dist/src/initialize.ts +88 -238
- package/dist/src/itemMachineAll.ts +6 -7
- package/dist/src/preparePublishRequestData.ts +1 -1
- package/dist/src/processItems.ts +5 -2
- package/dist/src/property.ts +2 -2
- package/dist/src/requestAll.ts +1 -1
- package/dist/src/trash.ts +1 -1
- package/dist/types/src/Item/index.d.ts +5 -0
- package/dist/types/src/Item/index.d.ts.map +1 -0
- package/dist/types/src/ItemProperty/BaseItemProperty.d.ts +1 -1
- package/dist/types/src/ItemProperty/BaseItemProperty.d.ts.map +1 -1
- package/dist/types/src/ItemProperty/index.d.ts +5 -0
- package/dist/types/src/ItemProperty/index.d.ts.map +1 -0
- package/dist/types/src/browser/{item → Item}/Item.d.ts.map +1 -1
- package/dist/types/src/browser/Item/index.d.ts +2 -0
- package/dist/types/src/browser/Item/index.d.ts.map +1 -0
- package/dist/types/src/browser/{item → ItemProperty}/ItemProperty.d.ts +2 -1
- package/dist/types/src/browser/ItemProperty/ItemProperty.d.ts.map +1 -0
- package/dist/types/src/browser/{property → ItemProperty}/index.d.ts +1 -1
- package/dist/types/src/browser/ItemProperty/index.d.ts.map +1 -0
- package/dist/types/src/browser/index.d.ts +2 -3
- package/dist/types/src/browser/index.d.ts.map +1 -1
- package/dist/types/src/browser/react/item.d.ts +1 -1
- package/dist/types/src/browser/react/property.d.ts +1 -1
- package/dist/types/src/browser/react/trash.d.ts +1 -1
- package/dist/types/src/browser/schema/index.d.ts +2 -2
- package/dist/types/src/browser/schema/index.d.ts.map +1 -1
- package/dist/types/src/browser/schema/model/index.d.ts +1 -1
- package/dist/types/src/{browser/client.d.ts → client.d.ts} +1 -1
- package/dist/types/src/client.d.ts.map +1 -0
- package/dist/types/src/db/read/getPublishPayload.d.ts +1 -1
- package/dist/types/src/helpers/constants.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +4 -4
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/interfaces/IItemProperty.d.ts +1 -1
- package/dist/types/src/interfaces/IItemProperty.d.ts.map +1 -1
- package/dist/types/src/node/{item → Item}/Item.d.ts.map +1 -1
- package/dist/types/src/node/ItemProperty/ItemProperty.d.ts +1 -0
- package/dist/types/src/node/ItemProperty/ItemProperty.d.ts.map +1 -0
- package/dist/types/src/services/allItems/actors/fetchDbData.d.ts +4 -0
- package/dist/types/src/services/allItems/actors/fetchDbData.d.ts.map +1 -0
- package/dist/types/src/services/allItems/actors/fetchRelatedItems.d.ts.map +1 -0
- package/dist/types/src/services/allItems/actors/fetchSeeds.d.ts +4 -0
- package/dist/types/src/services/allItems/actors/fetchSeeds.d.ts.map +1 -0
- package/dist/types/src/services/allItems/actors/fetchVersions.d.ts +4 -0
- package/dist/types/src/services/allItems/actors/fetchVersions.d.ts.map +1 -0
- package/dist/types/src/services/allItems/actors/initialize.d.ts.map +1 -0
- package/dist/types/src/services/allItems/actors/processItems.d.ts +4 -0
- package/dist/types/src/services/allItems/actors/processItems.d.ts.map +1 -0
- package/dist/types/src/services/allItems/itemMachineAll.d.ts +67 -0
- package/dist/types/src/services/allItems/itemMachineAll.d.ts.map +1 -0
- package/dist/types/src/types/item.d.ts +5 -5
- package/dist/types/src/types/item.d.ts.map +1 -1
- package/package.json +15 -12
- package/dist/constants-B6s6tGup.js.map +0 -1
- package/dist/index-B5qzD-bs.js.map +0 -1
- package/dist/index-DaK2dz5P.js.map +0 -1
- package/dist/seed.schema.config-DIMmvqJf.js.map +0 -1
- package/dist/src/init.ts +0 -61
- package/dist/types/src/browser/client.d.ts.map +0 -1
- package/dist/types/src/browser/item/ItemProperty.d.ts.map +0 -1
- package/dist/types/src/browser/item/all/actors/fetchDbData.d.ts +0 -2
- package/dist/types/src/browser/item/all/actors/fetchDbData.d.ts.map +0 -1
- package/dist/types/src/browser/item/all/actors/fetchRelatedItems.d.ts.map +0 -1
- package/dist/types/src/browser/item/all/actors/fetchSeeds.d.ts +0 -2
- package/dist/types/src/browser/item/all/actors/fetchSeeds.d.ts.map +0 -1
- package/dist/types/src/browser/item/all/actors/fetchVersions.d.ts +0 -2
- package/dist/types/src/browser/item/all/actors/fetchVersions.d.ts.map +0 -1
- package/dist/types/src/browser/item/all/actors/initialize.d.ts.map +0 -1
- package/dist/types/src/browser/item/all/actors/processItems.d.ts +0 -2
- package/dist/types/src/browser/item/all/actors/processItems.d.ts.map +0 -1
- package/dist/types/src/browser/item/all/itemMachineAll.d.ts +0 -2
- package/dist/types/src/browser/item/all/itemMachineAll.d.ts.map +0 -1
- package/dist/types/src/browser/item/index.d.ts +0 -3
- package/dist/types/src/browser/item/index.d.ts.map +0 -1
- package/dist/types/src/browser/property/index.d.ts.map +0 -1
- package/dist/types/src/init.d.ts +0 -6
- package/dist/types/src/init.d.ts.map +0 -1
- package/dist/types/src/seed.d.ts +0 -1
- package/dist/types/src/seed.d.ts.map +0 -1
- /package/dist/types/src/browser/{item → Item}/Item.d.ts +0 -0
- /package/dist/types/src/node/{item → Item}/Item.d.ts +0 -0
- /package/dist/types/src/{browser/item/all → services/allItems}/actors/fetchRelatedItems.d.ts +0 -0
- /package/dist/types/src/{browser/item/all → services/allItems}/actors/initialize.d.ts +0 -0
package/dist/main.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { a as ImageSrc, I as Item, b as ItemProperty, J as Json, L as List, M as Model, P as Property, R as Relation, T as Text, l as client, n as eventEmitter, m as getCorrectId, k as getGlobalService, e as useCreateItem, g as useDeleteItem, h as useGlobalServiceStatus, c as useItem, d as useItemProperties, f as useItemProperty, u as useItems, j as useServices, w as withSeed } from './index-DaK2dz5P.js';
|
|
2
1
|
import 'immer';
|
|
3
2
|
import 'reflect-metadata';
|
|
3
|
+
export { l as BaseArweaveClient, m as BaseEasClient, n as BaseFileManager, o as BaseQueryClient, a as ImageSrc, I as Item, b as ItemProperty, J as Json, L as List, M as Model, P as Property, R as Relation, T as Text, q as client, p as eventEmitter, k as getCorrectId, j as getGlobalService, e as useCreateItem, g as useDeleteItem, h as useGlobalServiceStatus, c as useItem, d as useItemProperties, f as useItemProperty, u as useItems, i as useServices, w as withSeed } from './index-DIlkGqpY.js';
|
|
4
4
|
import 'tslib';
|
|
5
5
|
import 'xstate';
|
|
6
6
|
import 'arweave';
|
|
@@ -18,9 +18,8 @@ import 'react';
|
|
|
18
18
|
import 'pluralize';
|
|
19
19
|
import 'eventemitter3';
|
|
20
20
|
import 'lodash-es';
|
|
21
|
-
import './constants-
|
|
21
|
+
import './constants-yM3e1D1k.js';
|
|
22
22
|
import '@ethereum-attestation-service/eas-sdk';
|
|
23
|
-
import 'thirdweb';
|
|
24
23
|
import '@statelyai/inspect';
|
|
25
24
|
import 'drizzle-orm/sqlite-proxy';
|
|
26
25
|
import 'drizzle-orm/sqlite-proxy/migrator';
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"main.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
2
|
import 'drizzle-orm';
|
|
3
|
-
import { T as Text, M as Model } from './index-
|
|
3
|
+
import { T as Text, M as Model } from './index-DIlkGqpY.js';
|
|
4
4
|
import 'react';
|
|
5
5
|
import 'reflect-metadata';
|
|
6
6
|
import 'xstate';
|
|
7
7
|
import 'arweave';
|
|
8
|
-
import '
|
|
9
|
-
import '@zenfs/dom';
|
|
8
|
+
import 'immer';
|
|
10
9
|
import '@sinclair/typebox';
|
|
11
10
|
import 'rxjs';
|
|
12
|
-
import '
|
|
11
|
+
import '@zenfs/core';
|
|
13
12
|
import 'dayjs';
|
|
14
13
|
import 'nanoid';
|
|
15
14
|
import 'nanoid-dictionary';
|
|
@@ -19,14 +18,14 @@ import 'path';
|
|
|
19
18
|
import 'pluralize';
|
|
20
19
|
import 'eventemitter3';
|
|
21
20
|
import 'lodash-es';
|
|
22
|
-
import './constants-
|
|
21
|
+
import './constants-yM3e1D1k.js';
|
|
23
22
|
import '@ethereum-attestation-service/eas-sdk';
|
|
24
|
-
import 'thirdweb';
|
|
25
23
|
import '@statelyai/inspect';
|
|
26
24
|
import 'drizzle-orm/sqlite-proxy';
|
|
27
25
|
import 'drizzle-orm/sqlite-proxy/migrator';
|
|
28
26
|
import 'drizzle-orm/migrator';
|
|
29
27
|
import 'node:fs';
|
|
28
|
+
import '@zenfs/dom';
|
|
30
29
|
import 'use-immer';
|
|
31
30
|
import '@xstate/react';
|
|
32
31
|
import 'lodash';
|
|
@@ -77,4 +76,4 @@ const models = {
|
|
|
77
76
|
};
|
|
78
77
|
|
|
79
78
|
export { models };
|
|
80
|
-
//# sourceMappingURL=seed.schema.config-
|
|
79
|
+
//# sourceMappingURL=seed.schema.config-Du8pUTQu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed.schema.config-Du8pUTQu.js","sources":["../../src/shared/configs/seed.schema.config.ts"],"sourcesContent":["import { Model, Text } from '@/browser'\n\n@Model\nclass Seed {\n @Text() uid!: string\n @Text() type!: string\n}\n\n@Model\nclass Version {\n @Text() seedUid!: string\n @Text() note!: string\n}\n\n@Model\nclass Metadata {\n @Text() key!: string\n @Text() value!: string\n}\n\nexport const models = {\n Seed,\n Version,\n Metadata,\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAM,IAAI,GAAV,MAAM,IAAI,CAAA;CAGT;AAFS,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAa,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,KAAA,EAAA,KAAA,CAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAc,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,CAAA,CAAA;AAFjB,IAAI,GAAA,UAAA,CAAA;IADT;AACK,CAAA,EAAA,IAAI,CAGT;AAGD,IAAM,OAAO,GAAb,MAAM,OAAO,CAAA;CAGZ;AAFS,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAiB,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,SAAA,EAAA,KAAA,CAAA,CAAA;AAChB,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAc,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,CAAA,CAAA;AAFjB,OAAO,GAAA,UAAA,CAAA;IADZ;AACK,CAAA,EAAA,OAAO,CAGZ;AAGD,IAAM,QAAQ,GAAd,MAAM,QAAQ,CAAA;CAGb;AAFS,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAa,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,KAAA,EAAA,KAAA,CAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAe,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,OAAA,EAAA,KAAA,CAAA,CAAA;AAFlB,QAAQ,GAAA,UAAA,CAAA;IADb;AACK,CAAA,EAAA,QAAQ,CAGb;AAEY,MAAA,MAAM,GAAG;IACpB,IAAI;IACJ,OAAO;IACP,QAAQ;;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ActorRefFrom, createActor, SnapshotFrom, Subscription, waitFor } from 'xstate'
|
|
2
2
|
import { BehaviorSubject, Subscriber } from 'rxjs'
|
|
3
3
|
import { Static } from '@sinclair/typebox'
|
|
4
|
-
import { ItemProperty, TProperty } from '@/browser/
|
|
4
|
+
import { ItemProperty, TProperty } from '@/browser/ItemProperty'
|
|
5
5
|
import { IItemProperty } from '@/interfaces/IItemProperty'
|
|
6
6
|
import { immerable } from 'immer'
|
|
7
7
|
import { CreatePropertyInstanceProps, PropertyMachineContext } from '@/types'
|
|
@@ -2,7 +2,7 @@ import { ActorRefFrom, Subscription } from 'xstate';
|
|
|
2
2
|
import { PropertyMachineContext } from '@/types';
|
|
3
3
|
import { BehaviorSubject } from 'rxjs';
|
|
4
4
|
import { Static } from '@sinclair/typebox';
|
|
5
|
-
import { TProperty } from '@/browser/
|
|
5
|
+
import { TProperty } from '@/browser/ItemProperty';
|
|
6
6
|
|
|
7
7
|
export interface IItemProperty<PropertyType> {
|
|
8
8
|
readonly localId: string;
|
package/dist/src/ItemProperty.ts
CHANGED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { CreatePropertyInstanceProps, PropertyType } from '@/types'
|
|
2
|
-
import { IItemProperty } from '@/interfaces/IItemProperty'
|
|
3
|
-
import { BaseItemProperty } from '@/ItemProperty/BaseItemProperty'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export class ItemProperty extends BaseItemProperty<PropertyType> implements IItemProperty<PropertyType> {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
constructor(initialValues: Partial<CreatePropertyInstanceProps>) {
|
|
11
|
-
super(initialValues)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
BaseItemProperty.setPlatformClass(ItemProperty)
|
package/dist/src/client.ts
CHANGED
|
@@ -12,9 +12,15 @@ import {
|
|
|
12
12
|
} from '@/stores/modelClass'
|
|
13
13
|
import { setupServiceHandlers } from '@/events/services'
|
|
14
14
|
import { setArweaveDomain } from '@/browser/helpers/arweave'
|
|
15
|
+
import { initItem } from './Item'
|
|
16
|
+
import { initItemProperty } from './ItemProperty'
|
|
15
17
|
|
|
16
18
|
const client = {
|
|
17
|
-
init: ({ config, addresses }: SeedConstructorOptions) => {
|
|
19
|
+
init: async ({ config, addresses }: Promise<SeedConstructorOptions>) => {
|
|
20
|
+
|
|
21
|
+
await initItem()
|
|
22
|
+
await initItemProperty()
|
|
23
|
+
|
|
18
24
|
const { endpoints, models, arweaveDomain } = config
|
|
19
25
|
|
|
20
26
|
if (arweaveDomain) {
|
|
@@ -41,11 +47,11 @@ const client = {
|
|
|
41
47
|
addresses,
|
|
42
48
|
arweaveDomain,
|
|
43
49
|
})
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
50
|
+
|
|
51
|
+
const { models: internalModels } = await import('@/shared/configs/seed.schema.config')
|
|
52
|
+
for (const [key, value] of Object.entries(internalModels)) {
|
|
53
|
+
setModel(key, value)
|
|
54
|
+
}
|
|
49
55
|
},
|
|
50
56
|
subscribe: (callback: any) => {
|
|
51
57
|
callback({
|
package/dist/src/create.ts
CHANGED
package/dist/src/fetchDbData.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { EventObject, fromCallback } from 'xstate'
|
|
2
|
-
import {
|
|
2
|
+
import { AllItemsMachineContext, FromCallbackInput } from '@/types'
|
|
3
3
|
|
|
4
|
-
export const fetchDbData = fromCallback<
|
|
4
|
+
export const fetchDbData = fromCallback<
|
|
5
|
+
EventObject,
|
|
6
|
+
FromCallbackInput<EventObject, AllItemsMachineContext>
|
|
7
|
+
>(
|
|
5
8
|
({ sendBack, input: { context } }) => {
|
|
6
9
|
const { modelNamePlural, times } = context
|
|
7
10
|
|
|
8
|
-
const _fetchDbData = async (): Promise<void> => {}
|
|
11
|
+
const _fetchDbData = async (): Promise<void> => { }
|
|
9
12
|
|
|
10
13
|
_fetchDbData().then(() => {
|
|
11
14
|
sendBack({ type: 'fetchDbDataSuccess' })
|
|
12
15
|
})
|
|
13
16
|
|
|
14
|
-
return () => {}
|
|
17
|
+
return () => { }
|
|
15
18
|
},
|
|
16
19
|
)
|
package/dist/src/fetchSeeds.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventObject, fromCallback } from 'xstate'
|
|
2
2
|
import { GET_SEEDS } from '@/Item/queries'
|
|
3
|
-
import {
|
|
3
|
+
import { AllItemsMachineContext, FromCallbackInput } from '@/types'
|
|
4
4
|
import { Attestation } from '@/graphql/gql/graphql'
|
|
5
5
|
import { BaseEasClient } from '@/helpers/BaseEasClient'
|
|
6
6
|
import { BaseQueryClient } from '@/helpers/BaseQueryClient'
|
|
@@ -11,7 +11,10 @@ const queryClient = BaseQueryClient.getQueryClient()
|
|
|
11
11
|
|
|
12
12
|
const logger = debug('app:allItemsActors:fetchSeeds')
|
|
13
13
|
|
|
14
|
-
export const fetchSeeds = fromCallback<
|
|
14
|
+
export const fetchSeeds = fromCallback<
|
|
15
|
+
EventObject,
|
|
16
|
+
FromCallbackInput<EventObject, AllItemsMachineContext>
|
|
17
|
+
>(
|
|
15
18
|
({ sendBack, input: { context } }) => {
|
|
16
19
|
const { queryVariables, modelName } = context
|
|
17
20
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventObject, fromCallback } from 'xstate'
|
|
2
2
|
import { GET_VERSIONS } from '@/Item/queries'
|
|
3
|
-
import {
|
|
3
|
+
import { AllItemsMachineContext, FromCallbackInput } from '@/types'
|
|
4
4
|
import { Attestation } from '@/graphql/gql/graphql'
|
|
5
5
|
import { BaseEasClient } from '@/helpers/BaseEasClient'
|
|
6
6
|
import { BaseQueryClient } from '@/helpers/BaseQueryClient'
|
|
@@ -9,7 +9,10 @@ const easClient = BaseEasClient.getEasClient()
|
|
|
9
9
|
const queryClient = BaseQueryClient.getQueryClient()
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
export const fetchVersions = fromCallback<
|
|
12
|
+
export const fetchVersions = fromCallback<
|
|
13
|
+
EventObject,
|
|
14
|
+
FromCallbackInput<EventObject, AllItemsMachineContext>
|
|
15
|
+
>(
|
|
13
16
|
({ sendBack, input: { context } }) => {
|
|
14
17
|
const { itemSeeds, modelName } = context
|
|
15
18
|
|
package/dist/src/getItem.ts
CHANGED
|
@@ -16,7 +16,7 @@ import pluralize from 'pluralize'
|
|
|
16
16
|
import { getSchemaUidForModel } from '@/db/read/getSchemaUidForModel'
|
|
17
17
|
import { getSchemaUidForSchemaDefinition } from '@/stores/eas'
|
|
18
18
|
import { getCorrectId } from '@/helpers'
|
|
19
|
-
import { Item } from '@/browser/
|
|
19
|
+
import { Item } from '@/browser/Item/Item'
|
|
20
20
|
import { getSegmentedItemProperties } from '@/helpers/getSegmentedItemProperties'
|
|
21
21
|
import { IItemProperty } from '@/interfaces'
|
|
22
22
|
|
|
@@ -14,7 +14,7 @@ import { initialize } from '@/services/global/actors/initialize'
|
|
|
14
14
|
import { getSchemaForModel } from '@/services/global/actors/getSchemaForModel'
|
|
15
15
|
import { addModelsToDb } from '@/services/global/actors/addModelsToDb'
|
|
16
16
|
import { internalMachine } from '@/services/internal/internalMachine'
|
|
17
|
-
import { itemMachineAll } from '
|
|
17
|
+
import { itemMachineAll } from '../allItems/itemMachineAll'
|
|
18
18
|
import { publishMachine } from '@/services/publish/publishMachine'
|
|
19
19
|
import { savePublishService } from '@/services/global/actors/savePublishService'
|
|
20
20
|
|
|
@@ -274,7 +274,7 @@ export const hydrateFromDb = fromCallback<
|
|
|
274
274
|
propertyRecordSchema.storageType &&
|
|
275
275
|
propertyRecordSchema.storageType === 'ItemStorage'
|
|
276
276
|
) {
|
|
277
|
-
const { Item } = await import(`@/browser/
|
|
277
|
+
const { Item } = await import(`@/browser/Item`)
|
|
278
278
|
const item = await Item.find({
|
|
279
279
|
seedLocalId,
|
|
280
280
|
modelName,
|
package/dist/src/index.ts
CHANGED
|
@@ -1,21 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from '@/browser/schema/file/upload/actors'
|
|
6
|
-
|
|
7
|
-
export const uploadMachine = setup({
|
|
8
|
-
actors: {
|
|
9
|
-
uploadBinaryData,
|
|
10
|
-
uploadMetadata,
|
|
11
|
-
},
|
|
12
|
-
}).createMachine({
|
|
13
|
-
id: 'upload',
|
|
14
|
-
initial: 'idle',
|
|
15
|
-
context: {
|
|
16
|
-
file: '',
|
|
17
|
-
},
|
|
18
|
-
states: {
|
|
19
|
-
idle: {},
|
|
20
|
-
},
|
|
21
|
-
})
|
|
1
|
+
export * from './analyzeInput'
|
|
2
|
+
export * from './saveImageSrc'
|
|
3
|
+
export * from './saveRelation'
|
|
4
|
+
export * from './saveItemStorage'
|
package/dist/src/initialize.ts
CHANGED
|
@@ -1,277 +1,127 @@
|
|
|
1
|
-
import { EventObject, fromCallback } from 'xstate'
|
|
2
|
-
import {
|
|
3
|
-
import pluralize from 'pluralize'
|
|
4
|
-
import { BaseEasClient } from '@/helpers/BaseEasClient'
|
|
5
|
-
import { BaseQueryClient } from '@/helpers/BaseQueryClient'
|
|
6
|
-
import { toSnakeCase } from '@/helpers'
|
|
1
|
+
import { EventObject, fromCallback, Subscription } from 'xstate'
|
|
2
|
+
import { isNode, isReactNative } from '@/shared'
|
|
7
3
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
import { SchemaWhereInput } from '@/graphql/gql/graphql'
|
|
15
|
-
import { INTERNAL_DATA_TYPES } from '@/helpers/constants'
|
|
16
|
-
import { getAddressesFromDb } from '@/helpers/db'
|
|
17
|
-
import { eventEmitter } from '@/eventBus'
|
|
4
|
+
GLOBAL_INITIALIZING_CREATE_ALL_ITEMS_SERVICES,
|
|
5
|
+
GLOBAL_INITIALIZING_INTERNAL_SERVICE_READY,
|
|
6
|
+
GLOBAL_INITIALIZING_SEND_CONFIG,
|
|
7
|
+
} from '@/services/internal/constants'
|
|
8
|
+
import debug from 'debug'
|
|
9
|
+
import { FromCallbackInput, GlobalMachineContext } from '@/types'
|
|
18
10
|
import { BaseDb } from '@/db/BaseDb'
|
|
11
|
+
import { appState } from '@/seedSchema'
|
|
12
|
+
import { like } from 'drizzle-orm'
|
|
13
|
+
import { fetchSchemaUids } from '@/stores/eas'
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const easClient = BaseEasClient.getEasClient()
|
|
23
|
-
const queryClient = BaseQueryClient.getQueryClient()
|
|
24
|
-
|
|
25
|
-
type Times = {
|
|
26
|
-
initialize?: {
|
|
27
|
-
start: number | null
|
|
28
|
-
end: number | null
|
|
29
|
-
}
|
|
30
|
-
fetchDbData?: {
|
|
31
|
-
start: number | null
|
|
32
|
-
end: number | null
|
|
33
|
-
}
|
|
34
|
-
fetchSeeds?: {
|
|
35
|
-
start: number | null
|
|
36
|
-
end: number | null
|
|
37
|
-
}
|
|
38
|
-
fetchVersions?: {
|
|
39
|
-
start: number | null
|
|
40
|
-
end: number | null
|
|
41
|
-
}
|
|
42
|
-
fetchRelatedItems?: {
|
|
43
|
-
start: number | null
|
|
44
|
-
end: number | null
|
|
45
|
-
}
|
|
46
|
-
processItems?: {
|
|
47
|
-
start: number | null
|
|
48
|
-
end: number | null
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
type InternalDataType = keyof typeof INTERNAL_DATA_TYPES;
|
|
15
|
+
const logger = debug('app:services:global:actors:initialize')
|
|
53
16
|
|
|
54
17
|
export const initialize = fromCallback<
|
|
55
18
|
EventObject,
|
|
56
|
-
FromCallbackInput<
|
|
57
|
-
>(({ sendBack, input: { context } }) => {
|
|
58
|
-
const {
|
|
59
|
-
|
|
60
|
-
const newTimes: Times = {
|
|
61
|
-
initialize: {
|
|
62
|
-
start: Date.now(),
|
|
63
|
-
end: null,
|
|
64
|
-
},
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
let modelNameLowercase: string | undefined
|
|
68
|
-
let modelNamePlural: string | undefined
|
|
69
|
-
let queryVariables: Record<string, unknown> | undefined
|
|
70
|
-
let appDb
|
|
19
|
+
FromCallbackInput<GlobalMachineContext, EventObject>
|
|
20
|
+
>(({ sendBack, input: { event, context } }) => {
|
|
21
|
+
const { internalService, models, endpoints, arweaveDomain } = context
|
|
71
22
|
|
|
72
|
-
const
|
|
73
|
-
appDb = BaseDb.getAppDb()
|
|
23
|
+
const { addresses } = event
|
|
74
24
|
|
|
75
|
-
|
|
76
|
-
//
|
|
77
|
-
// if (rows && rows.length > 0) {
|
|
78
|
-
// for (const itemData of rows) {
|
|
79
|
-
// const {
|
|
80
|
-
// versionLocalId,
|
|
81
|
-
// versionUid,
|
|
82
|
-
// createdAt,
|
|
83
|
-
// seedLocalId,
|
|
84
|
-
// seedUid,
|
|
85
|
-
// attestationCreatedAt,
|
|
86
|
-
// } = itemData
|
|
87
|
-
//
|
|
88
|
-
// eventEmitter.emit('item.create.request', {
|
|
89
|
-
// itemData: {
|
|
90
|
-
// versionLocalId,
|
|
91
|
-
// versionUid,
|
|
92
|
-
// createdAt,
|
|
93
|
-
// seedLocalId,
|
|
94
|
-
// seedUid,
|
|
95
|
-
// attestationCreatedAt,
|
|
96
|
-
// },
|
|
97
|
-
// ModelClass,
|
|
98
|
-
// })
|
|
99
|
-
// }
|
|
100
|
-
// }
|
|
25
|
+
let environment = 'browser'
|
|
101
26
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const modelSchemas = await queryClient.fetchQuery({
|
|
106
|
-
queryKey: [`getSchemas${modelName}`],
|
|
107
|
-
queryFn: async () =>
|
|
108
|
-
easClient.request(GET_SCHEMAS, {
|
|
109
|
-
where: {
|
|
110
|
-
schema: {
|
|
111
|
-
equals: `bytes32 ${toSnakeCase(modelName)}`,
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
}),
|
|
115
|
-
})
|
|
27
|
+
if (isNode()) {
|
|
28
|
+
environment = 'node'
|
|
29
|
+
}
|
|
116
30
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
modelSchemas.schemas.length === 0
|
|
121
|
-
) {
|
|
122
|
-
throw new Error(`No schema found for ${modelName}`)
|
|
123
|
-
}
|
|
31
|
+
if (isReactNative()) {
|
|
32
|
+
environment = 'react-native'
|
|
33
|
+
}
|
|
124
34
|
|
|
125
|
-
|
|
35
|
+
let internalSubscription: Subscription | undefined
|
|
36
|
+
let easSubscription: Subscription | undefined
|
|
126
37
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
)
|
|
38
|
+
if (environment === 'browser' && models) {
|
|
39
|
+
const _initFileSystem = async (): Promise<void> => {
|
|
40
|
+
return
|
|
41
|
+
// return new Promise((resolve) => {
|
|
42
|
+
// })
|
|
131
43
|
}
|
|
132
44
|
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
45
|
+
const _initInternal = async (): Promise<void> => {
|
|
46
|
+
return new Promise((resolve) => {
|
|
47
|
+
internalSubscription = internalService.subscribe((snapshot) => {
|
|
48
|
+
logger('[sdk] [internal] snapshot', snapshot)
|
|
49
|
+
if (snapshot.value === 'ready') {
|
|
50
|
+
resolve()
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
internalService.send({
|
|
54
|
+
type: 'init',
|
|
55
|
+
endpoints,
|
|
56
|
+
addresses,
|
|
57
|
+
arweaveDomain,
|
|
58
|
+
})
|
|
138
59
|
})
|
|
139
|
-
.from(modelsTable)
|
|
140
|
-
.leftJoin(modelUids, eq(modelsTable.id, modelUids.modelId))
|
|
141
|
-
.where(eq(modelsTable.name, modelName))
|
|
142
|
-
.limit(1)
|
|
143
|
-
|
|
144
|
-
const foundModel = foundModels[0]
|
|
145
|
-
|
|
146
|
-
if (!foundModel) {
|
|
147
|
-
sendBack({ type: 'modelNotFound', modelName })
|
|
148
|
-
return
|
|
149
60
|
}
|
|
150
61
|
|
|
151
|
-
|
|
152
|
-
.
|
|
153
|
-
.values({
|
|
154
|
-
modelId: foundModel.id,
|
|
155
|
-
uid: modelSchema.id,
|
|
156
|
-
})
|
|
157
|
-
.onConflictDoNothing()
|
|
62
|
+
const _initAllItemsServices = async (): Promise<void> => {
|
|
63
|
+
const appDb = BaseDb.getAppDb()
|
|
158
64
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
dataType: properties.dataType,
|
|
164
|
-
uid: propertyUids.uid,
|
|
165
|
-
})
|
|
166
|
-
.from(properties)
|
|
167
|
-
.fullJoin(propertyUids, eq(properties.id, propertyUids.propertyId))
|
|
168
|
-
.where(eq(properties.modelId, foundModel.id))
|
|
65
|
+
const rows = await appDb
|
|
66
|
+
.select()
|
|
67
|
+
.from(appState)
|
|
68
|
+
.where(like(appState.key, 'snapshot__%'))
|
|
169
69
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
OR: [],
|
|
174
|
-
},
|
|
70
|
+
const payloadObj = {
|
|
71
|
+
create: {},
|
|
72
|
+
restore: {},
|
|
175
73
|
}
|
|
176
74
|
|
|
177
|
-
|
|
178
|
-
if (foundPropertyDb.name && foundPropertyDb.dataType) {
|
|
179
|
-
const easDatatype = INTERNAL_DATA_TYPES[foundPropertyDb.dataType as InternalDataType].eas
|
|
75
|
+
const modelNamesRestored: string[] = []
|
|
180
76
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
queryVariables.where.OR!.push({
|
|
188
|
-
schema: {
|
|
189
|
-
equals: `${easDatatype} ${easPropertyName}`,
|
|
190
|
-
},
|
|
191
|
-
})
|
|
77
|
+
if (rows && rows.length > 0) {
|
|
78
|
+
for (const row of rows) {
|
|
79
|
+
const modelName = row.key.replace('snapshot__', '')
|
|
80
|
+
payloadObj.restore[modelName] = JSON.parse(row.value)
|
|
81
|
+
modelNamesRestored.push(modelName)
|
|
192
82
|
}
|
|
193
83
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
queryFn: async () => easClient.request(GET_SCHEMAS, queryVariables),
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
const tempExclusions = ['html', 'json']
|
|
201
|
-
|
|
202
|
-
for (const foundProperty of foundPropertiesDb) {
|
|
203
|
-
if (tempExclusions.includes(foundProperty.name)) {
|
|
204
|
-
continue
|
|
205
|
-
}
|
|
206
|
-
const easDatatype = INTERNAL_DATA_TYPES[foundProperty.dataType as InternalDataType].eas
|
|
207
|
-
|
|
208
|
-
let easPropertyName = toSnakeCase(foundProperty.name)
|
|
209
|
-
|
|
210
|
-
if (foundProperty.dataType === 'Relation') {
|
|
211
|
-
easPropertyName += '_id'
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const regex = new RegExp(`${easDatatype} ${easPropertyName}`)
|
|
215
|
-
const propertySchema = foundPropertySchemas.schemas.find((s) =>
|
|
216
|
-
regex.test(s.schema),
|
|
217
|
-
)
|
|
218
|
-
|
|
219
|
-
if (!propertySchema) {
|
|
220
|
-
// TODO: We should create the schema here?
|
|
221
|
-
continue
|
|
84
|
+
for (const [modelName, ModelClass] of Object.entries(models)) {
|
|
85
|
+
if (!modelNamesRestored.includes(modelName)) {
|
|
86
|
+
payloadObj.create[modelName] = ModelClass
|
|
222
87
|
}
|
|
223
|
-
await appDb
|
|
224
|
-
.insert(propertyUids)
|
|
225
|
-
.values({
|
|
226
|
-
propertyId: foundProperty.id,
|
|
227
|
-
uid: propertySchema.id,
|
|
228
|
-
})
|
|
229
|
-
.onConflictDoNothing()
|
|
230
88
|
}
|
|
89
|
+
sendBack({
|
|
90
|
+
type: GLOBAL_INITIALIZING_CREATE_ALL_ITEMS_SERVICES,
|
|
91
|
+
...payloadObj,
|
|
92
|
+
})
|
|
231
93
|
}
|
|
232
94
|
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
queryVariables = {
|
|
236
|
-
where: {
|
|
237
|
-
attester: {
|
|
238
|
-
in: addresses,
|
|
239
|
-
},
|
|
240
|
-
schemaId: {
|
|
241
|
-
equals: modelSchema.id,
|
|
242
|
-
},
|
|
243
|
-
decodedDataJson: {
|
|
244
|
-
contains: modelSchema.id,
|
|
245
|
-
},
|
|
246
|
-
},
|
|
95
|
+
const _initEas = async (): Promise<void> => {
|
|
96
|
+
await fetchSchemaUids()
|
|
247
97
|
}
|
|
248
|
-
}
|
|
249
98
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
sendBack({
|
|
253
|
-
type: 'initializeSuccess',
|
|
254
|
-
modelName,
|
|
255
|
-
modelNameLowercase,
|
|
256
|
-
modelNamePlural,
|
|
257
|
-
queryVariables,
|
|
258
|
-
})
|
|
259
|
-
newTimes!.initialize!.end = Date.now()
|
|
260
|
-
sendBack({ type: 'updateTimes', times: newTimes })
|
|
99
|
+
_initFileSystem().then(() => {
|
|
100
|
+
logger('[global/actors] File system initialized')
|
|
261
101
|
})
|
|
262
|
-
}
|
|
263
102
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
103
|
+
_initInternal()
|
|
104
|
+
.then(() => {
|
|
105
|
+
return _initAllItemsServices()
|
|
106
|
+
})
|
|
107
|
+
.then(() => {
|
|
108
|
+
return _initEas()
|
|
109
|
+
})
|
|
110
|
+
.then(() => {
|
|
111
|
+
logger('[global/actors] Internal initialized')
|
|
112
|
+
sendBack({ type: GLOBAL_INITIALIZING_INTERNAL_SERVICE_READY })
|
|
113
|
+
internalSubscription?.unsubscribe()
|
|
114
|
+
})
|
|
267
115
|
|
|
268
|
-
|
|
269
|
-
|
|
116
|
+
// _initEas().then(() => {
|
|
117
|
+
// logger('EAS initialized')
|
|
118
|
+
// })
|
|
270
119
|
}
|
|
271
120
|
|
|
272
|
-
|
|
121
|
+
sendBack({ type: GLOBAL_INITIALIZING_SEND_CONFIG, environment })
|
|
273
122
|
|
|
274
123
|
return () => {
|
|
275
|
-
|
|
124
|
+
internalSubscription?.unsubscribe()
|
|
125
|
+
easSubscription?.unsubscribe()
|
|
276
126
|
}
|
|
277
127
|
})
|