@seedprotocol/sdk 0.1.70 → 0.1.72

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 (68) hide show
  1. package/README.md +40 -19
  2. package/dist/bin.js +3 -1
  3. package/dist/bin.js.map +1 -1
  4. package/dist/{constants-BLctWkrn.js → constants-CtmwCBma.js} +23 -2
  5. package/dist/{constants-BLctWkrn.js.map → constants-CtmwCBma.js.map} +1 -1
  6. package/dist/{index-Cy1fke9s.js → index-Bcf8xGUK.js} +202 -71
  7. package/dist/index-Bcf8xGUK.js.map +1 -0
  8. package/dist/{index-B6WilINl.js → index-CG7KjAdn.js} +5 -3
  9. package/dist/index-CG7KjAdn.js.map +1 -0
  10. package/dist/main.js +4 -2
  11. package/dist/main.js.map +1 -1
  12. package/dist/{seed.schema.config-dylVDX7W.js → seed.schema.config-Z67FC09h.js} +5 -3
  13. package/dist/seed.schema.config-Z67FC09h.js.map +1 -0
  14. package/dist/src/ItemProperty.ts +4 -0
  15. package/dist/src/allItems.ts +3 -2
  16. package/dist/src/download.ts +2 -2
  17. package/dist/src/getPublishPayload.ts +111 -0
  18. package/dist/src/globalMachine.ts +46 -26
  19. package/dist/src/hydrateFromDb.ts +5 -19
  20. package/dist/src/index.ts +19 -104
  21. package/dist/src/item.ts +5 -5
  22. package/dist/src/publish.ts +0 -3
  23. package/dist/src/saveAppState.ts +19 -0
  24. package/dist/src/savePublishService.ts +30 -0
  25. package/dist/src/services.ts +13 -4
  26. package/dist/src/updateMetadata.ts +19 -0
  27. package/dist/src/write.ts +1 -18
  28. package/dist/types/src/browser/db/read/getPublishPayload.d.ts +15 -0
  29. package/dist/types/src/browser/db/read/getPublishPayload.d.ts.map +1 -0
  30. package/dist/types/src/browser/db/write/saveAppState.d.ts +2 -0
  31. package/dist/types/src/browser/db/write/saveAppState.d.ts.map +1 -0
  32. package/dist/types/src/browser/db/write/updateMetadata.d.ts +5 -0
  33. package/dist/types/src/browser/db/write/updateMetadata.d.ts.map +1 -0
  34. package/dist/types/src/browser/db/write.d.ts +0 -1
  35. package/dist/types/src/browser/db/write.d.ts.map +1 -1
  36. package/dist/types/src/browser/events/item/index.d.ts.map +1 -1
  37. package/dist/types/src/browser/events/item/publish.d.ts +0 -1
  38. package/dist/types/src/browser/events/item/publish.d.ts.map +1 -1
  39. package/dist/types/src/browser/events/services/allItems.d.ts.map +1 -1
  40. package/dist/types/src/browser/item/Item.d.ts +1 -0
  41. package/dist/types/src/browser/item/Item.d.ts.map +1 -1
  42. package/dist/types/src/browser/item/queries.d.ts +3 -0
  43. package/dist/types/src/browser/item/queries.d.ts.map +1 -1
  44. package/dist/types/src/browser/property/ItemProperty.d.ts +1 -0
  45. package/dist/types/src/browser/property/ItemProperty.d.ts.map +1 -1
  46. package/dist/types/src/browser/property/actors/hydrateFromDb.d.ts.map +1 -1
  47. package/dist/types/src/browser/react/item.d.ts.map +1 -1
  48. package/dist/types/src/browser/react/services.d.ts.map +1 -1
  49. package/dist/types/src/browser/schema/file/fetchAll/actors.d.ts.map +1 -1
  50. package/dist/types/src/browser/services/global/actors/savePublishService.d.ts +4 -0
  51. package/dist/types/src/browser/services/global/actors/savePublishService.d.ts.map +1 -0
  52. package/dist/types/src/browser/services/global/globalMachine.d.ts +20 -0
  53. package/dist/types/src/browser/services/global/globalMachine.d.ts.map +1 -1
  54. package/dist/types/src/shared/helpers/constants.d.ts +12 -0
  55. package/dist/types/src/shared/helpers/constants.d.ts.map +1 -1
  56. package/package.json +1 -1
  57. package/dist/index-B6WilINl.js.map +0 -1
  58. package/dist/index-Cy1fke9s.js.map +0 -1
  59. package/dist/seed.schema.config-dylVDX7W.js.map +0 -1
  60. package/dist/src/seedData.ts +0 -0
  61. package/dist/types/src/browser/eas/actors.d.ts +0 -3
  62. package/dist/types/src/browser/eas/actors.d.ts.map +0 -1
  63. package/dist/types/src/browser/eas/helpers.d.ts +0 -5
  64. package/dist/types/src/browser/eas/helpers.d.ts.map +0 -1
  65. package/dist/types/src/browser/eas/index.d.ts +0 -113
  66. package/dist/types/src/browser/eas/index.d.ts.map +0 -1
  67. package/dist/types/src/browser/eas/seedData.d.ts +0 -1
  68. package/dist/types/src/browser/eas/seedData.d.ts.map +0 -1
