@seedprotocol/sdk 0.2.1 → 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.
Files changed (114) hide show
  1. package/dist/Item-EuINlFXI.js +41 -0
  2. package/dist/Item-EuINlFXI.js.map +1 -0
  3. package/dist/ItemProperty-l0sNRNKZ.js +2 -0
  4. package/dist/ItemProperty-l0sNRNKZ.js.map +1 -0
  5. package/dist/bin.js +1 -2
  6. package/dist/bin.js.map +1 -1
  7. package/dist/{constants-B6s6tGup.js → constants-yM3e1D1k.js} +2 -3
  8. package/dist/constants-yM3e1D1k.js.map +1 -0
  9. package/dist/{index-B5qzD-bs.js → index-C9eVIXxd.js} +5 -6
  10. package/dist/index-C9eVIXxd.js.map +1 -0
  11. package/dist/{index-DaK2dz5P.js → index-DIlkGqpY.js} +221 -223
  12. package/dist/index-DIlkGqpY.js.map +1 -0
  13. package/dist/main.js +2 -3
  14. package/dist/main.js.map +1 -1
  15. package/dist/{seed.schema.config-DIMmvqJf.js → seed.schema.config-Du8pUTQu.js} +6 -7
  16. package/dist/seed.schema.config-Du8pUTQu.js.map +1 -0
  17. package/dist/src/BaseItemProperty.ts +1 -1
  18. package/dist/src/IItemProperty.ts +1 -1
  19. package/dist/src/ItemProperty.ts +0 -16
  20. package/dist/src/SeedProtocolSdk.d.ts +1 -1
  21. package/dist/src/client.ts +12 -6
  22. package/dist/src/create.ts +1 -1
  23. package/dist/src/fetchDbData.ts +7 -4
  24. package/dist/src/fetchSeeds.ts +5 -2
  25. package/dist/src/fetchVersions.ts +5 -2
  26. package/dist/src/getItem.ts +1 -1
  27. package/dist/src/getPublishPayload.ts +1 -1
  28. package/dist/src/globalMachine.ts +1 -1
  29. package/dist/src/hydrateFromDb.ts +1 -1
  30. package/dist/src/index.ts +4 -21
  31. package/dist/src/initialize.ts +88 -238
  32. package/dist/src/itemMachineAll.ts +6 -7
  33. package/dist/src/preparePublishRequestData.ts +1 -1
  34. package/dist/src/processItems.ts +5 -2
  35. package/dist/src/property.ts +2 -2
  36. package/dist/src/requestAll.ts +1 -1
  37. package/dist/src/trash.ts +1 -1
  38. package/dist/types/src/Item/index.d.ts +5 -0
  39. package/dist/types/src/Item/index.d.ts.map +1 -0
  40. package/dist/types/src/ItemProperty/BaseItemProperty.d.ts +1 -1
  41. package/dist/types/src/ItemProperty/BaseItemProperty.d.ts.map +1 -1
  42. package/dist/types/src/ItemProperty/index.d.ts +5 -0
  43. package/dist/types/src/ItemProperty/index.d.ts.map +1 -0
  44. package/dist/types/src/browser/{item → Item}/Item.d.ts.map +1 -1
  45. package/dist/types/src/browser/Item/index.d.ts +2 -0
  46. package/dist/types/src/browser/Item/index.d.ts.map +1 -0
  47. package/dist/types/src/browser/{item → ItemProperty}/ItemProperty.d.ts +2 -1
  48. package/dist/types/src/browser/ItemProperty/ItemProperty.d.ts.map +1 -0
  49. package/dist/types/src/browser/{property → ItemProperty}/index.d.ts +1 -1
  50. package/dist/types/src/browser/ItemProperty/index.d.ts.map +1 -0
  51. package/dist/types/src/browser/index.d.ts +2 -3
  52. package/dist/types/src/browser/index.d.ts.map +1 -1
  53. package/dist/types/src/browser/react/item.d.ts +1 -1
  54. package/dist/types/src/browser/react/property.d.ts +1 -1
  55. package/dist/types/src/browser/react/trash.d.ts +1 -1
  56. package/dist/types/src/browser/schema/index.d.ts +2 -2
  57. package/dist/types/src/browser/schema/index.d.ts.map +1 -1
  58. package/dist/types/src/browser/schema/model/index.d.ts +1 -1
  59. package/dist/types/src/{browser/client.d.ts → client.d.ts} +1 -1
  60. package/dist/types/src/client.d.ts.map +1 -0
  61. package/dist/types/src/db/read/getPublishPayload.d.ts +1 -1
  62. package/dist/types/src/helpers/constants.d.ts.map +1 -1
  63. package/dist/types/src/index.d.ts +4 -4
  64. package/dist/types/src/index.d.ts.map +1 -1
  65. package/dist/types/src/interfaces/IItemProperty.d.ts +1 -1
  66. package/dist/types/src/interfaces/IItemProperty.d.ts.map +1 -1
  67. package/dist/types/src/node/{item → Item}/Item.d.ts.map +1 -1
  68. package/dist/types/src/node/ItemProperty/ItemProperty.d.ts +1 -0
  69. package/dist/types/src/node/ItemProperty/ItemProperty.d.ts.map +1 -0
  70. package/dist/types/src/services/allItems/actors/fetchDbData.d.ts +4 -0
  71. package/dist/types/src/services/allItems/actors/fetchDbData.d.ts.map +1 -0
  72. package/dist/types/src/services/allItems/actors/fetchRelatedItems.d.ts.map +1 -0
  73. package/dist/types/src/services/allItems/actors/fetchSeeds.d.ts +4 -0
  74. package/dist/types/src/services/allItems/actors/fetchSeeds.d.ts.map +1 -0
  75. package/dist/types/src/services/allItems/actors/fetchVersions.d.ts +4 -0
  76. package/dist/types/src/services/allItems/actors/fetchVersions.d.ts.map +1 -0
  77. package/dist/types/src/services/allItems/actors/initialize.d.ts.map +1 -0
  78. package/dist/types/src/services/allItems/actors/processItems.d.ts +4 -0
  79. package/dist/types/src/services/allItems/actors/processItems.d.ts.map +1 -0
  80. package/dist/types/src/services/allItems/itemMachineAll.d.ts +67 -0
  81. package/dist/types/src/services/allItems/itemMachineAll.d.ts.map +1 -0
  82. package/dist/types/src/types/item.d.ts +5 -5
  83. package/dist/types/src/types/item.d.ts.map +1 -1
  84. package/package.json +1 -1
  85. package/dist/constants-B6s6tGup.js.map +0 -1
  86. package/dist/index-B5qzD-bs.js.map +0 -1
  87. package/dist/index-DaK2dz5P.js.map +0 -1
  88. package/dist/seed.schema.config-DIMmvqJf.js.map +0 -1
  89. package/dist/src/init.ts +0 -61
  90. package/dist/types/src/browser/client.d.ts.map +0 -1
  91. package/dist/types/src/browser/item/ItemProperty.d.ts.map +0 -1
  92. package/dist/types/src/browser/item/all/actors/fetchDbData.d.ts +0 -2
  93. package/dist/types/src/browser/item/all/actors/fetchDbData.d.ts.map +0 -1
  94. package/dist/types/src/browser/item/all/actors/fetchRelatedItems.d.ts.map +0 -1
  95. package/dist/types/src/browser/item/all/actors/fetchSeeds.d.ts +0 -2
  96. package/dist/types/src/browser/item/all/actors/fetchSeeds.d.ts.map +0 -1
  97. package/dist/types/src/browser/item/all/actors/fetchVersions.d.ts +0 -2
  98. package/dist/types/src/browser/item/all/actors/fetchVersions.d.ts.map +0 -1
  99. package/dist/types/src/browser/item/all/actors/initialize.d.ts.map +0 -1
  100. package/dist/types/src/browser/item/all/actors/processItems.d.ts +0 -2
  101. package/dist/types/src/browser/item/all/actors/processItems.d.ts.map +0 -1
  102. package/dist/types/src/browser/item/all/itemMachineAll.d.ts +0 -2
  103. package/dist/types/src/browser/item/all/itemMachineAll.d.ts.map +0 -1
  104. package/dist/types/src/browser/item/index.d.ts +0 -3
  105. package/dist/types/src/browser/item/index.d.ts.map +0 -1
  106. package/dist/types/src/browser/property/index.d.ts.map +0 -1
  107. package/dist/types/src/init.d.ts +0 -6
  108. package/dist/types/src/init.d.ts.map +0 -1
  109. package/dist/types/src/seed.d.ts +0 -1
  110. package/dist/types/src/seed.d.ts.map +0 -1
  111. /package/dist/types/src/browser/{item → Item}/Item.d.ts +0 -0
  112. /package/dist/types/src/node/{item → Item}/Item.d.ts +0 -0
  113. /package/dist/types/src/{browser/item/all → services/allItems}/actors/fetchRelatedItems.d.ts +0 -0
  114. /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-B6s6tGup.js';
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-DaK2dz5P.js';
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 '@zenfs/core';
9
- import '@zenfs/dom';
8
+ import 'immer';
10
9
  import '@sinclair/typebox';
