@seedprotocol/sdk 0.1.74 → 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 -6
- package/dist/bin.js.map +1 -1
- package/dist/{constants-CtmwCBma.js → constants-rmQ8zg8_.js} +2 -1
- package/dist/{constants-CtmwCBma.js.map → constants-rmQ8zg8_.js.map} +1 -1
- package/dist/{index-3ASvLLXY.js → index-D5bGQvS6.js} +3 -3
- package/dist/{index-3ASvLLXY.js.map → index-D5bGQvS6.js.map} +1 -1
- package/dist/{index-Br7jo_vg.js → index-nyYoS6hl.js} +254 -333
- package/dist/index-nyYoS6hl.js.map +1 -0
- package/dist/main.js +2 -2
- package/dist/{seed.schema.config-BHNlL53f.js → seed.schema.config-CaxQONHV.js} +3 -3
- package/dist/{seed.schema.config-BHNlL53f.js.map → seed.schema.config-CaxQONHV.js.map} +1 -1
- package/dist/src/ItemProperty.ts +21 -25
- package/dist/src/actors.ts +7 -282
- package/dist/src/analyzeInput.ts +102 -0
- package/dist/src/db.ts +0 -29
- package/dist/src/drizzle.ts +0 -4
- package/dist/src/getItem.ts +12 -32
- package/dist/src/getItemProperties.ts +17 -113
- package/dist/src/hydrateFromDb.ts +198 -218
- package/dist/src/index.ts +10 -62
- package/dist/src/item.ts +1 -2
- package/dist/src/itemMachineSingle.ts +12 -29
- package/dist/src/propertyMachine.ts +3 -14
- package/dist/src/reload.ts +33 -0
- package/dist/src/request.ts +0 -9
- package/dist/src/resolveRelatedValue.ts +25 -4
- package/dist/src/resolveRemoteStorage.ts +3 -2
- package/dist/src/saveImageSrc.ts +0 -4
- package/dist/src/services.ts +0 -3
- package/dist/src/updateItemPropertyValue.ts +1 -0
- package/dist/src/waitForFiles.ts +33 -0
- 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/db/write/updateItemPropertyValue.d.ts.map +1 -1
- package/dist/types/src/browser/events/item/request.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 +4 -112
- package/dist/types/src/browser/property/ItemProperty.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/hydrateFromDb.d.ts +4 -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/dist/types/src/browser/property/actors/saveValueToDb/analyzeInput.d.ts +5 -0
- package/dist/types/src/browser/property/actors/saveValueToDb/analyzeInput.d.ts.map +1 -0
- package/dist/types/src/browser/property/actors/saveValueToDb/index.d.ts +1 -4
- package/dist/types/src/browser/property/actors/saveValueToDb/index.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/saveValueToDb/saveImageSrc.d.ts.map +1 -1
- package/dist/types/src/browser/property/propertyMachine.d.ts.map +1 -1
- package/dist/types/src/browser/react/item.d.ts.map +1 -1
- package/dist/types/src/browser/react/services.d.ts.map +1 -1
- package/dist/types/src/browser/services/db/actors/waitForFiles.d.ts +4 -0
- package/dist/types/src/browser/services/db/actors/waitForFiles.d.ts.map +1 -0
- package/dist/types/src/node/codegen/drizzle.d.ts.map +1 -1
- package/dist/types/src/node/constants.d.ts.map +1 -1
- package/dist/types/src/node/webpack/index.d.ts.map +1 -1
- package/dist/types/src/shared/helpers/constants.d.ts.map +1 -1
- package/dist/types/src/shared/helpers/db.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/index-Br7jo_vg.js.map +0 -1
|
@@ -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
|
-
// }
|
|
@@ -1,277 +1,257 @@
|
|
|
1
1
|
import { EventObject, fromCallback } from 'xstate'
|
|
2
|
-
import { propertyMachine } from '../propertyMachine'
|
|
3
2
|
import { and, eq, or, sql } from 'drizzle-orm'
|
|
4
|
-
import { escapeSqliteString } from '@/shared/helpers/db'
|
|
5
3
|
import debug from 'debug'
|
|
6
4
|
import { fs } from '@zenfs/core'
|
|
7
5
|
import { metadata } from 'src/shared/seedSchema'
|
|
8
6
|
import { getAppDb } from '@/browser/db/sqlWasmClient'
|
|
9
7
|
import { updateMetadata } from '@/browser/db/write/updateMetadata'
|
|
8
|
+
import { FromCallbackInput } from '@/types/machines'
|
|
9
|
+
import { PropertyMachineContext } from '@/types/property'
|
|
10
10
|
|
|
11
11
|
const logger = debug('app:property:actors:hydrateFromDb')
|
|
12
12
|
|
|
13
|
-
export const hydrateFromDb = fromCallback<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
export const hydrateFromDb = fromCallback<
|
|
14
|
+
EventObject,
|
|
15
|
+
FromCallbackInput<PropertyMachineContext, EventObject>
|
|
16
|
+
>(({ sendBack, input: { context } }) => {
|
|
17
|
+
const {
|
|
18
|
+
seedUid,
|
|
19
|
+
seedLocalId,
|
|
20
|
+
propertyName: propertyNameRaw,
|
|
21
|
+
propertyValue,
|
|
22
|
+
propertyRecordSchema,
|
|
23
|
+
itemModelName,
|
|
24
|
+
} = context
|
|
25
|
+
|
|
26
|
+
let propertyName = propertyNameRaw
|
|
27
|
+
|
|
28
|
+
if (
|
|
29
|
+
propertyRecordSchema &&
|
|
30
|
+
propertyRecordSchema.ref &&
|
|
31
|
+
propertyRecordSchema.dataType === 'Relation' &&
|
|
32
|
+
!propertyNameRaw.endsWith('Id')
|
|
33
|
+
) {
|
|
34
|
+
propertyName = propertyNameRaw + 'Id'
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (
|
|
38
|
+
propertyRecordSchema &&
|
|
39
|
+
propertyRecordSchema.ref &&
|
|
40
|
+
propertyRecordSchema.dataType === 'List' &&
|
|
41
|
+
!propertyNameRaw.endsWith('Ids')
|
|
42
|
+
) {
|
|
43
|
+
propertyName = propertyNameRaw + 'Ids'
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const _hydrateFromDb = async () => {
|
|
47
|
+
const appDb = getAppDb()
|
|
48
|
+
|
|
49
|
+
const whereClauses = []
|
|
25
50
|
|
|
26
51
|
if (
|
|
27
52
|
propertyRecordSchema &&
|
|
28
53
|
propertyRecordSchema.ref &&
|
|
29
|
-
propertyRecordSchema.dataType === 'Relation'
|
|
30
|
-
!propertyNameRaw.endsWith('Id')
|
|
54
|
+
propertyRecordSchema.dataType === 'Relation'
|
|
31
55
|
) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
propertyRecordSchema &&
|
|
37
|
-
propertyRecordSchema.ref &&
|
|
38
|
-
propertyRecordSchema.dataType === 'List' &&
|
|
39
|
-
!propertyNameRaw.endsWith('Ids')
|
|
40
|
-
) {
|
|
41
|
-
propertyName = propertyNameRaw + 'Ids'
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const _hydrateFromDb = async () => {
|
|
45
|
-
const db = getAppDb()
|
|
46
|
-
|
|
47
|
-
let hydrateQuery
|
|
48
|
-
let safeValue = propertyValue
|
|
49
|
-
let propertyValueQueryString = `property_value `
|
|
50
|
-
let propertyNameQueryString = `property_name = '${propertyName}'`
|
|
51
|
-
let propertyNameQuery = eq(metadata.propertyName, propertyName)
|
|
52
|
-
|
|
53
|
-
if (safeValue && typeof propertyValue === 'string') {
|
|
54
|
-
safeValue = escapeSqliteString(propertyValue)
|
|
55
|
-
propertyValueQueryString += `= '${safeValue}'`
|
|
56
|
+
let missingPropertyNameVariant
|
|
57
|
+
if (propertyName.endsWith('Id')) {
|
|
58
|
+
missingPropertyNameVariant = propertyName.slice(0, -2)
|
|
56
59
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
propertyValueQueryString += 'IS NULL'
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (typeof propertyValue === 'number') {
|
|
63
|
-
propertyValueQueryString += `= ${propertyValue}`
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
propertyRecordSchema &&
|
|
68
|
-
propertyRecordSchema.ref &&
|
|
69
|
-
propertyRecordSchema.dataType === 'Relation'
|
|
70
|
-
) {
|
|
71
|
-
let missingPropertyNameVariant
|
|
72
|
-
if (propertyName.endsWith('Id')) {
|
|
73
|
-
missingPropertyNameVariant = propertyName.slice(0, -2)
|
|
74
|
-
}
|
|
75
|
-
if (!propertyName.endsWith('Id')) {
|
|
76
|
-
missingPropertyNameVariant = propertyName + 'Id'
|
|
77
|
-
}
|
|
78
|
-
propertyNameQuery = or(
|
|
79
|
-
eq(metadata.propertyName, propertyName),
|
|
80
|
-
eq(metadata.propertyName, missingPropertyNameVariant),
|
|
81
|
-
)
|
|
60
|
+
if (!propertyName.endsWith('Id')) {
|
|
61
|
+
missingPropertyNameVariant = propertyName + 'Id'
|
|
82
62
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
and(eq(metadata.seedUid, seedUid), propertyNameQuery),
|
|
89
|
-
)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (seedUid && seedLocalId) {
|
|
93
|
-
hydrateQuery = selectFromStatement.where(
|
|
94
|
-
and(
|
|
95
|
-
eq(metadata.seedLocalId, seedLocalId),
|
|
96
|
-
eq(metadata.seedUid, seedUid),
|
|
97
|
-
propertyNameQuery,
|
|
63
|
+
if (missingPropertyNameVariant) {
|
|
64
|
+
whereClauses.push(
|
|
65
|
+
or(
|
|
66
|
+
eq(metadata.propertyName, propertyName),
|
|
67
|
+
eq(metadata.propertyName, missingPropertyNameVariant),
|
|
98
68
|
),
|
|
99
69
|
)
|
|
100
70
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
hydrateQuery = selectFromStatement.where(
|
|
104
|
-
and(eq(metadata.seedLocalId, seedLocalId), propertyNameQuery),
|
|
105
|
-
)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (!hydrateQuery) {
|
|
109
|
-
return
|
|
71
|
+
if (!missingPropertyNameVariant) {
|
|
72
|
+
whereClauses.push(eq(metadata.propertyName, propertyName))
|
|
110
73
|
}
|
|
74
|
+
} else {
|
|
75
|
+
whereClauses.push(eq(metadata.propertyName, propertyName))
|
|
76
|
+
}
|
|
111
77
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
78
|
+
if (seedUid) {
|
|
79
|
+
whereClauses.push(eq(metadata.seedUid, seedUid))
|
|
80
|
+
}
|
|
115
81
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
82
|
+
if (seedLocalId) {
|
|
83
|
+
whereClauses.push(eq(metadata.seedLocalId, seedLocalId))
|
|
84
|
+
}
|
|
119
85
|
|
|
120
|
-
|
|
86
|
+
const rows = await appDb
|
|
87
|
+
.select()
|
|
88
|
+
.from(metadata)
|
|
89
|
+
.where(and(...whereClauses))
|
|
90
|
+
.orderBy(sql.raw('COALESCE(attestation_created_at, created_at) DESC'))
|
|
121
91
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
propertyName: propertyNameFromDb,
|
|
126
|
-
propertyValue: propertyValueFromDb,
|
|
127
|
-
seedLocalId: seedLocalIdFromDb,
|
|
128
|
-
seedUid: seedUidFromDb,
|
|
129
|
-
schemaUid: schemaUidFromDb,
|
|
130
|
-
versionLocalId: versionLocalIdFromDb,
|
|
131
|
-
versionUid: versionUidFromDb,
|
|
132
|
-
refValueType,
|
|
133
|
-
refResolvedValue,
|
|
134
|
-
localStorageDir,
|
|
135
|
-
} = firstRow
|
|
92
|
+
if (!rows || !rows.length) {
|
|
93
|
+
return
|
|
94
|
+
}
|
|
136
95
|
|
|
137
|
-
|
|
96
|
+
const firstRow = rows[0]
|
|
138
97
|
|
|
139
|
-
|
|
140
|
-
|
|
98
|
+
const {
|
|
99
|
+
localId,
|
|
100
|
+
uid,
|
|
101
|
+
propertyName: propertyNameFromDb,
|
|
102
|
+
propertyValue: propertyValueFromDb,
|
|
103
|
+
seedLocalId: seedLocalIdFromDb,
|
|
104
|
+
seedUid: seedUidFromDb,
|
|
105
|
+
schemaUid: schemaUidFromDb,
|
|
106
|
+
versionLocalId: versionLocalIdFromDb,
|
|
107
|
+
versionUid: versionUidFromDb,
|
|
108
|
+
refValueType,
|
|
109
|
+
refResolvedValue,
|
|
110
|
+
localStorageDir,
|
|
111
|
+
} = firstRow
|
|
112
|
+
|
|
113
|
+
let { refResolvedDisplayValue } = firstRow
|
|
114
|
+
|
|
115
|
+
let propertyValueProcessed: string | string[] | undefined | null =
|
|
116
|
+
propertyValueFromDb
|
|
117
|
+
|
|
118
|
+
if (propertyName && !propertyNameFromDb) {
|
|
119
|
+
logger(
|
|
120
|
+
`Property name from code is ${propertyName} but has not value in db ${propertyNameFromDb} for Property.${localId}`,
|
|
121
|
+
)
|
|
122
|
+
}
|
|
141
123
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
124
|
+
if (
|
|
125
|
+
propertyName &&
|
|
126
|
+
propertyNameFromDb &&
|
|
127
|
+
!propertyNameFromDb.includes(propertyName) &&
|
|
128
|
+
!propertyName.includes(propertyNameFromDb) &&
|
|
129
|
+
propertyNameFromDb !== propertyName
|
|
130
|
+
) {
|
|
131
|
+
logger(
|
|
132
|
+
`Property name from db ${propertyNameFromDb} does not match property name ${propertyName} for Property.${localId}`,
|
|
133
|
+
)
|
|
134
|
+
}
|
|
147
135
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
propertyNameFromDb !== propertyName
|
|
154
|
-
) {
|
|
155
|
-
logger(
|
|
156
|
-
`Property name from db ${propertyNameFromDb} does not match property name ${propertyName} for Property.${localId}`,
|
|
157
|
-
)
|
|
158
|
-
}
|
|
136
|
+
if (propertyValue && propertyValueFromDb !== propertyValue) {
|
|
137
|
+
logger(
|
|
138
|
+
`Property value from db ${propertyValueFromDb} does not match property value ${propertyValue} for Property.${localId}`,
|
|
139
|
+
)
|
|
140
|
+
}
|
|
159
141
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
142
|
+
if (seedLocalIdFromDb !== seedLocalId) {
|
|
143
|
+
logger(
|
|
144
|
+
`Seed local id from db ${seedLocalIdFromDb} does not match seed local id ${seedLocalId} for Property.${localId}`,
|
|
145
|
+
)
|
|
146
|
+
}
|
|
165
147
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
148
|
+
if (seedUidFromDb !== seedUid) {
|
|
149
|
+
logger(
|
|
150
|
+
`Seed uid from db ${seedUidFromDb} does not match seed uid ${seedUid} for Property.${localId}`,
|
|
151
|
+
)
|
|
152
|
+
}
|
|
171
153
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
154
|
+
if (
|
|
155
|
+
propertyRecordSchema &&
|
|
156
|
+
propertyRecordSchema.refValueType === 'ImageSrc'
|
|
157
|
+
) {
|
|
158
|
+
let shouldReadFromFile = true
|
|
177
159
|
|
|
178
160
|
if (
|
|
179
161
|
refResolvedValue &&
|
|
180
162
|
refResolvedDisplayValue &&
|
|
181
163
|
refResolvedDisplayValue.includes('http')
|
|
182
164
|
) {
|
|
183
|
-
let urlNeedsToBeRefreshed = false
|
|
184
|
-
|
|
185
165
|
try {
|
|
186
166
|
const response = await fetch(refResolvedDisplayValue, {
|
|
187
167
|
method: 'HEAD',
|
|
188
168
|
})
|
|
189
169
|
|
|
190
170
|
// Check if the status is in the 200-299 range
|
|
191
|
-
if (
|
|
192
|
-
|
|
171
|
+
if (response.ok) {
|
|
172
|
+
shouldReadFromFile = false
|
|
193
173
|
}
|
|
194
174
|
} catch (error) {
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (urlNeedsToBeRefreshed) {
|
|
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}`
|
|
208
|
-
const fileExists = await fs.promises.exists(filePath)
|
|
209
|
-
if (fileExists) {
|
|
210
|
-
const fileContents = await fs.promises.readFile(filePath)
|
|
211
|
-
const fileHandler = new File([fileContents], refResolvedValue)
|
|
212
|
-
refResolvedDisplayValue = URL.createObjectURL(fileHandler)
|
|
213
|
-
await updateMetadata({
|
|
214
|
-
localId,
|
|
215
|
-
refResolvedDisplayValue,
|
|
216
|
-
})
|
|
217
|
-
}
|
|
175
|
+
shouldReadFromFile = true
|
|
218
176
|
}
|
|
219
177
|
}
|
|
220
178
|
|
|
221
|
-
if (
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
179
|
+
if (shouldReadFromFile) {
|
|
180
|
+
let dir = localStorageDir
|
|
181
|
+
if (
|
|
182
|
+
!dir &&
|
|
183
|
+
propertyRecordSchema &&
|
|
184
|
+
propertyRecordSchema.refValueType === 'ImageSrc'
|
|
185
|
+
) {
|
|
186
|
+
dir = 'images'
|
|
187
|
+
}
|
|
188
|
+
const filePath = `/files/${dir}/${refResolvedValue}`
|
|
189
|
+
const fileExists = await fs.promises.exists(filePath)
|
|
190
|
+
if (fileExists) {
|
|
191
|
+
const fileContents = await fs.promises.readFile(filePath)
|
|
192
|
+
const fileHandler = new File([fileContents], refResolvedValue)
|
|
193
|
+
refResolvedDisplayValue = URL.createObjectURL(fileHandler)
|
|
194
|
+
await updateMetadata({
|
|
195
|
+
localId,
|
|
196
|
+
refResolvedDisplayValue,
|
|
197
|
+
})
|
|
198
|
+
}
|
|
228
199
|
}
|
|
200
|
+
}
|
|
229
201
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
versionUid: versionUidFromDb,
|
|
239
|
-
schemaUid: schemaUidFromDb,
|
|
240
|
-
refValueType,
|
|
241
|
-
localStorageDir,
|
|
242
|
-
resolvedValue: refResolvedValue,
|
|
243
|
-
resolvedDisplayValue: refResolvedDisplayValue,
|
|
244
|
-
renderValue: refResolvedDisplayValue,
|
|
245
|
-
})
|
|
202
|
+
if (
|
|
203
|
+
propertyRecordSchema &&
|
|
204
|
+
propertyRecordSchema.dataType === 'List' &&
|
|
205
|
+
propertyRecordSchema.ref &&
|
|
206
|
+
typeof propertyValueFromDb === 'string'
|
|
207
|
+
) {
|
|
208
|
+
propertyValueProcessed = propertyValueFromDb.split(',')
|
|
209
|
+
}
|
|
246
210
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
211
|
+
sendBack({
|
|
212
|
+
type: 'updateContext',
|
|
213
|
+
localId,
|
|
214
|
+
uid,
|
|
215
|
+
propertyValue: propertyValueProcessed,
|
|
216
|
+
seedLocalId: seedLocalIdFromDb,
|
|
217
|
+
seedUid: seedUidFromDb,
|
|
218
|
+
versionLocalId: versionLocalIdFromDb,
|
|
219
|
+
versionUid: versionUidFromDb,
|
|
220
|
+
schemaUid: schemaUidFromDb,
|
|
221
|
+
refValueType,
|
|
222
|
+
localStorageDir,
|
|
223
|
+
resolvedValue: refResolvedValue,
|
|
224
|
+
resolvedDisplayValue: refResolvedDisplayValue,
|
|
225
|
+
renderValue: refResolvedDisplayValue,
|
|
226
|
+
})
|
|
260
227
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
228
|
+
if (
|
|
229
|
+
propertyRecordSchema &&
|
|
230
|
+
propertyRecordSchema.storageType &&
|
|
231
|
+
propertyRecordSchema.storageType === 'ItemStorage'
|
|
232
|
+
) {
|
|
233
|
+
const { Item } = await import(`@/browser/item`)
|
|
234
|
+
const item = await Item.find({
|
|
235
|
+
seedLocalId,
|
|
236
|
+
modelName: itemModelName,
|
|
237
|
+
})
|
|
238
|
+
if (item) {
|
|
239
|
+
const filePath = `/files/${localStorageDir}/${refResolvedValue}`
|
|
240
|
+
const exists = await fs.promises.exists(filePath)
|
|
264
241
|
|
|
265
|
-
|
|
266
|
-
const property = item.properties[propertyName]
|
|
267
|
-
property.getService().send({ type: 'updateRenderValue', renderValue })
|
|
242
|
+
if (!exists) {
|
|
268
243
|
return
|
|
269
244
|
}
|
|
245
|
+
|
|
246
|
+
const renderValue = await fs.promises.readFile(filePath, 'utf8')
|
|
247
|
+
const property = item.properties[propertyName]
|
|
248
|
+
property.getService().send({ type: 'updateRenderValue', renderValue })
|
|
249
|
+
return
|
|
270
250
|
}
|
|
271
251
|
}
|
|
252
|
+
}
|
|
272
253
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
)
|
|
254
|
+
_hydrateFromDb().then(() => {
|
|
255
|
+
sendBack({ type: 'hydrateFromDbSuccess' })
|
|
256
|
+
})
|
|
257
|
+
})
|