@seedprotocol/sdk 0.1.75 → 0.1.76
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/bin.js +1 -1
- package/dist/{constants-B9hSFQXL.js → constants-rmQ8zg8_.js} +2 -2
- package/dist/{constants-B9hSFQXL.js.map → constants-rmQ8zg8_.js.map} +1 -1
- package/dist/index-D5bGQvS6.js +32 -0
- package/dist/index-D5bGQvS6.js.map +1 -0
- package/dist/index-nyYoS6hl.js +7547 -0
- package/dist/index-nyYoS6hl.js.map +1 -0
- package/dist/main.js +29 -7542
- package/dist/main.js.map +1 -1
- package/dist/{seed.schema.config-BPJfo_5h.js → seed.schema.config-CaxQONHV.js} +3 -3
- package/dist/{seed.schema.config-BPJfo_5h.js.map → seed.schema.config-CaxQONHV.js.map} +1 -1
- package/dist/src/ItemProperty.ts +21 -25
- package/dist/src/getItem.ts +12 -32
- package/dist/src/getItemProperties.ts +17 -113
- package/dist/src/hydrateFromDb.ts +22 -58
- package/dist/src/item.ts +1 -1
- package/dist/src/itemMachineSingle.ts +12 -29
- package/dist/src/reload.ts +33 -0
- package/dist/src/resolveRelatedValue.ts +25 -4
- package/dist/src/resolveRemoteStorage.ts +3 -2
- package/dist/types/src/browser/db/read/getItem.d.ts.map +1 -1
- package/dist/types/src/browser/db/read/getItemProperties.d.ts.map +1 -1
- package/dist/types/src/browser/item/Item.d.ts.map +1 -1
- package/dist/types/src/browser/item/single/actors/reload.d.ts +5 -0
- package/dist/types/src/browser/item/single/actors/reload.d.ts.map +1 -0
- package/dist/types/src/browser/item/single/actors/saveDataToDb.d.ts +1 -55
- package/dist/types/src/browser/item/single/actors/saveDataToDb.d.ts.map +1 -1
- package/dist/types/src/browser/item/single/itemMachineSingle.d.ts +1 -56
- package/dist/types/src/browser/item/single/itemMachineSingle.d.ts.map +1 -1
- package/dist/types/src/browser/property/ItemProperty.d.ts +3 -111
- package/dist/types/src/browser/property/ItemProperty.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/hydrateFromDb.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/resolveRelatedValue.d.ts +4 -1
- package/dist/types/src/browser/property/actors/resolveRelatedValue.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/resolveRemoteStorage.d.ts +3 -55
- package/dist/types/src/browser/property/actors/resolveRemoteStorage.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as __decorate, a as __metadata } from './constants-rmQ8zg8_.js';
|
|
2
2
|
import 'drizzle-orm';
|
|
3
|
-
import { Text, Model } from './
|
|
3
|
+
import { T as Text, M as Model } from './index-nyYoS6hl.js';
|
|
4
4
|
import 'react';
|
|
5
5
|
import 'reflect-metadata';
|
|
6
6
|
import 'xstate';
|
|
@@ -76,4 +76,4 @@ const models = {
|
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
export { models };
|
|
79
|
-
//# sourceMappingURL=seed.schema.config-
|
|
79
|
+
//# sourceMappingURL=seed.schema.config-CaxQONHV.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seed.schema.config-
|
|
1
|
+
{"version":3,"file":"seed.schema.config-CaxQONHV.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;;;;;"}
|
package/dist/src/ItemProperty.ts
CHANGED
|
@@ -18,7 +18,6 @@ import { getModel } from '@/browser/stores/modelClass'
|
|
|
18
18
|
import { getCorrectId } from '@/browser/helpers'
|
|
19
19
|
import { Static } from '@sinclair/typebox'
|
|
20
20
|
import { TProperty } from '@/browser/property'
|
|
21
|
-
import { fs } from '@zenfs/core'
|
|
22
21
|
|
|
23
22
|
const logger = debug('app:property:class')
|
|
24
23
|
|
|
@@ -151,14 +150,6 @@ export class ItemProperty<PropertyType> {
|
|
|
151
150
|
const { context } = snapshot
|
|
152
151
|
const { propertyRecordSchema } = context
|
|
153
152
|
|
|
154
|
-
// if (this.uid && !cacheHasProperty(this.uid)) {
|
|
155
|
-
// addPropertyToCache(this)
|
|
156
|
-
// }
|
|
157
|
-
//
|
|
158
|
-
// if (!this.uid && this.localId && !cacheHasProperty(this.localId,)) {
|
|
159
|
-
// addPropertyToCache(this)
|
|
160
|
-
// }
|
|
161
|
-
|
|
162
153
|
if (context.seedLocalId) {
|
|
163
154
|
const cacheKey = ItemProperty.cacheKey(
|
|
164
155
|
context.seedLocalId,
|
|
@@ -179,19 +170,26 @@ export class ItemProperty<PropertyType> {
|
|
|
179
170
|
|
|
180
171
|
let renderValue
|
|
181
172
|
|
|
182
|
-
if (
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
173
|
+
// if (
|
|
174
|
+
// propertyRecordSchema &&
|
|
175
|
+
// propertyRecordSchema.storageType &&
|
|
176
|
+
// propertyRecordSchema.storageType === 'ItemStorage' &&
|
|
177
|
+
// context.resolvedValue &&
|
|
178
|
+
// context.localStorageDir
|
|
179
|
+
// ) {
|
|
180
|
+
// const filePath = `/files/${context.localStorageDir}/${context.resolvedValue}`
|
|
181
|
+
// try {
|
|
182
|
+
// const exists = await fs.promises.exists(filePath)
|
|
183
|
+
// if (exists) {
|
|
184
|
+
// renderValue = await fs.promises.readFile(filePath, 'utf-8')
|
|
185
|
+
// }
|
|
186
|
+
// } catch (e) {
|
|
187
|
+
// logger(
|
|
188
|
+
// `[ItemProperty] [${context.seedLocalId}] [${context.propertyName}] [storageType] error`,
|
|
189
|
+
// e,
|
|
190
|
+
// )
|
|
191
|
+
// }
|
|
192
|
+
// }
|
|
195
193
|
|
|
196
194
|
if (!renderValue) {
|
|
197
195
|
renderValue = context.renderValue || context.propertyValue
|
|
@@ -296,13 +294,11 @@ export class ItemProperty<PropertyType> {
|
|
|
296
294
|
const cacheKey = ItemProperty.cacheKey(cacheKeyId!, propertyName)
|
|
297
295
|
if (this.instanceCache.has(cacheKey)) {
|
|
298
296
|
const { instance, refCount } = this.instanceCache.get(cacheKey)!
|
|
297
|
+
instance.getService().send({ type: 'reload' })
|
|
299
298
|
this.instanceCache.set(cacheKey, {
|
|
300
299
|
instance,
|
|
301
300
|
refCount: refCount + 1,
|
|
302
301
|
})
|
|
303
|
-
if (instance.status === 'idle') {
|
|
304
|
-
instance.getService().send({ type: 'refresh' })
|
|
305
|
-
}
|
|
306
302
|
return instance
|
|
307
303
|
}
|
|
308
304
|
const propertyData = await getPropertyData(
|
package/dist/src/getItem.ts
CHANGED
|
@@ -83,46 +83,26 @@ export const getItemDataFromDb: GetItemDataFromDb = async ({
|
|
|
83
83
|
|
|
84
84
|
let itemData = itemDataRows[0]
|
|
85
85
|
|
|
86
|
-
const propertiesData = await getItemProperties({
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
// seedUid,
|
|
91
|
-
// modelName,
|
|
92
|
-
// }
|
|
86
|
+
const propertiesData = await getItemProperties({
|
|
87
|
+
seedLocalId,
|
|
88
|
+
seedUid: itemData.seedUid || undefined,
|
|
89
|
+
})
|
|
93
90
|
|
|
94
91
|
if (!propertiesData || propertiesData.length === 0) {
|
|
95
92
|
return itemData
|
|
96
93
|
}
|
|
97
94
|
|
|
98
|
-
const firstPropertyData = propertiesData[0]
|
|
99
|
-
|
|
100
95
|
for (const propertyData of propertiesData) {
|
|
101
96
|
const propertyName = propertyData.propertyName
|
|
102
97
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
// if (refSeedType) {
|
|
112
|
-
// initObj.refSeedType = refSeedType
|
|
113
|
-
// }
|
|
114
|
-
// const refValueType = propertyDbValues[12]
|
|
115
|
-
// if (refValueType) {
|
|
116
|
-
// initObj.refValueType = refValueType
|
|
117
|
-
// }
|
|
118
|
-
//
|
|
119
|
-
// if (
|
|
120
|
-
// refSeedType &&
|
|
121
|
-
// refValueType === 'list' &&
|
|
122
|
-
// propertyName.endsWith('Ids')
|
|
123
|
-
// ) {
|
|
124
|
-
// logger('[db/queries] [getItemDataFromDb] propertyName', propertyName)
|
|
125
|
-
// }
|
|
98
|
+
let propertyValue = propertyData.propertyValue
|
|
99
|
+
|
|
100
|
+
if (propertyName.endsWith('Id') || propertyName.endsWith('Ids')) {
|
|
101
|
+
if (propertyData.refSeedType) {
|
|
102
|
+
const propertyNameVariant = propertyName.replace(/Ids?$/, '')
|
|
103
|
+
itemData[propertyNameVariant] = propertyValue
|
|
104
|
+
}
|
|
105
|
+
}
|
|
126
106
|
|
|
127
107
|
itemData[propertyName] = propertyValue
|
|
128
108
|
}
|
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import { PropertyData } from '@/types'
|
|
2
2
|
import { getAppDb } from '@/browser/db/sqlWasmClient'
|
|
3
3
|
import { metadata, seeds, versions } from '@/shared/seedSchema'
|
|
4
|
-
import {
|
|
5
|
-
and,
|
|
6
|
-
eq,
|
|
7
|
-
getTableColumns,
|
|
8
|
-
isNotNull,
|
|
9
|
-
isNull,
|
|
10
|
-
or,
|
|
11
|
-
SQL,
|
|
12
|
-
} from 'drizzle-orm'
|
|
4
|
+
import { and, eq, getTableColumns, isNotNull, isNull, SQL } from 'drizzle-orm'
|
|
13
5
|
|
|
14
6
|
type GetPropertiesForSeedProps = {
|
|
15
7
|
seedLocalId?: string
|
|
@@ -30,16 +22,24 @@ export const getItemProperties: GetItemProperties = async ({
|
|
|
30
22
|
|
|
31
23
|
const whereClauses: SQL[] = [isNotNull(metadata.propertyName)]
|
|
32
24
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
25
|
+
if (seedUid) {
|
|
26
|
+
whereClauses.push(eq(seeds.uid, seedUid))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (seedLocalId) {
|
|
30
|
+
whereClauses.push(eq(seeds.localId, seedLocalId))
|
|
31
|
+
}
|
|
39
32
|
|
|
40
|
-
|
|
33
|
+
// const uidWhereClause: SQL = seedUid
|
|
34
|
+
// ? eq(seeds.uid, seedUid)
|
|
35
|
+
// : isNull(seeds.uid)
|
|
36
|
+
// const localWhereClause: SQL = seedLocalId
|
|
37
|
+
// ? eq(seeds.localId, seedLocalId)
|
|
38
|
+
// : isNull(seeds.localId)
|
|
39
|
+
|
|
40
|
+
// whereClauses.push(or(localWhereClause, uidWhereClause) as SQL)
|
|
41
41
|
whereClauses.push(isNotNull(metadata.propertyName))
|
|
42
|
-
whereClauses.push(isNotNull(metadata.easDataType))
|
|
42
|
+
// whereClauses.push(isNotNull(metadata.easDataType))
|
|
43
43
|
|
|
44
44
|
if (typeof edited !== 'undefined') {
|
|
45
45
|
if (edited) {
|
|
@@ -50,21 +50,6 @@ export const getItemProperties: GetItemProperties = async ({
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
// if (!seedLocalId || !seedUid) {
|
|
54
|
-
// const seedRows = await appDb
|
|
55
|
-
// .select({
|
|
56
|
-
// localId: seeds.localId,
|
|
57
|
-
// uid: seeds.uid,
|
|
58
|
-
// })
|
|
59
|
-
// .from(seeds)
|
|
60
|
-
// .where(or(localWhereClause, uidWhereClause))
|
|
61
|
-
//
|
|
62
|
-
// if (seedRows && seedRows.length > 0) {
|
|
63
|
-
// seedUid = seedRows[0].uid as string
|
|
64
|
-
// seedLocalId = seedRows[0].localId as string
|
|
65
|
-
// }
|
|
66
|
-
// }
|
|
67
|
-
|
|
68
53
|
const metadataColumns = getTableColumns(metadata)
|
|
69
54
|
|
|
70
55
|
const propertiesData = await appDb
|
|
@@ -79,84 +64,3 @@ export const getItemProperties: GetItemProperties = async ({
|
|
|
79
64
|
|
|
80
65
|
return propertiesData
|
|
81
66
|
}
|
|
82
|
-
|
|
83
|
-
// const localIdWhere = seedLocalId
|
|
84
|
-
// ? `s.local_id = '${seedLocalId}'`
|
|
85
|
-
// : 's.local_id IS NULL'
|
|
86
|
-
// const uidWhere = seedUid ? `s.uid = '${seedUid}'` : 's.uid IS NULL'
|
|
87
|
-
//
|
|
88
|
-
// const queryStatement = `WITH LatestMetadata as (SELECT m.property_name,
|
|
89
|
-
// m.property_value,
|
|
90
|
-
// m.version_local_id,
|
|
91
|
-
// MAX(m.attestation_created_at),
|
|
92
|
-
// m.uid,
|
|
93
|
-
// m.seed_local_id,
|
|
94
|
-
// seed_uid
|
|
95
|
-
// FROM metadata m
|
|
96
|
-
// JOIN seeds s ON s.local_id = m.seed_local_id
|
|
97
|
-
// GROUP BY m.property_name),
|
|
98
|
-
//
|
|
99
|
-
// LatestVersion as (SELECT v.local_id,
|
|
100
|
-
// MAX(v.attestation_created_at) as attestation_created_at,
|
|
101
|
-
// v.uid,
|
|
102
|
-
// v.seed_local_id,
|
|
103
|
-
// v.seed_uid
|
|
104
|
-
// FROM versions v
|
|
105
|
-
// JOIN seeds s ON s.local_id = v.seed_local_id
|
|
106
|
-
// GROUP BY s.local_id)
|
|
107
|
-
//
|
|
108
|
-
//
|
|
109
|
-
// SELECT s.local_id,
|
|
110
|
-
// s.uid,
|
|
111
|
-
// s.schema_uid,
|
|
112
|
-
// m.property_name,
|
|
113
|
-
// m.property_value,
|
|
114
|
-
// COUNT(v.local_id) as versions_count,
|
|
115
|
-
// m.model_type,
|
|
116
|
-
// lv.attestation_created_at,
|
|
117
|
-
// m.local_id,
|
|
118
|
-
// m.uid,
|
|
119
|
-
// MAX(m.attestation_created_at),
|
|
120
|
-
// m.ref_seed_type,
|
|
121
|
-
// m.ref_value_type,
|
|
122
|
-
// m.seed_local_id,
|
|
123
|
-
// m.seed_uid,
|
|
124
|
-
// m.created_at,
|
|
125
|
-
// m.updated_at,
|
|
126
|
-
// m.version_uid
|
|
127
|
-
// FROM seeds s
|
|
128
|
-
// JOIN LatestMetadata lm ON s.local_id = m.seed_local_id
|
|
129
|
-
// JOIN LatestVersion lv ON lv.seed_local_id = m.seed_local_id
|
|
130
|
-
// JOIN metadata m ON m.property_name = lm.property_name OR lm.property_value = s.uid
|
|
131
|
-
// JOIN versions v ON s.local_id = v.seed_local_id
|
|
132
|
-
// WHERE ${localIdWhere}
|
|
133
|
-
// OR ${uidWhere}
|
|
134
|
-
// GROUP BY m.property_name;
|
|
135
|
-
// `
|
|
136
|
-
//
|
|
137
|
-
// const { rows } = await runQueryForStatement(queryStatement)
|
|
138
|
-
//
|
|
139
|
-
// const propertiesDataOld: PropertyData[] = []
|
|
140
|
-
//
|
|
141
|
-
// for (const row of rows) {
|
|
142
|
-
// propertiesDataOld.push({
|
|
143
|
-
// localId: row[0],
|
|
144
|
-
// uid: row[1],
|
|
145
|
-
// schemaUid: row[2],
|
|
146
|
-
// propertyName: row[3],
|
|
147
|
-
// propertyValue: row[4],
|
|
148
|
-
// versionsCount: row[5],
|
|
149
|
-
// itemModelName: row[6],
|
|
150
|
-
// attestationCreatedAt: row[7],
|
|
151
|
-
// metadataLocalId: row[8],
|
|
152
|
-
// metadataUid: row[9],
|
|
153
|
-
// metadataAttestationCreatedAt: row[10],
|
|
154
|
-
// refSeedType: row[11],
|
|
155
|
-
// refValueType: row[12],
|
|
156
|
-
// seedLocalId: row[13],
|
|
157
|
-
// seedUid: row[14],
|
|
158
|
-
// createdAt: row[15],
|
|
159
|
-
// updatedAt: row[16],
|
|
160
|
-
// versionUid: row[17],
|
|
161
|
-
// })
|
|
162
|
-
// }
|
|
@@ -48,25 +48,6 @@ export const hydrateFromDb = fromCallback<
|
|
|
48
48
|
|
|
49
49
|
const whereClauses = []
|
|
50
50
|
|
|
51
|
-
let hydrateQuery
|
|
52
|
-
// let safeValue = propertyValue
|
|
53
|
-
// let propertyValueQueryString = `property_value `
|
|
54
|
-
// let propertyNameQueryString = `property_name = '${propertyName}'`
|
|
55
|
-
let propertyNameQuery = eq(metadata.propertyName, propertyName)
|
|
56
|
-
|
|
57
|
-
// if (safeValue && typeof propertyValue === 'string') {
|
|
58
|
-
// safeValue = escapeSqliteString(propertyValue)
|
|
59
|
-
// propertyValueQueryString += `= '${safeValue}'`
|
|
60
|
-
// }
|
|
61
|
-
|
|
62
|
-
// if (!safeValue) {
|
|
63
|
-
// propertyValueQueryString += 'IS NULL'
|
|
64
|
-
// }
|
|
65
|
-
|
|
66
|
-
// if (typeof propertyValue === 'number') {
|
|
67
|
-
// propertyValueQueryString += `= ${propertyValue}`
|
|
68
|
-
// }
|
|
69
|
-
|
|
70
51
|
if (
|
|
71
52
|
propertyRecordSchema &&
|
|
72
53
|
propertyRecordSchema.ref &&
|
|
@@ -86,44 +67,22 @@ export const hydrateFromDb = fromCallback<
|
|
|
86
67
|
eq(metadata.propertyName, missingPropertyNameVariant),
|
|
87
68
|
),
|
|
88
69
|
)
|
|
89
|
-
// propertyNameQuery = or(
|
|
90
|
-
// eq(metadata.propertyName, propertyName),
|
|
91
|
-
// eq(metadata.propertyName, missingPropertyNameVariant),
|
|
92
|
-
// )
|
|
93
70
|
}
|
|
94
71
|
if (!missingPropertyNameVariant) {
|
|
95
72
|
whereClauses.push(eq(metadata.propertyName, propertyName))
|
|
96
73
|
}
|
|
74
|
+
} else {
|
|
75
|
+
whereClauses.push(eq(metadata.propertyName, propertyName))
|
|
97
76
|
}
|
|
98
77
|
|
|
99
|
-
// if (seedUid && !seedLocalId) {
|
|
100
|
-
// hydrateQuery = selectFromStatement.where(
|
|
101
|
-
// and(eq(metadata.seedUid, seedUid), propertyNameQuery),
|
|
102
|
-
// )
|
|
103
|
-
// }
|
|
104
|
-
|
|
105
78
|
if (seedUid) {
|
|
106
|
-
// hydrateQuery = selectFromStatement.where(
|
|
107
|
-
// and(
|
|
108
|
-
// eq(metadata.seedLocalId, seedLocalId),
|
|
109
|
-
// eq(metadata.seedUid, seedUid),
|
|
110
|
-
// propertyNameQuery,
|
|
111
|
-
// ),
|
|
112
|
-
// )
|
|
113
79
|
whereClauses.push(eq(metadata.seedUid, seedUid))
|
|
114
80
|
}
|
|
115
81
|
|
|
116
82
|
if (seedLocalId) {
|
|
117
|
-
// hydrateQuery = selectFromStatement.where(
|
|
118
|
-
// and(eq(metadata.seedLocalId, seedLocalId), propertyNameQuery),
|
|
119
|
-
// )
|
|
120
83
|
whereClauses.push(eq(metadata.seedLocalId, seedLocalId))
|
|
121
84
|
}
|
|
122
85
|
|
|
123
|
-
if (!hydrateQuery) {
|
|
124
|
-
return
|
|
125
|
-
}
|
|
126
|
-
|
|
127
86
|
const rows = await appDb
|
|
128
87
|
.select()
|
|
129
88
|
.from(metadata)
|
|
@@ -193,26 +152,31 @@ export const hydrateFromDb = fromCallback<
|
|
|
193
152
|
}
|
|
194
153
|
|
|
195
154
|
if (
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
refResolvedDisplayValue.includes('http')
|
|
155
|
+
propertyRecordSchema &&
|
|
156
|
+
propertyRecordSchema.refValueType === 'ImageSrc'
|
|
199
157
|
) {
|
|
200
|
-
let
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
158
|
+
let shouldReadFromFile = true
|
|
159
|
+
|
|
160
|
+
if (
|
|
161
|
+
refResolvedValue &&
|
|
162
|
+
refResolvedDisplayValue &&
|
|
163
|
+
refResolvedDisplayValue.includes('http')
|
|
164
|
+
) {
|
|
165
|
+
try {
|
|
166
|
+
const response = await fetch(refResolvedDisplayValue, {
|
|
167
|
+
method: 'HEAD',
|
|
168
|
+
})
|
|
206
169
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
170
|
+
// Check if the status is in the 200-299 range
|
|
171
|
+
if (response.ok) {
|
|
172
|
+
shouldReadFromFile = false
|
|
173
|
+
}
|
|
174
|
+
} catch (error) {
|
|
175
|
+
shouldReadFromFile = true
|
|
210
176
|
}
|
|
211
|
-
} catch (error) {
|
|
212
|
-
urlNeedsToBeRefreshed = true
|
|
213
177
|
}
|
|
214
178
|
|
|
215
|
-
if (
|
|
179
|
+
if (shouldReadFromFile) {
|
|
216
180
|
let dir = localStorageDir
|
|
217
181
|
if (
|
|
218
182
|
!dir &&
|
package/dist/src/item.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { initialize } from './actors/initialize'
|
|
|
7
7
|
import { hydrateExistingItem } from './actors/hydrateExistingItem'
|
|
8
8
|
import { hydrateNewItem } from './actors/hydrateNewItem'
|
|
9
9
|
import { fetchDataFromEas } from './actors/fetchDataFromEas'
|
|
10
|
+
import { reload } from '@/browser/item/single/actors/reload'
|
|
10
11
|
|
|
11
12
|
export const itemMachineSingle = setup({
|
|
12
13
|
types: {
|
|
@@ -19,6 +20,7 @@ export const itemMachineSingle = setup({
|
|
|
19
20
|
hydrateExistingItem,
|
|
20
21
|
hydrateNewItem,
|
|
21
22
|
fetchDataFromEas,
|
|
23
|
+
reload,
|
|
22
24
|
},
|
|
23
25
|
}).createMachine({
|
|
24
26
|
id: MachineIds.ITEM,
|
|
@@ -75,17 +77,7 @@ export const itemMachineSingle = setup({
|
|
|
75
77
|
}
|
|
76
78
|
}),
|
|
77
79
|
},
|
|
78
|
-
|
|
79
|
-
// actions: assign(({ context, event }) => {
|
|
80
|
-
// console.log('[singleItemMachine] [addPropertyAttestation] event', event)
|
|
81
|
-
// const propertyInstances =
|
|
82
|
-
// context.propertyInstances || new Map<string, typeof ItemProperty>()
|
|
83
|
-
// propertyInstances.set(event.propertyName, event.propertyInstances)
|
|
84
|
-
// return {
|
|
85
|
-
// propertyInstances,
|
|
86
|
-
// }
|
|
87
|
-
// }),
|
|
88
|
-
// },
|
|
80
|
+
reload: '.reloading',
|
|
89
81
|
},
|
|
90
82
|
states: {
|
|
91
83
|
idle: {},
|
|
@@ -150,24 +142,15 @@ export const itemMachineSingle = setup({
|
|
|
150
142
|
input: ({ context }) => ({ context }),
|
|
151
143
|
},
|
|
152
144
|
},
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
// savingDataToDb: {
|
|
163
|
-
// on: {
|
|
164
|
-
// saveDataToDbSuccess: 'idle',
|
|
165
|
-
// },
|
|
166
|
-
// invoke: {
|
|
167
|
-
// src: 'saveDataToDb',
|
|
168
|
-
// input: ({ context }) => ({ context }),
|
|
169
|
-
// },
|
|
170
|
-
// },
|
|
145
|
+
reloading: {
|
|
146
|
+
on: {
|
|
147
|
+
reloadSuccess: 'idle',
|
|
148
|
+
},
|
|
149
|
+
invoke: {
|
|
150
|
+
src: 'reload',
|
|
151
|
+
input: ({ context }) => ({ context }),
|
|
152
|
+
},
|
|
153
|
+
},
|
|
171
154
|
destroying: {
|
|
172
155
|
type: 'final',
|
|
173
156
|
},
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { EventObject, fromCallback } from 'xstate'
|
|
2
|
+
import { FromCallbackInput } from '@/types/machines'
|
|
3
|
+
import { ItemMachineContext } from '@/types/item'
|
|
4
|
+
|
|
5
|
+
export const reload = fromCallback<
|
|
6
|
+
EventObject,
|
|
7
|
+
FromCallbackInput<ItemMachineContext<any>>
|
|
8
|
+
>(({ sendBack, input: { context } }) => {
|
|
9
|
+
const { propertyInstances } = context
|
|
10
|
+
|
|
11
|
+
const _reload = async () => {
|
|
12
|
+
if (!propertyInstances) {
|
|
13
|
+
return
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
for (const propertyInstance of propertyInstances.values()) {
|
|
17
|
+
if (propertyInstance) {
|
|
18
|
+
const propertyRecordSchema = propertyInstance.propertyDef
|
|
19
|
+
if (
|
|
20
|
+
propertyRecordSchema &&
|
|
21
|
+
propertyRecordSchema.storageType &&
|
|
22
|
+
propertyRecordSchema.storageType === 'ItemStorage'
|
|
23
|
+
) {
|
|
24
|
+
propertyInstance.getService().send({ type: 'reload' })
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
_reload().then(() => {
|
|
31
|
+
sendBack({ type: 'reloadSuccess' })
|
|
32
|
+
})
|
|
33
|
+
})
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { EventObject, fromCallback } from 'xstate'
|
|
2
2
|
import { convertTxIdToImageSrc } from '@/shared/helpers'
|
|
3
|
-
import { propertyMachine } from '../propertyMachine'
|
|
4
3
|
import { fs } from '@zenfs/core'
|
|
5
4
|
import {
|
|
6
5
|
getRelationValueData,
|
|
7
6
|
getStorageTransactionIdForSeedUid,
|
|
8
7
|
} from '@/browser/db/read'
|
|
8
|
+
import debug from 'debug'
|
|
9
|
+
import { FromCallbackInput } from '@/types/machines'
|
|
10
|
+
import { PropertyMachineContext } from '@/types/property'
|
|
11
|
+
|
|
12
|
+
const logger = debug('app:property:actors:resolveRelatedValue')
|
|
9
13
|
|
|
10
14
|
const storageTransactionIdToContentUrl = new Map<string, string>()
|
|
11
15
|
const refResolvedValueToContentUrl = new Map<string, string>()
|
|
@@ -13,7 +17,7 @@ const seedUidToContentUrl = new Map<string, string>()
|
|
|
13
17
|
|
|
14
18
|
export const resolveRelatedValue = fromCallback<
|
|
15
19
|
EventObject,
|
|
16
|
-
|
|
20
|
+
FromCallbackInput<PropertyMachineContext, EventObject>
|
|
17
21
|
>(({ sendBack, input: { context } }) => {
|
|
18
22
|
const {
|
|
19
23
|
isRelation,
|
|
@@ -30,7 +34,15 @@ export const resolveRelatedValue = fromCallback<
|
|
|
30
34
|
return
|
|
31
35
|
}
|
|
32
36
|
|
|
33
|
-
|
|
37
|
+
let parsedValue
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
parsedValue = JSON.parse(propertyValue)
|
|
41
|
+
} catch (error) {
|
|
42
|
+
logger(`${propertyName} value is not a JSON string.`)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!parsedValue && seedUidToContentUrl.has(propertyValue)) {
|
|
34
46
|
const contentUrl = seedUidToContentUrl.get(propertyValue)
|
|
35
47
|
sendBack({
|
|
36
48
|
type: 'updateRenderValue',
|
|
@@ -45,6 +57,12 @@ export const resolveRelatedValue = fromCallback<
|
|
|
45
57
|
|
|
46
58
|
if (Array.isArray(propertyValue)) {
|
|
47
59
|
// TODO: Handle array of seedUids
|
|
60
|
+
logger(`${propertyName} value is an array of seedUids`)
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (Array.isArray(parsedValue)) {
|
|
65
|
+
logger(`${propertyName} value is a stringified array of seedUids`)
|
|
48
66
|
return
|
|
49
67
|
}
|
|
50
68
|
|
|
@@ -133,7 +151,10 @@ export const resolveRelatedValue = fromCallback<
|
|
|
133
151
|
|
|
134
152
|
if (typeof propertyValueFromDb === 'string') {
|
|
135
153
|
// Check files for a filename that matches the propertyValue
|
|
136
|
-
if (
|
|
154
|
+
if (
|
|
155
|
+
propertyRecordSchema &&
|
|
156
|
+
propertyRecordSchema.refValueType === 'ImageSrc'
|
|
157
|
+
) {
|
|
137
158
|
let contentUrl
|
|
138
159
|
|
|
139
160
|
if (storageTransactionIdToContentUrl.has(propertyValueFromDb)) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { EventObject, fromCallback } from 'xstate'
|
|
2
|
-
import {
|
|
2
|
+
import { FromCallbackInput } from '@/types/machines'
|
|
3
|
+
import { PropertyMachineContext } from '@/types/property'
|
|
3
4
|
|
|
4
5
|
export const resolveRemoteStorage = fromCallback<
|
|
5
6
|
EventObject,
|
|
6
|
-
|
|
7
|
+
FromCallbackInput<PropertyMachineContext, EventObject>
|
|
7
8
|
>(({ sendBack, input: { context } }) => {
|
|
8
9
|
const { propertyInstances } = context
|
|
9
10
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getItem.d.ts","sourceRoot":"","sources":["../../../../../../src/browser/db/read/getItem.ts"],"names":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"file":"getItemProperties.d.ts","sourceRoot":"","sources":["../../../../../../src/browser/db/read/getItemProperties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"getItemProperties.d.ts","sourceRoot":"","sources":["../../../../../../src/browser/db/read/getItemProperties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAKtC,KAAK,yBAAyB,GAAG;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,KAAK,iBAAiB,GAAG,CACvB,KAAK,EAAE,yBAAyB,KAC7B,OAAO,CAAC,YAAY,EAAE,CAAC,CAAA;AAE5B,eAAO,MAAM,iBAAiB,EAAE,iBAkD/B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Item.d.ts","sourceRoot":"","sources":["../../../../../src/browser/item/Item.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EACR,aAAa,EACb,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACb,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,YAAY,EAAe,YAAY,EAAE,MAAM,QAAQ,CAAA;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAYjC,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAGhE,qBAAa,IAAI,CAAC,CAAC,SAAS,WAAW,CAAC,WAAW,CAAC;IAClD,OAAO,CAAC,MAAM,CAAC,aAAa,CAGf;IACb,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwC;IACjE,OAAO,CAAC,aAAa,CAA0B;IA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AC,CAAC;WAoDR,IAAI,CAAC,EAChB,SAAS,EACT,WAAW,EACX,OAAO,GACR,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;WAqBpC,GAAG,CACd,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,OAAO,GAChB,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;WAeV,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAcpD,OAAO,CAAC,uBAAuB;IAwB/B,SAAS,aAAc,CAAC,SAAS,EAAE,GAAG,KAAK,IAAI,KAAG,YAAY,CAI7D;IAED,UAAU,QAAO,YAAY,CAAC,OAAO,iBAAiB,CAAC,CAEtD;IAED,mBAAmB,QAAa,OAAO,CAAC,YAAY,EAAE,CAAC,CAKtD;IAED,OAAO,QAAa,OAAO,CAAC,IAAI,CAAC,CAYhC;IAED,iBAAiB,sBAEhB;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,IAAI,OAAO,IAAI,MAAM,GAAG,SAAS,CAEhC;IAED,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,IAAI,gBAAgB,IAAI,YAAY,CAEnC;IAED,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,IAAI,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC,CAElD;IAED,MAAM,IAAI,IAAI;CAIf"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { EventObject } from 'xstate';
|
|
2
|
+
import { FromCallbackInput } from '@/types/machines';
|
|
3
|
+
import { ItemMachineContext } from '@/types/item';
|
|
4
|
+
export declare const reload: import("xstate").CallbackActorLogic<EventObject, FromCallbackInput<ItemMachineContext<any>>, EventObject>;
|
|
5
|
+
//# sourceMappingURL=reload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reload.d.ts","sourceRoot":"","sources":["../../../../../../../src/browser/item/single/actors/reload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAgB,MAAM,QAAQ,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEjD,eAAO,MAAM,MAAM,2GA4BjB,CAAA"}
|