@@ -1,5 +1,7 @@
1
- export { f as GET_ALL_PROPERTIES_FOR_ALL_VERSIONS, e as GET_PROPERTIES, G as GET_SCHEMAS, a as GET_SEEDS, b as GET_SEED_IDS, c as GET_STORAGE_TRANSACTION_ID, d as GET_VERSIONS, I as Item, g as itemMachineAll, i as itemMachineSingle } from './index-Cy1fke9s.js';
2
- import './constants-BLctWkrn.js';
1
+ export { g as GET_ALL_PROPERTIES_FOR_ALL_VERSIONS, f as GET_PROPERTIES, G as GET_SCHEMAS, a as GET_SCHEMA_BY_NAME, b as GET_SEEDS, c as GET_SEED_IDS, d as GET_STORAGE_TRANSACTION_ID, e as GET_VERSIONS, I as Item, h as itemMachineAll, i as itemMachineSingle } from './index-Bcf8xGUK.js';
2
+ import './constants-CtmwCBma.js';
3
+ import '@ethereum-attestation-service/eas-sdk';
4
+ import 'thirdweb';
3
5
  import 'path';
4
6
  import 'reflect-metadata';
5
7
  import '@sinclair/typebox';
@@ -27,4 +29,4 @@ import '@zenfs/dom';
27
29
  import 'arweave';
28
30
  import 'use-immer';
29
31
  import '@xstate/react';
30
- //# sourceMappingURL=index-B6WilINl.js.map
32
+ //# sourceMappingURL=index-CG7KjAdn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-CG7KjAdn.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/main.js CHANGED
@@ -1,7 +1,7 @@
1
- export { h as ImageSrc, I as Item, j as ItemProperty, J as Json, L as List, M as Model, P as Property, R as Relation, T as Text, s as client, t as getCorrectId, r as getGlobalService, m as useCreateItem, o as useDeleteItem, p as useGlobalServiceStatus, k as useItem, l as useItemProperties, n as useItemProperty, u as useItems, q as useServices, w as withSeed } from './index-Cy1fke9s.js';
1
+ export { j as ImageSrc, I as Item, k as ItemProperty, J as Json, L as List, M as Model, P as Property, R as Relation, T as Text, t as client, v as getCorrectId, s as getGlobalService, n as useCreateItem, p as useDeleteItem, q as useGlobalServiceStatus, l as useItem, m as useItemProperties, o as useItemProperty, u as useItems, r as useServices, w as withSeed } from './index-Bcf8xGUK.js';
2
2
  import 'immer';
3
3
  import 'reflect-metadata';
4
- import './constants-BLctWkrn.js';
4
+ import './constants-CtmwCBma.js';
5
5
  import 'xstate';
6
6
  import 'arweave';
7
7
  import 'drizzle-orm';
@@ -27,4 +27,6 @@ import 'drizzle-orm/sqlite-proxy';
27
27
  import '@zenfs/dom';
28
28
  import 'use-immer';
29
29
  import '@xstate/react';
30
+ import 'thirdweb';
31
+ import '@ethereum-attestation-service/eas-sdk';
30
32
  //# sourceMappingURL=main.js.map
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,12 +1,14 @@
1
- import { _ as __decorate, a as __metadata } from './constants-BLctWkrn.js';
1
+ import { _ as __decorate, a as __metadata } from './constants-CtmwCBma.js';
2
2
  import 'drizzle-orm';
