@seedprotocol/sdk 0.1.69 → 0.1.70

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/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-Cy1fke9s.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-Cy1fke9s.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-dylVDX7W.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\nex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","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;;;;;"}
@@ -195,7 +195,15 @@ export const hydrateFromDb = fromCallback<EventObject, typeof propertyMachine>(
195
195
  }
196
196
 
197
197
  if (urlNeedsToBeRefreshed) {
198
- const filePath = `/files/${localStorageDir}/${refResolvedValue}`
198
+ let dir = localStorageDir
199
+ if (
200
+ !dir &&
201
+ propertyRecordSchema &&
202
+ propertyRecordSchema.refValueType === 'ImageSrc'
203
+ ) {
204
+ dir = 'images'
205
+ }
206
+ const filePath = `/files/${dir}/${refResolvedValue}`
199
207
  const fileExists = await fs.promises.exists(filePath)
200
208
  if (fileExists) {
201
209
  const fileContents = await fs.promises.readFile(filePath)
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
  })
@@ -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":"AAWA,eAAO,MAAM,aAAa,KAuRzB,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.70",
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;"}