@seedprotocol/sdk 0.1.75 → 0.1.77
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-BH0P1ozi.js +7568 -0
- package/dist/index-BH0P1ozi.js.map +1 -0
- package/dist/index-BpkGOxI0.js +32 -0
- package/dist/index-BpkGOxI0.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-CR4yAjam.js} +3 -3
- package/dist/{seed.schema.config-BPJfo_5h.js.map → seed.schema.config-CR4yAjam.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 +58 -64
- package/dist/src/initialize.ts +33 -119
- package/dist/src/item.ts +1 -1
- package/dist/src/itemMachineSingle.ts +12 -29
- package/dist/src/queries.ts +27 -6
- 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 +2 -2
|
@@ -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-BH0P1ozi.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-CR4yAjam.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seed.schema.config-
|
|
1
|
+
{"version":3,"file":"seed.schema.config-CR4yAjam.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
|
-
// }
|
|
@@ -46,32 +46,14 @@ export const hydrateFromDb = fromCallback<
|
|
|
46
46
|
const _hydrateFromDb = async () => {
|
|
47
47
|
const appDb = getAppDb()
|
|
48
48
|
|
|
49
|
-
const
|
|
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
|
-
if (
|
|
49
|
+
const isRelation =
|
|
71
50
|
propertyRecordSchema &&
|
|
72
51
|
propertyRecordSchema.ref &&
|
|
73
52
|
propertyRecordSchema.dataType === 'Relation'
|
|
74
|
-
|
|
53
|
+
|
|
54
|
+
const whereClauses = []
|
|
55
|
+
|
|
56
|
+
if (isRelation) {
|
|
75
57
|
let missingPropertyNameVariant
|
|
76
58
|
if (propertyName.endsWith('Id')) {
|
|
77
59
|
missingPropertyNameVariant = propertyName.slice(0, -2)
|
|
@@ -86,44 +68,22 @@ export const hydrateFromDb = fromCallback<
|
|
|
86
68
|
eq(metadata.propertyName, missingPropertyNameVariant),
|
|
87
69
|
),
|
|
88
70
|
)
|
|
89
|
-
// propertyNameQuery = or(
|
|
90
|
-
// eq(metadata.propertyName, propertyName),
|
|
91
|
-
// eq(metadata.propertyName, missingPropertyNameVariant),
|
|
92
|
-
// )
|
|
93
71
|
}
|
|
94
72
|
if (!missingPropertyNameVariant) {
|
|
95
73
|
whereClauses.push(eq(metadata.propertyName, propertyName))
|
|
96
74
|
}
|
|
75
|
+
} else {
|
|
76
|
+
whereClauses.push(eq(metadata.propertyName, propertyName))
|
|
97
77
|
}
|
|
98
78
|
|
|
99
|
-
// if (seedUid && !seedLocalId) {
|
|
100
|
-
// hydrateQuery = selectFromStatement.where(
|
|
101
|
-
// and(eq(metadata.seedUid, seedUid), propertyNameQuery),
|
|
102
|
-
// )
|
|
103
|
-
// }
|
|
104
|
-
|
|
105
79
|
if (seedUid) {
|
|
106
|
-
// hydrateQuery = selectFromStatement.where(
|
|
107
|
-
// and(
|
|
108
|
-
// eq(metadata.seedLocalId, seedLocalId),
|
|
109
|
-
// eq(metadata.seedUid, seedUid),
|
|
110
|
-
// propertyNameQuery,
|
|
111
|
-
// ),
|
|
112
|
-
// )
|
|
113
80
|
whereClauses.push(eq(metadata.seedUid, seedUid))
|
|
114
81
|
}
|
|
115
82
|
|
|
116
83
|
if (seedLocalId) {
|
|
117
|
-
// hydrateQuery = selectFromStatement.where(
|
|
118
|
-
// and(eq(metadata.seedLocalId, seedLocalId), propertyNameQuery),
|
|
119
|
-
// )
|
|
120
84
|
whereClauses.push(eq(metadata.seedLocalId, seedLocalId))
|
|
121
85
|
}
|
|
122
86
|
|
|
123
|
-
if (!hydrateQuery) {
|
|
124
|
-
return
|
|
125
|
-
}
|
|
126
|
-
|
|
127
87
|
const rows = await appDb
|
|
128
88
|
.select()
|
|
129
89
|
.from(metadata)
|
|
@@ -147,11 +107,10 @@ export const hydrateFromDb = fromCallback<
|
|
|
147
107
|
versionLocalId: versionLocalIdFromDb,
|
|
148
108
|
versionUid: versionUidFromDb,
|
|
149
109
|
refValueType,
|
|
150
|
-
refResolvedValue,
|
|
151
110
|
localStorageDir,
|
|
152
111
|
} = firstRow
|
|
153
112
|
|
|
154
|
-
let { refResolvedDisplayValue } = firstRow
|
|
113
|
+
let { refResolvedDisplayValue, refResolvedValue } = firstRow
|
|
155
114
|
|
|
156
115
|
let propertyValueProcessed: string | string[] | undefined | null =
|
|
157
116
|
propertyValueFromDb
|
|
@@ -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 &&
|
|
@@ -221,6 +185,36 @@ export const hydrateFromDb = fromCallback<
|
|
|
221
185
|
) {
|
|
222
186
|
dir = 'images'
|
|
223
187
|
}
|
|
188
|
+
|
|
189
|
+
if (
|
|
190
|
+
!refResolvedValue &&
|
|
191
|
+
propertyValueFromDb &&
|
|
192
|
+
propertyValueFromDb.length === 66
|
|
193
|
+
) {
|
|
194
|
+
const storageTransactionQuery = await appDb
|
|
195
|
+
.select({
|
|
196
|
+
propertyValue: metadata.propertyValue,
|
|
197
|
+
})
|
|
198
|
+
.from(metadata)
|
|
199
|
+
.where(
|
|
200
|
+
and(
|
|
201
|
+
eq(metadata.seedUid, propertyValueFromDb),
|
|
202
|
+
eq(metadata.propertyName, 'storageTransactionId'),
|
|
203
|
+
),
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
if (storageTransactionQuery && storageTransactionQuery.length > 0) {
|
|
207
|
+
const row = storageTransactionQuery[0]
|
|
208
|
+
refResolvedValue = row.propertyValue
|
|
209
|
+
console.log('storageTransactionId', refResolvedValue)
|
|
210
|
+
await updateMetadata({
|
|
211
|
+
localId,
|
|
212
|
+
refResolvedValue,
|
|
213
|
+
localStorageDir: '/images',
|
|
214
|
+
})
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
224
218
|
const filePath = `/files/${dir}/${refResolvedValue}`
|
|
225
219
|
const fileExists = await fs.promises.exists(filePath)
|
|
226
220
|
if (fileExists) {
|
package/dist/src/initialize.ts
CHANGED
|
@@ -1,127 +1,41 @@
|
|
|
1
|
-
import { EventObject, fromCallback
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
let environment = 'browser'
|
|
25
|
-
|
|
26
|
-
if (isNode()) {
|
|
27
|
-
environment = 'node'
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (isReactNative()) {
|
|
31
|
-
environment = 'react-native'
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
let internalSubscription: Subscription | undefined
|
|
35
|
-
let easSubscription: Subscription | undefined
|
|
36
|
-
|
|
37
|
-
if (environment === 'browser' && models) {
|
|
38
|
-
const _initFileSystem = async (): Promise<void> => {
|
|
39
|
-
return
|
|
40
|
-
// return new Promise((resolve) => {
|
|
41
|
-
// })
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const _initInternal = async (): Promise<void> => {
|
|
45
|
-
return new Promise((resolve) => {
|
|
46
|
-
internalSubscription = internalService.subscribe((snapshot) => {
|
|
47
|
-
logger('[sdk] [internal] snapshot', snapshot)
|
|
48
|
-
if (snapshot.value === 'ready') {
|
|
49
|
-
resolve()
|
|
50
|
-
}
|
|
1
|
+
import { EventObject, fromCallback } from 'xstate'
|
|
2
|
+
import { itemMachineSingle } from '@/browser/item/single/itemMachineSingle'
|
|
3
|
+
import pluralize from 'pluralize'
|
|
4
|
+
import { getExistingItem } from '@/browser/db/read'
|
|
5
|
+
|
|
6
|
+
export const initialize = fromCallback<EventObject, typeof itemMachineSingle>(
|
|
7
|
+
({ sendBack, input: { context } }) => {
|
|
8
|
+
const { seedLocalId, seedUid, ModelClass } = context
|
|
9
|
+
|
|
10
|
+
const modelName = ModelClass.originalConstructor.name
|
|
11
|
+
const modelNamePlural = pluralize(modelName)
|
|
12
|
+
const modelTableName = modelNamePlural.toLowerCase()
|
|
13
|
+
|
|
14
|
+
const _intialize = async (): Promise<void> => {
|
|
15
|
+
const existingItem = await getExistingItem({ seedUid, seedLocalId })
|
|
16
|
+
|
|
17
|
+
if (existingItem) {
|
|
18
|
+
sendBack({
|
|
19
|
+
type: 'hasExistingItem',
|
|
20
|
+
modelName,
|
|
21
|
+
modelTableName,
|
|
22
|
+
modelNamePlural,
|
|
23
|
+
existingItem,
|
|
51
24
|
})
|
|
52
|
-
|
|
53
|
-
})
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const _initAllItemsServices = async (): Promise<void> => {
|
|
57
|
-
const appDb = getAppDb()
|
|
58
|
-
|
|
59
|
-
const rows = await appDb
|
|
60
|
-
.select()
|
|
61
|
-
.from(appState)
|
|
62
|
-
.where(like(appState.key, 'snapshot__%'))
|
|
63
|
-
|
|
64
|
-
const payloadObj = {
|
|
65
|
-
create: {},
|
|
66
|
-
restore: {},
|
|
25
|
+
return
|
|
67
26
|
}
|
|
68
27
|
|
|
69
|
-
const modelNamesRestored: string[] = []
|
|
70
|
-
|
|
71
|
-
if (rows && rows.length > 0) {
|
|
72
|
-
for (const row of rows) {
|
|
73
|
-
const modelName = row.key.replace('snapshot__', '')
|
|
74
|
-
payloadObj.restore[modelName] = JSON.parse(row.value)
|
|
75
|
-
modelNamesRestored.push(modelName)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
for (const [modelName, ModelClass] of Object.entries(models)) {
|
|
79
|
-
if (!modelNamesRestored.includes(modelName)) {
|
|
80
|
-
payloadObj.create[modelName] = ModelClass
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
28
|
sendBack({
|
|
84
|
-
type:
|
|
85
|
-
|
|
29
|
+
type: 'isNewItem',
|
|
30
|
+
modelName,
|
|
31
|
+
modelTableName,
|
|
32
|
+
modelNamePlural,
|
|
86
33
|
})
|
|
87
34
|
}
|
|
88
35
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// return new Promise((resolve) => {
|
|
93
|
-
// easSubscription = easService.subscribe((snapshot) => {
|
|
94
|
-
// if (snapshot.value === 'ready') {
|
|
95
|
-
// resolve()
|
|
96
|
-
// }
|
|
97
|
-
// })
|
|
98
|
-
// easService.send({ type: 'init', endpoints, models })
|
|
99
|
-
// })
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
_initFileSystem().then(() => {
|
|
103
|
-
logger('[global/actors] File system initialized')
|
|
36
|
+
_intialize().then(() => {
|
|
37
|
+
sendBack({ type: 'initializeSuccess' })
|
|
38
|
+
return
|
|
104
39
|
})
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
.then(() => {
|
|
108
|
-
return _initAllItemsServices()
|
|
109
|
-
})
|
|
110
|
-
.then(() => {
|
|
111
|
-
logger('[global/actors] Internal initialized')
|
|
112
|
-
sendBack({ type: GLOBAL_INITIALIZING_INTERNAL_SERVICE_READY })
|
|
113
|
-
internalSubscription?.unsubscribe()
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
// _initEas().then(() => {
|
|
117
|
-
// logger('EAS initialized')
|
|
118
|
-
// })
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
sendBack({ type: GLOBAL_INITIALIZING_SEND_CONFIG, environment })
|
|
122
|
-
|
|
123
|
-
return () => {
|
|
124
|
-
internalSubscription?.unsubscribe()
|
|
125
|
-
easSubscription?.unsubscribe()
|
|
126
|
-
}
|
|
127
|
-
})
|
|
40
|
+
},
|
|
41
|
+
)
|