3
- import { T as Text, M as Model } from './index-Cy1fke9s.js';
3
+ import { T as Text, M as Model } from './index-Bcf8xGUK.js';
4
4
  import 'react';
5
5
  import 'reflect-metadata';
6
6
  import 'xstate';
7
7
  import 'arweave';
8
8
  import '@zenfs/core';
9
9
  import '@zenfs/dom';
10
+ import '@ethereum-attestation-service/eas-sdk';
11
+ import 'thirdweb';
10
12
  import 'path';
11
13
  import '@sinclair/typebox';
12
14
  import 'dayjs';
@@ -74,4 +76,4 @@ const models = {
74
76
  };
75
77
 
76
78
  export { models };
77
- //# sourceMappingURL=seed.schema.config-dylVDX7W.js.map
79
+ //# sourceMappingURL=seed.schema.config-Z67FC09h.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seed.schema.config-Z67FC09h.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;;;;;"}
@@ -345,6 +345,10 @@ export class ItemProperty<PropertyType> {
345
345
  return this._getSnapshot().context.seedUid
346
346
  }
347
347
 
348
+ get schemaUid() {
349
+ return this._getSnapshot().context.schemaUid
350
+ }
351
+
348
352
  get propertyName() {
349
353
  if (this._alias) {
350
354
  return this._alias
@@ -1,5 +1,6 @@
1
1
  import { getGlobalService } from '@/browser/services/global'
2
- import { writeAppState } from '@/browser/db/write'
2
+
3
+ import { saveAppState } from '@/browser/db/write/saveAppState'
3
4
 
4
5
  type SaveServiceEvent = {
5
6
  modelName: string
@@ -23,7 +24,7 @@ export const saveServiceHandler = async (event: SaveServiceEvent) => {
23
24
  return
24
25
  }
25
26
 
26
- await writeAppState(
27
+ await saveAppState(
27
28
  `snapshot__${modelName}`,
28
29
  JSON.stringify(service.getPersistedSnapshot()),
29
30
  )
@@ -17,10 +17,10 @@ import debug from 'debug'
17
17
  import { getAppDb, isAppDbReady } from '@/browser/db/sqlWasmClient'
18
18
  import { getGlobalService } from '@/browser/services'
19
19
  import { waitFor } from 'xstate'
20
- import { writeAppState } from '@/browser/db/write'
21
20
  import { getMetadata } from '@/browser/db/read/getMetadata'
22
21
  import { saveMetadata } from '@/browser/db/write/saveMetadata'
23
22
  import { GET_TRANSACTION_TAGS } from '@/browser/arweave/queries'
23
+ import { saveAppState } from '@/browser/db/write/saveAppState'
24
24
 
25
25
  const logger = debug('app:files:download')
26
26
 
@@ -141,7 +141,7 @@ export const downloadAllFilesBinaryRequestHandler = async () => {
141
141
 
142
142
  excludedTransactions.add(transactionId)
143
143
 
144
- await writeAppState(
144
+ await saveAppState(
145
145
  'excludedTransactions',
146
146
  JSON.stringify(Array.from(excludedTransactions)),
147
147
  )
@@ -0,0 +1,111 @@
1
+ import { GET_SCHEMAS } from '@/browser'
2
+ import { getItem } from '@/browser/db/read/getItem'
3
+ import {
4
+ defaultAttestationData,
5
+ INTERNAL_DATA_TYPES,
6
+ VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA,
7
+ } from '@/shared/helpers/constants'
8
+ import { getModelSchemas } from '@/browser/db/read/getModelSchemas'
9
+ import { ZERO_ADDRESS } from 'thirdweb'
10
+ import {
11
+ AttestationRequest,
12
+ SchemaEncoder,
13
+ } from '@ethereum-attestation-service/eas-sdk'
14
+ import { easClient, queryClient } from '@/browser/helpers'
15
+
16
+ type PublishPayload = {
17
+ localId: string
18
+ seedIsRevocable: boolean
19
+ seedSchemaUid: string
20
+ seedUid: string
21
+ versionSchemaUid: string
22
+ versionUid: string
23
+ listOfAttestations: AttestationRequest[]
24
+ propertiesToUpdate: any[]
25
+ }
26
+
27
+ type MultiPublishPayload = PublishPayload[]
28
+
29
+ export const getPublishPayload = async (
30
+ seedLocalId: string,
31
+ ): Promise<MultiPublishPayload> => {
32
+ const item = await getItem({ seedLocalId })
33
+
34
+ if (!item) {
35
+ throw new Error('Item not found')
36
+ }
37
+
38
+ const localId = item.seedLocalId
39
+ const seedIsRevocable = true
40
+ const seedSchemaUid = item.schemaUid
41
+ const seedUid = item.seedUid
42
+ const versionSchemaUid = VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA
43
+ const listOfAttestations = []
44
+ const propertiesToUpdate = []
45
+
46
+ const schemas = await getModelSchemas()
47
+
48
+ for (const [propertyName, itemProperty] of Object.entries(item.properties)) {
49
+ const foundPropertySchema = await queryClient.fetchQuery({
50
+ queryKey: [`getPropertySchema${propertyName}`],
51
+ queryFn: async () =>
52
+ easClient.request(GET_SCHEMAS, {
53
+ where: {
54
+ id: {
55
+ equals: itemProperty.schemaUid,
56
+ },
57
+ },
58
+ }),
59
+ })
60
+
61
+ if (
62
+ !foundPropertySchema ||
63
+ !foundPropertySchema.schemas ||
64
+ foundPropertySchema.schemas.length === 0
65
+ ) {
66
+ console.error(`Property schema not found for ${propertyName}`)
67
+ continue
68
+ }
69
+
70
+ if (!itemProperty.propertyDef) {
71
+ console.error(`Property definition not found for ${propertyName}`)
72
+ continue
73
+ }
74
+
75
+ const easDataType =
76
+ INTERNAL_DATA_TYPES[itemProperty.propertyDef.dataType].eas
77
+
78
+ const data = [
79
+ { name: propertyName, type: easDataType, value: itemProperty.value },
80
+ ]
81
+
82
+ const easSchemaDefinition = foundPropertySchema.schemas[0].schema
83
+
84
+ const dataEncoder = new SchemaEncoder(easSchemaDefinition)
85
+
86
+ const encodedData = dataEncoder.encodeData(data)
87
+
88
+ listOfAttestations.push({
89
+ schema: itemProperty.schemaUid!,
90
+ data: [
91
+ {
92
+ ...defaultAttestationData,
93
+ data: encodedData,
94
+ },
95
+ ],
96
+ })
97
+ }
98
+
99
+ return [
100
+ {
101
+ localId,
102
+ seedIsRevocable,
103
+ seedSchemaUid,
104
+ seedUid: seedUid || ZERO_ADDRESS,
105
+ versionUid: item.latestVersionUid || ZERO_ADDRESS,
106
+ versionSchemaUid,
107
+ listOfAttestations,
108
+ propertiesToUpdate,
109
+ },
110
+ ]
111
+ }
@@ -16,6 +16,7 @@ import { addModelsToDb } from '@/browser/services/global/actors/addModelsToDb'
16
16
  import { internalMachine } from '@/browser/services/internal/internalMachine'
17
17
  import { itemMachineAll } from '@/browser/item/all/itemMachineAll'
18
18
  import { publishMachine } from '@/browser/services/publish/publishMachine'
19
+ import { savePublishService } from '@/browser/services/global/actors/savePublishService'
19
20
 
20
21
  const {
21
22
  UNINITIALIZED,
@@ -38,11 +39,17 @@ const globalMachine = setup({
38
39
  initialize,
39
40
  addModelsToDb,
40
41
  getSchemaForModel,
42
+ savePublishService,
41
43
  },
42
44
  }).createMachine({
43
45
  id: MachineIds.GLOBAL,
44
46
  initial: UNINITIALIZED,
45
47
  context: ({ input }) => input as GlobalMachineContext,
48
+ on: {
49
+ publishItemRequest: `.${PUBLISHING_ITEM}`,
50
+ savePublishService: `.savingPublishService`,
51
+ restorePublishService: `.${PUBLISHING_ITEM}`,
52
+ },
46
53
  states: {
47
54
  [UNINITIALIZED]: {
48
55
  on: {
@@ -73,7 +80,7 @@ const globalMachine = setup({
73
80
  displayText: 'Booting up',
74
81
  percentComplete: 5,
75
82
  },
76
- tags: ['loading'],
83
+ tags: ['loading', 'startup'],
77
84
  },
78
85
  [INITIALIZING]: {
79
86
  on: {
@@ -130,7 +137,7 @@ const globalMachine = setup({
130
137
  displayText: 'Initializing Seed SDK',
131
138
  percentComplete: 10,
132
139
  },
133
- tags: ['loading'],
140
+ tags: ['loading', 'startup'],
134
141
  },
135
142
  },
136
143
  [ADDING_MODELS_TO_DB]: {
@@ -148,39 +155,52 @@ const globalMachine = setup({
148
155
  meta: {
149
156
  displayText: 'Adding models to database',
150
157
  },
151
- tags: ['loading'],
158
+ tags: ['loading', 'startup'],
152
159
  },
153
160
  },
154
161
  [INITIALIZED]: {
155
- type: 'parallel',
156
- on: {
157
- publishItemRequest: `.${PUBLISHING_ITEM}`,
158
- },
162
+ // type: 'parallel',
163
+ // on: {
164
+ // publishItemRequest: `.${PUBLISHING_ITEM}`,
165
+ // },
159
166
  meta: {
160
167
  displayText: 'Global service ready',
161
168
  percentComplete: 40,
162
169
  },
163
- tags: ['loading'],
164
- states: {
165
- [PUBLISHING_ITEM]: {
166
- entry: [
167
- assign({
168
- publishItemService: ({ spawn, event }) =>
169
- spawn(publishMachine, {
170
- id: 'publishService',
171
- input: {
172
- modelName: event.modelName,
173
- localId: event.seedLocalId,
174
- },
175
- }),
170
+ tags: ['loading', 'startup'],
171
+ // initial: PUBLISHING_ITEM,
172
+ },
173
+ [PUBLISHING_ITEM]: {
174
+ target: INITIALIZED,
175
+ entry: [
176
+ assign({
177
+ publishItemService: ({ spawn, event }) =>
178
+ spawn(publishMachine, {
179
+ id: 'publishService',
180
+ input: {
181
+ localId: event.seedLocalId,
182
+ },
176
183
  }),
177
- ],
178
- meta: {
179
- displayText: 'Publishing item',
180
- },
181
- tags: ['publishing'],
182
- },
184
+ }),
185
+ ],
186
+ meta: {
187
+ displayText: 'Publishing item',
188
+ },
189
+ tags: ['publishing'],
190
+ },
191
+ savingPublishService: {
192
+ target: INITIALIZED,
193
+ on: {
194
+ savePublishServiceSuccess: INITIALIZED,
195
+ },
196
+ invoke: {
197
+ src: 'savePublishService',
198
+ input: ({ context }) => ({ context }),
199
+ },
200
+ meta: {
201
+ displayText: 'Saving publish service',
183
202
  },
203
+ tags: ['publishing'],
184
204
  },
185
205
  },
186
206
  // on: {
@@ -6,6 +6,7 @@ import debug from 'debug'
6
6
  import { fs } from '@zenfs/core'
7
7
  import { metadata } from 'src/shared/seedSchema'
8
8
  import { getAppDb } from '@/browser/db/sqlWasmClient'
9
+ import { updateMetadata } from '@/browser/db/write/updateMetadata'
9
10
 
10
11
  const logger = debug('app:property:actors:hydrateFromDb')
11
12
 
@@ -209,6 +210,10 @@ export const hydrateFromDb = fromCallback<EventObject, typeof propertyMachine>(
209
210
  const fileContents = await fs.promises.readFile(filePath)
210
211
  const fileHandler = new File([fileContents], refResolvedValue)
211
212
  refResolvedDisplayValue = URL.createObjectURL(fileHandler)
213
+ await updateMetadata({
214
+ localId,
215
+ refResolvedDisplayValue,
216
+ })
212
217
  }
213
218
  }
214
219
  }
@@ -222,25 +227,6 @@ export const hydrateFromDb = fromCallback<EventObject, typeof propertyMachine>(
222
227
  propertyValueProcessed = propertyValueFromDb.split(',')
223
228
  }
224
229
 
225
- if (seedLocalIdFromDb === 'sAFXuO7Uez') {
226
- console.log(`[hydrateFromDb] sending updateContext with:`, {
227
- type: 'updateContext',
228
- localId,
229
- uid,
230
- propertyValue: propertyValueProcessed,
231
- seedLocalId: seedLocalIdFromDb,
232
- seedUid: seedUidFromDb,
233
- versionLocalId: versionLocalIdFromDb,
234
- versionUid: versionUidFromDb,
235
- schemaUid: schemaUidFromDb,
236
- refValueType,
237
- localStorageDir,
238
- resolvedValue: refResolvedValue,
239
- resolvedDisplayValue: refResolvedDisplayValue,
240
- renderValue: refResolvedDisplayValue,
241
- })
242
- }
243
-
244
230
  sendBack({
245
231
  type: 'updateContext',
246
232
  localId,
package/dist/src/index.ts CHANGED
@@ -1,106 +1,21 @@
1
- import { EventObject, fromCallback } from 'xstate'
2
- import { FromCallbackInput } from '@/types/machines'
1
+ import { setup } from 'xstate'
3
2
  import {
4
- ItemPropertyValueType,
5
- PropertyMachineContext,
6
- SaveValueToDbEvent,
7
- } from '@/types/property'
8
- import { updateItemPropertyValue } from '@/browser/db/write/updateItemPropertyValue'
9
-
10
- export * from './saveImageSrc'
11
- export * from './saveRelation'
12
- export * from './saveItemStorage'
13
-
14
- export const analyzeInput = fromCallback<
15
- EventObject,
16
- FromCallbackInput<PropertyMachineContext, SaveValueToDbEvent>
17
- >(({ sendBack, input: { context, event } }) => {
18
- const {
19
- localId,
20
- propertyName: propertyNameRaw,
21
- seedLocalId,
22
- versionLocalId,
23
- versionUid,
24
- propertyValue: existingValue,
25
- propertyRecordSchema,
26
- itemModelName,
27
- schemaUid,
28
- } = context
29
-
30
- let newValue: ItemPropertyValueType
31
-
32
- if (event) {
33
- newValue = event.newValue
34
- }
35
-
36
- if (existingValue === newValue) {
37
- sendBack({ type: 'saveValueToDbSuccess' })
38
- return
39
- }
40
-
41
- if (!propertyRecordSchema) {
42
- throw new Error('Missing propertyRecordSchema')
43
- }
44
-
45
- const _analyzeInput = async (): Promise<boolean> => {
46
- let propertyName = propertyNameRaw
47
-
48
- if (
49
- propertyRecordSchema.refValueType &&
50
- propertyRecordSchema.refValueType !== 'ImageSrc' &&
51
- propertyRecordSchema.dataType === 'Relation'
52
- ) {
53
- sendBack({
54
- type: 'saveRelation',
55
- newValue,
56
- })
57
- return false
58
- }
59
-
60
- if (
61
- propertyRecordSchema.refValueType === 'ImageSrc' ||
62
- propertyRecordSchema.dataType === 'ImageSrc'
63
- ) {
64
- sendBack({
65
- type: 'saveImageSrc',
66
- newValue,
67
- })
68
- return false
69
- }
70
-
71
- if (
72
- propertyRecordSchema.storageType &&
73
- propertyRecordSchema.storageType === 'ItemStorage'
74
- ) {
75
- sendBack({
76
- type: 'saveItemStorage',
77
- newValue,
78
- })
79
- return false
80
- }
81
-
82
- await updateItemPropertyValue({
83
- localId: localId,
84
- propertyName,
85
- newValue,
86
- seedLocalId,
87
- versionLocalId,
88
- versionUid,
89
- modelName: itemModelName,
90
- schemaUid,
91
- })
92
-
93
- sendBack({
94
- type: 'updateContext',
95
- propertyValue: newValue,
96
- })
97
-
98
- return true
99
- }
100
-
101
- _analyzeInput().then((isDone) => {
102
- if (isDone) {
103
- sendBack({ type: 'saveValueToDbSuccess' })
104
- }
105
- })
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
+ },
106
21
  })
package/dist/src/item.ts CHANGED
@@ -335,10 +335,9 @@ type UsePublishItemReturn = {
335
335
  isPublishing: boolean
336
336
  }
337
337
 
338
- type PublishItemProps = [
339
- item: Item<any> | undefined,
340
- callback?: (result: PublishItemResult) => any | undefined,
341
- ]
338
+ type PublishItemProps =
339
+ | [Item<any> | undefined]
340
+ | [Item<any> | undefined, (result: PublishItemResult) => any | undefined]
342
341
 
343
342
  type PublishItem = (...props: PublishItemProps) => Promise<any>
344
343
 
@@ -355,7 +354,8 @@ export const usePublishItem = (): UsePublishItemReturn => {
355
354
  console.log('Publishing item', item)
356
355
  setIsPublishing(true)
357
356
  try {
358
- await item.publish()
357
+ // await item.publish()
358
+ const payload = await item.getPublishPayload()
359
359
  if (callback) {
360
360
  callback()
361
361
  }
@@ -1,7 +1,6 @@
1
1
  import { getGlobalService } from '@/browser/services/global'
2
2
 
3
3
  type PublishItemRequestEvent = {
4
- modelName?: string
5
4
  seedLocalId: string
6
5
  }
7
6
 
@@ -10,7 +9,6 @@ type PublishItemRequestHandler = (
10
9
  ) => Promise<void>
11
10
 
12
11
  export const publishItemRequestHandler: PublishItemRequestHandler = async ({
13
- modelName,
14
12
  seedLocalId,
15
13
  }) => {
16
14
  const globalService = getGlobalService()
@@ -25,7 +23,6 @@ export const publishItemRequestHandler: PublishItemRequestHandler = async ({
25
23
  })
26
24
  globalService.send({
27
25
  type: 'publishItemRequest',
28
- modelName,
29
26
  seedLocalId,
30
27
  })
31
28
  }
@@ -0,0 +1,19 @@
1
+ import { getAppDb } from '@/browser'
2
+ import { appState } from '@/shared/seedSchema'
3
+
4
+ export const saveAppState = async (key: string, value: string) => {
5
+ const appDb = getAppDb()
6
+
7
+ await appDb
8
+ .insert(appState)
9
+ .values({
10
+ key,
11
+ value,
12
+ })
13
+ .onConflictDoUpdate({
14
+ target: appState.key,
15
+ set: {
16
+ value,
17
+ },
18
+ })
19
+ }
@@ -0,0 +1,30 @@
1
+ import { EventObject, fromCallback } from 'xstate'
2
+ import { FromCallbackInput, GlobalMachineContext } from '@/types/machines'
3
+ import { saveAppState } from '@/browser/db/write/saveAppState'
4
+
5
+ export const savePublishService = fromCallback<
6
+ EventObject,
7
+ FromCallbackInput<GlobalMachineContext>
8
+ >(({ sendBack, input: { event, context } }) => {
9
+ const { publishItemService } = context
10
+
11
+ if (!publishItemService) {
12
+ sendBack({ type: 'savePublishServiceError' })
13
+ return
14
+ }
15
+
16
+ const _savePublishService = async (): Promise<boolean> => {
17
+ await saveAppState(
18
+ `snapshot__publishItemService`,
19
+ JSON.stringify(publishItemService.getPersistedSnapshot()),
20
+ )
21
+
22
+ return true
23
+ }
24
+
25
+ _savePublishService().then((success) => {
26
+ if (success) {
27
+ sendBack({ type: 'savePublishServiceSuccess' })
28
+ }
29
+ })
30
+ })
@@ -14,7 +14,7 @@ import { MachineIds } from '@/browser/services/internal/constants'
14
14
 
15
15
  const logger = debug('app:react:services')
16
16
 
17
- const finalStrings = ['idle', 'ready', 'done', 'success']
17
+ const finalStrings = ['idle', 'ready', 'done', 'success', 'initialized']
18
18
 
19
19
  export const getServiceName = (service: ActorRef<any, any>) => {
20
20
  let name = 'actor'
@@ -90,8 +90,17 @@ export const useService = (service: ActorRef<any, any>) => {
90
90
  const getPercentComplete = (service: ActorRef<any, any>) => {
91
91
  let percentComplete = 0
92
92
  if (service.logic.states) {
93
- const stateNames = Object.keys(service.logic.states)
94
- const totalStates = stateNames.length
93
+ const stateNames = []
94
+ const startupStates = []
95
+
96
+ for (const [stateName, state] of Object.entries(service.logic.states)) {
97
+ if (state.tags.includes('loading')) {
98
+ stateNames.push(stateName)
99
+ startupStates.push(state)
100
+ }
101
+ }
102
+
103
+ const totalStates = startupStates.length
95
104
  const value = getServiceValue(service)
96
105
  if (finalStrings.includes(value)) {
97
106
  return 0
@@ -311,7 +320,7 @@ export const useServices = () => {
311
320
  return
312
321
  }
313
322
  if (
314
- getServiceValue(globalService) === 'ready' &&
323
+ getServiceValue(globalService) === 'initialized' &&
315
324
  getServiceValue(internalService) === 'ready'
316
325
  ) {
317
326
  const denominator = actors.length