11
10
  import 'rxjs';
12
- import 'immer';
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-B6s6tGup.js';
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-DIMmvqJf.js.map
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/property'
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/property';
5
+ import { TProperty } from '@/browser/ItemProperty';
6
6
 
7
7
  export interface IItemProperty<PropertyType> {
8
8
  readonly localId: string;
@@ -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)
@@ -1,6 +1,6 @@
1
1
  export interface SeedProtocolSdk {
2
2
  // Exported classes
3
- Item: typeof import('@/browser/item/Item').Item;
3
+ Item: typeof import('@/browser/Item/Item').Item;
4
4
  ItemProperty: typeof import('@/browser/property/ItemProperty').ItemProperty;
5
5
 
6
6
  // Exported hooks
@@ -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
- import('@/shared/configs/seed.schema.config').then(({ models }) => {
45
- for (const [key, value] of Object.entries(models)) {
46
- setModel(key, value)
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({
@@ -1,4 +1,4 @@
1
- import { Item } from 'src/browser/item'
1
+ import { Item } from '@/browser/Item'
2
2
  import { eventEmitter } from '@/eventBus'
3
3
  import { createItemCacheKey, getItemCache, updateItemCache } from './requestAll'
4
4
 
@@ -1,16 +1,19 @@
1
1
  import { EventObject, fromCallback } from 'xstate'
2
- import { itemMachineAll } from '@/browser/item/all/itemMachineAll'
2
+ import { AllItemsMachineContext, FromCallbackInput } from '@/types'
3
3
 
4
- export const fetchDbData = fromCallback<EventObject, typeof itemMachineAll>(
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
  )
@@ -1,6 +1,6 @@
1
1
  import { EventObject, fromCallback } from 'xstate'
2
2
  import { GET_SEEDS } from '@/Item/queries'
3
- import { itemMachineAll } from '@/browser/item/all/itemMachineAll'
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<EventObject, typeof itemMachineAll>(
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 { itemMachineAll } from '@/browser/item/all/itemMachineAll'
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<EventObject, typeof itemMachineAll>(
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
 
@@ -1,4 +1,4 @@
1
- import { Item } from '@/browser/item'
1
+ import { Item } from '@/browser/Item'
2
2
  import { getItemData } from './getItemData'
3
3
  import { GetItem } from '@/types'
4
4
 
@@ -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/item/Item'
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 '@/browser/item/all/itemMachineAll'
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/item`)
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
- import { setup } from 'xstate'
2
- import {
3
- uploadBinaryData,
4
- uploadMetadata,
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'
@@ -1,277 +1,127 @@
1
- import { EventObject, fromCallback } from 'xstate'
2
- import { GET_SCHEMAS } from '@/Item/queries'
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
- models as modelsTable,
9
- modelUids,
10
- properties,
11
- propertyUids,
12
- } from '@/seedSchema'
13
- import { eq } from 'drizzle-orm'
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
- import { AllItemsMachineContext, FromCallbackInput } from '@/types'
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<AllItemsMachineContext>
57
- >(({ sendBack, input: { context } }) => {
58
- const { modelName, modelAddedToDb, ModelClass, times } = context
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 _initialize = async () => {
73
- appDb = BaseDb.getAppDb()
23
+ const { addresses } = event
74
24
 
75
- // const rows = await getItemsDataFromDb(modelName)
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
- modelNameLowercase = modelName.toLowerCase()
103
- modelNamePlural = pluralize(modelNameLowercase!)
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
- if (
118
- !modelSchemas ||
119
- !modelSchemas.schemas ||
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
- const modelSchema = modelSchemas.schemas[0]
35
+ let internalSubscription: Subscription | undefined
36
+ let easSubscription: Subscription | undefined
126
37
 
127
- if (!modelSchema.id) {
128
- throw new Error(
129
- `No schema ID found for schema ${JSON.stringify(modelSchema)}`,
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 foundModels = await appDb
134
- .select({
135
- id: modelsTable.id,
136
- name: modelsTable.name,
137
- uid: modelUids.uid,
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
- await appDb
152
- .insert(modelUids)
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
- const foundPropertiesDb = await appDb
160
- .select({
161
- id: properties.id,
162
- name: properties.name,
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
- if (foundPropertiesDb && foundPropertiesDb.length > 0) {
171
- const queryVariables: { where: SchemaWhereInput } = {
172
- where: {
173
- OR: [],
174
- },
70
+ const payloadObj = {
71
+ create: {},
72
+ restore: {},
175
73
  }
176
74
 
177
- for (const foundPropertyDb of foundPropertiesDb) {
178
- if (foundPropertyDb.name && foundPropertyDb.dataType) {
179
- const easDatatype = INTERNAL_DATA_TYPES[foundPropertyDb.dataType as InternalDataType].eas
75
+ const modelNamesRestored: string[] = []
180
76
 
181
- let easPropertyName = toSnakeCase(foundPropertyDb.name)
182
-
183
- if (foundPropertyDb.dataType === 'Relation') {
184
- easPropertyName += '_id'
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
- const foundPropertySchemas = await queryClient.fetchQuery({
196
- queryKey: [`getPropertySchemas${modelName}`],
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 addresses = await getAddressesFromDb()
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
- const initializeHandler = () => {
251
- _initialize().then(() => {
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
- if (modelAddedToDb) {
265
- initializeHandler()
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
- const dbReadyHandler = (event) => {
269
- initializeHandler()
116
+ // _initEas().then(() => {
117
+ // logger('EAS initialized')
118
+ // })
270
119
  }
271
120
 
272
- eventEmitter.addListener('allDbsLoaded', dbReadyHandler)
121
+ sendBack({ type: GLOBAL_INITIALIZING_SEND_CONFIG, environment })
273
122
 
274
123
  return () => {
275
- eventEmitter.removeListener('allDbsLoaded', dbReadyHandler)
124
+ internalSubscription?.unsubscribe()
125
+ easSubscription?.unsubscribe()
276
126
  }
277
127
  })