@seedprotocol/sdk 0.1.64 → 0.1.65

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-bNy6MtOd.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-UWk43qGs.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-bNy6MtOd.js';
3
+ import { T as Text, M as Model } from './index-UWk43qGs.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-BcB0_Har.js.map
77
+ //# sourceMappingURL=seed.schema.config-DA3JNobc.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"seed.schema.config-BcB0_Har.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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ources":["../../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;;;;;"}
@@ -74,7 +74,6 @@ export const hydrateFromDb = fromCallback<EventObject, typeof propertyMachine>(
74
74
  if (!propertyName.endsWith('Id')) {
75
75
  missingPropertyNameVariant = propertyName + 'Id'
76
76
  }
77
- propertyNameQueryString += ` OR property_name = '${missingPropertyNameVariant}'`
78
77
  propertyNameQuery = or(
79
78
  eq(metadata.propertyName, propertyName),
80
79
  eq(metadata.propertyName, missingPropertyNameVariant),
@@ -131,10 +130,14 @@ export const hydrateFromDb = fromCallback<EventObject, typeof propertyMachine>(
131
130
  versionUid: versionUidFromDb,
132
131
  refValueType,
133
132
  refResolvedValue,
134
- refResolvedDisplayValue,
135
133
  localStorageDir,
136
134
  } = firstRow
137
135
 
136
+ let { refResolvedDisplayValue } = firstRow
137
+
138
+ let propertyValueProcessed: string | string[] | undefined | null =
139
+ propertyValueFromDb
140
+
138
141
  if (propertyName && !propertyNameFromDb) {
139
142
  logger(
140
143
  `Property name from code is ${propertyName} but has not value in db ${propertyNameFromDb} for Property.${localId}`,
@@ -171,11 +174,51 @@ export const hydrateFromDb = fromCallback<EventObject, typeof propertyMachine>(
171
174
  )
172
175
  }
173
176
 
177
+ if (
178
+ refResolvedValue &&
179
+ refResolvedDisplayValue &&
180
+ refResolvedDisplayValue.includes('http')
181
+ ) {
182
+ let urlNeedsToBeRefreshed = false
183
+
184
+ try {
185
+ const response = await fetch(refResolvedDisplayValue, {
186
+ method: 'HEAD',
187
+ })
188
+
189
+ // Check if the status is in the 200-299 range
190
+ if (!response.ok) {
191
+ urlNeedsToBeRefreshed = true
192
+ }
193
+ } catch (error) {
194
+ urlNeedsToBeRefreshed = true
195
+ }
196
+
197
+ if (urlNeedsToBeRefreshed) {
198
+ const filePath = `/files/${localStorageDir}/${refResolvedValue}`
199
+ const fileExists = await fs.promises.exists(filePath)
200
+ if (fileExists) {
201
+ const fileContents = await fs.promises.readFile(filePath)
202
+ const fileHandler = new File([fileContents], refResolvedValue)
203
+ refResolvedDisplayValue = URL.createObjectURL(fileHandler)
204
+ }
205
+ }
206
+ }
207
+
208
+ if (
209
+ propertyRecordSchema &&
210
+ propertyRecordSchema.dataType === 'List' &&
211
+ propertyRecordSchema.ref &&
212
+ typeof propertyValueFromDb === 'string'
213
+ ) {
214
+ propertyValueProcessed = propertyValueFromDb.split(',')
215
+ }
216
+
174
217
  sendBack({
175
218
  type: 'updateContext',
176
219
  localId,
177
220
  uid,
178
- propertyValue: propertyValueFromDb,
221
+ propertyValue: propertyValueProcessed,
179
222
  seedLocalId: seedLocalIdFromDb,
180
223
  seedUid: seedUidFromDb,
181
224
  versionLocalId: versionLocalIdFromDb,
@@ -0,0 +1,107 @@
1
+ import { EventObject, fromCallback } from 'xstate'
2
+ import { FromCallbackInput } from '@/types/machines'
3
+ import {
4
+ ItemPropertyValueType,
5
+ PropertyMachineContext,
6
+ SaveValueToDbEvent,
7
+ } from '@/types/property'
8
+
9
+ export const saveListRelation = fromCallback<
10
+ EventObject,
11
+ FromCallbackInput<PropertyMachineContext, SaveValueToDbEvent>
12
+ >(({ sendBack, input: { context, event } }) => {
13
+ const {
14
+ localId,
15
+ propertyName: propertyNameRaw,
16
+ versionLocalId,
17
+ seedUid,
18
+ seedLocalId,
19
+ propertyValue: existingValue,
20
+ propertyRecordSchema,
21
+ } = context
22
+
23
+ if (!propertyRecordSchema) {
24
+ throw new Error('Missing propertyRecordSchema')
25
+ }
26
+
27
+ let newValue: ItemPropertyValueType
28
+
29
+ if (event) {
30
+ newValue = event.newValue
31
+ }
32
+
33
+ const _saveListRelation = async (): Promise<boolean> => {
34
+ let refResolvedDisplayValue
35
+ let refSeedType
36
+ let propertyName = propertyNameRaw
37
+ let versionLocalIdToSave = versionLocalId
38
+
39
+ const refResolvedValue = newValue
40
+
41
+ if (!propertyName.endsWith('Ids')) {
42
+ propertyName = `${propertyName}Ids`
43
+ }
44
+
45
+ let newValueType
46
+
47
+ if (typeof newValue === 'string') {
48
+ newValue = newValue.split(',')
49
+ }
50
+
51
+ if (!Array.isArray(newValue)) {
52
+ sendBack({
53
+ type: 'saveListRelationFailure',
54
+ })
55
+ return false
56
+ }
57
+
58
+ // Should have array of ids here
59
+
60
+ return true
61
+
62
+ // let fileType
63
+ //
64
+ // const dirs = await fs.promises.readdir('/files')
65
+ //
66
+ // for (const dir of dirs) {
67
+ // const files = await fs.promises.readdir(`/files/${dir}`)
68
+ // if (newValue && files.includes(newValue as string)) {
69
+ // fileType = dir
70
+ // break
71
+ // }
72
+ // }
73
+ //
74
+ // if (newValue && fileType === 'images') {
75
+ // const filePath = `/files/images/${newValue}`
76
+ // refResolvedDisplayValue = await getContentUrlFromPath(filePath)
77
+ // refSeedType = 'image'
78
+ // newValue = await createSeed({
79
+ // type: refSeedType,
80
+ // })
81
+ // await createVersion({
82
+ // seedLocalId,
83
+ // seedUid,
84
+ // seedType: refSeedType,
85
+ // })
86
+ // }
87
+ //
88
+ // await updateItemPropertyValue({
89
+ // propertyLocalId: localId,
90
+ // propertyName,
91
+ // newValue,
92
+ // seedLocalId,
93
+ // refSeedType,
94
+ // refResolvedValue,
95
+ // refResolvedDisplayValue,
96
+ // versionLocalId,
97
+ // modelName: itemModelName,
98
+ // schemaUid,
99
+ // })
100
+ }
101
+
102
+ _saveListRelation().then((success) => {
103
+ if (success) {
104
+ sendBack({ type: 'saveRelationSuccess' })
105
+ }
106
+ })
107
+ })
@@ -1 +1 @@
1
- {"version":3,"file":"hydrateFromDb.d.ts","sourceRoot":"","sources":["../../../../../../src/browser/property/actors/hydrateFromDb.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,aAAa,KAiNzB,CAAA"}
1
+ {"version":3,"file":"hydrateFromDb.d.ts","sourceRoot":"","sources":["../../../../../../src/browser/property/actors/hydrateFromDb.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,aAAa,KA4PzB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../src/browser/property/actors/saveValueToDb/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAgB,MAAM,QAAQ,CAAA;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAEL,sBAAsB,EACtB,kBAAkB,EACnB,MAAM,kBAAkB,CAAA;AAEzB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AAEjC,eAAO,MAAM,YAAY,8HA0FvB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../src/browser/property/actors/saveValueToDb/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAgB,MAAM,QAAQ,CAAA;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAEL,sBAAsB,EACtB,kBAAkB,EACnB,MAAM,kBAAkB,CAAA;AAEzB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AAEjC,eAAO,MAAM,YAAY,8HAqGvB,CAAA"}
@@ -0,0 +1,5 @@
1
+ import { EventObject } from 'xstate';
2
+ import { FromCallbackInput } from '@/types/machines';
3
+ import { PropertyMachineContext, SaveValueToDbEvent } from '@/types/property';
4
+ export declare const saveListRelation: import("xstate").CallbackActorLogic<EventObject, FromCallbackInput<PropertyMachineContext, SaveValueToDbEvent>, EventObject>;
5
+ //# sourceMappingURL=saveListRelation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"saveListRelation.d.ts","sourceRoot":"","sources":["../../../../../../../src/browser/property/actors/saveValueToDb/saveListRelation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAgB,MAAM,QAAQ,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAEL,sBAAsB,EACtB,kBAAkB,EACnB,MAAM,kBAAkB,CAAA;AAEzB,eAAO,MAAM,gBAAgB,8HAkG3B,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seedprotocol/sdk",
3
- "version": "0.1.64",
3
+ "version": "0.1.65",
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-9o1LuAwu.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;"}