@seedprotocol/sdk 0.1.69 → 0.1.71

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.
@@ -1,4 +1,4 @@
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-YshZfGRu.js';
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-Cv-NmpW4.js';
2
2
  import './constants-BLctWkrn.js';
3
3
  import 'path';
4
4
  import 'reflect-metadata';
@@ -27,4 +27,4 @@ import '@zenfs/dom';
27
27
  import 'arweave';
28
28
  import 'use-immer';
29
29
  import '@xstate/react';
30
- //# sourceMappingURL=index-VSlWKRIZ.js.map
30
+ //# sourceMappingURL=index-DXh19Ejc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-DXh19Ejc.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/main.js CHANGED
@@ -1,4 +1,4 @@
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-YshZfGRu.js';
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-Cv-NmpW4.js';
2
2
  import 'immer';
3
3
  import 'reflect-metadata';
4
4
  import './constants-BLctWkrn.js';
@@ -1,6 +1,6 @@
1
1
  import { _ as __decorate, a as __metadata } from './constants-BLctWkrn.js';
2
2
  import 'drizzle-orm';
3
- import { T as Text, M as Model } from './index-YshZfGRu.js';
3
+ import { T as Text, M as Model } from './index-Cv-NmpW4.js';
4
4
  import 'react';
5
5
  import 'reflect-metadata';
6
6
  import 'xstate';
@@ -74,4 +74,4 @@ const models = {
74
74
  };
75
75
 
76
76
  export { models };
77
- //# sourceMappingURL=seed.schema.config-BEvGEHkp.js.map
77
+ //# sourceMappingURL=seed.schema.config-Bp82HrfV.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"seed.schema.config-BEvGEHkp.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
+ {"version":3,"file":"seed.schema.config-Bp82HrfV.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;;;;;"}
@@ -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
 
@@ -195,12 +196,24 @@ export const hydrateFromDb = fromCallback<EventObject, typeof propertyMachine>(
195
196
  }
196
197
 
197
198
  if (urlNeedsToBeRefreshed) {
198
- const filePath = `/files/${localStorageDir}/${refResolvedValue}`
199
+ let dir = localStorageDir
200
+ if (
201
+ !dir &&
202
+ propertyRecordSchema &&
203
+ propertyRecordSchema.refValueType === 'ImageSrc'
204
+ ) {
205
+ dir = 'images'
206
+ }
207
+ const filePath = `/files/${dir}/${refResolvedValue}`
199
208
  const fileExists = await fs.promises.exists(filePath)
200
209
  if (fileExists) {
201
210
  const fileContents = await fs.promises.readFile(filePath)
202
211
  const fileHandler = new File([fileContents], refResolvedValue)
203
212
  refResolvedDisplayValue = URL.createObjectURL(fileHandler)
213
+ await updateMetadata({
214
+ localId,
215
+ refResolvedDisplayValue,
216
+ })
204
217
  }
205
218
  }
206
219
  }
@@ -214,25 +227,6 @@ export const hydrateFromDb = fromCallback<EventObject, typeof propertyMachine>(
214
227
  propertyValueProcessed = propertyValueFromDb.split(',')
215
228
  }
216
229
 
217
- if (seedLocalIdFromDb === 'sAFXuO7Uez') {
218
- console.log(`[hydrateFromDb] sending updateContext with:`, {
219
- type: 'updateContext',
220
- localId,
221
- uid,
222
- propertyValue: propertyValueProcessed,
223
- seedLocalId: seedLocalIdFromDb,
224
- seedUid: seedUidFromDb,
225
- versionLocalId: versionLocalIdFromDb,
226
- versionUid: versionUidFromDb,
227
- schemaUid: schemaUidFromDb,
228
- refValueType,
229
- localStorageDir,
230
- resolvedValue: refResolvedValue,
231
- resolvedDisplayValue: refResolvedDisplayValue,
232
- renderValue: refResolvedDisplayValue,
233
- })
234
- }
235
-
236
230
  sendBack({
237
231
  type: 'updateContext',
238
232
  localId,
package/dist/src/index.ts CHANGED
@@ -1,21 +1,106 @@
1
- import { setup } from 'xstate'
1
+ import { EventObject, fromCallback } from 'xstate'
2
+ import { FromCallbackInput } from '@/types/machines'
2
3
  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
- },
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
+ })
21
106
  })
package/dist/src/seed.ts CHANGED
@@ -1,37 +1,10 @@
1
- import { isBrowser, isNode, isReactNative } from '@/shared/environment'
2
- import { Endpoints, SeedConstructorOptions } from '@/types/types'
3
- import { Subject } from 'rxjs'
1
+ import { SeedConstructorOptions } from '@/types/types'
2
+ import { SeedBase } from '@/shared/seed'
4
3
 
5
- type Environment = 'node' | 'browser' | 'react-native'
6
-
7
- abstract class SeedBase {
8
- private readonly _env: Environment = 'browser'
9
- protected _subject: Subject<void> = new Subject<void>()
10
-
11
- constructor(props: { endpoints: Endpoints }) {
12
- console.log('Seed constructor called')
13
- if (isNode()) {
14
- this._env = 'node'
15
- }
16
- if (isBrowser()) {
17
- this._env = 'browser'
18
- }
19
- if (isReactNative()) {
20
- this._env = 'react-native'
21
- }
22
- }
23
-
24
- async initialize() {}
25
-
26
- subscribe(callback: (event: any) => void) {
27
- return this._subject.subscribe(callback)
28
- }
29
- }
30
-
31
- class SeedSync extends SeedBase {
4
+ class SeedNode extends SeedBase {
32
5
  constructor(props: SeedConstructorOptions) {
33
6
  super(props)
34
7
  }
35
8
  }
36
9
 
37
- export { SeedBase, SeedSync }
10
+ export { SeedNode }
@@ -0,0 +1,19 @@
1
+ import { metadata, MetadataType } from '@/shared/seedSchema'
2
+ import { getAppDb } from '../sqlWasmClient'
3
+ import { eq } from 'drizzle-orm'
4
+
5
+ type UpdateMetadata = (
6
+ metadataValues: Partial<MetadataType>,
7
+ ) => Promise<MetadataType>
8
+
9
+ export const updateMetadata: UpdateMetadata = async (metadataValues) => {
10
+ const appDb = getAppDb()
11
+
12
+ const { localId, ...rest } = metadataValues
13
+
14
+ if (!localId) {
15
+ throw new Error('No localId provided to updateMetadata')
16
+ }
17
+
18
+ await appDb.update(metadata).set(rest).where(eq(metadata.localId, localId))
19
+ }
@@ -0,0 +1,5 @@
1
+ import { MetadataType } from '@/shared/seedSchema';
2
+ type UpdateMetadata = (metadataValues: Partial<MetadataType>) => Promise<MetadataType>;
3
+ export declare const updateMetadata: UpdateMetadata;
4
+ export {};
5
+ //# sourceMappingURL=updateMetadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateMetadata.d.ts","sourceRoot":"","sources":["../../../../../../src/browser/db/write/updateMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAI5D,KAAK,cAAc,GAAG,CACpB,cAAc,EAAE,OAAO,CAAC,YAAY,CAAC,KAClC,OAAO,CAAC,YAAY,CAAC,CAAA;AAE1B,eAAO,MAAM,cAAc,EAAE,cAU5B,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"hydrateFromDb.d.ts","sourceRoot":"","sources":["../../../../../../src/browser/property/actors/hydrateFromDb.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,aAAa,KA+QzB,CAAA"}
1
+ {"version":3,"file":"hydrateFromDb.d.ts","sourceRoot":"","sources":["../../../../../../src/browser/property/actors/hydrateFromDb.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,aAAa,KAwQzB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seedprotocol/sdk",
3
- "version": "0.1.69",
3
+ "version": "0.1.71",
4
4
  "description": "The SDK for Seed Protocol",
5
5
  "type": "module",
6
6
  "types": "./dist/types/src/index.d.ts",
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-VSlWKRIZ.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;"}