@seedprotocol/sdk 0.1.89 → 0.1.91
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/{index-CcE521Ay.js → index-B3xp2pDI.js} +6 -6
- package/dist/{index-CcE521Ay.js.map → index-B3xp2pDI.js.map} +1 -1
- package/dist/{index-BejZtiZ6.js → index-j7sFsIYr.js} +187 -167
- package/dist/index-j7sFsIYr.js.map +1 -0
- package/dist/main.js +5 -5
- package/dist/{seed.schema.config-CnfT1dNe.js → seed.schema.config-BRGl01il.js} +6 -6
- package/dist/{seed.schema.config-CnfT1dNe.js.map → seed.schema.config-BRGl01il.js.map} +1 -1
- package/dist/src/actors.ts +289 -7
- package/dist/src/analyzeInput.ts +11 -2
- package/dist/src/getPublishPayload.ts +8 -26
- package/dist/src/index.ts +62 -10
- package/dist/types/src/browser/db/read/getPublishPayload.d.ts.map +1 -1
- package/dist/types/src/browser/helpers.d.ts +7 -0
- package/dist/types/src/browser/helpers.d.ts.map +1 -1
- package/dist/types/src/browser/property/ItemProperty.d.ts +4 -4
- package/dist/types/src/browser/property/actors/saveValueToDb/analyzeInput.d.ts.map +1 -1
- package/dist/types/src/browser/property/propertyMachine.d.ts +8 -8
- package/dist/types/src/browser/services/global/globalMachine.d.ts +22 -22
- package/package.json +1 -1
- package/dist/index-BejZtiZ6.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { g as GET_ALL_PROPERTIES_FOR_ALL_VERSIONS, f as GET_PROPERTIES, G as GET_SCHEMAS, a as GET_SCHEMA_BY_NAME, b as GET_SEEDS, c as GET_SEED_IDS, d as GET_STORAGE_TRANSACTION_ID, e as GET_VERSIONS, I as Item, h as itemMachineAll, i as itemMachineSingle } from './index-
|
|
1
|
+
export { g as GET_ALL_PROPERTIES_FOR_ALL_VERSIONS, f as GET_PROPERTIES, G as GET_SCHEMAS, a as GET_SCHEMA_BY_NAME, b as GET_SEEDS, c as GET_SEED_IDS, d as GET_STORAGE_TRANSACTION_ID, e as GET_VERSIONS, I as Item, h as itemMachineAll, i as itemMachineSingle } from './index-j7sFsIYr.js';
|
|
2
2
|
import './constants-rmQ8zg8_.js';
|
|
3
3
|
import '@ethereum-attestation-service/eas-sdk';
|
|
4
4
|
import 'thirdweb';
|
|
@@ -19,14 +19,14 @@ import '@tanstack/react-query';
|
|
|
19
19
|
import 'graphql-request';
|
|
20
20
|
import '@tanstack/query-sync-storage-persister';
|
|
21
21
|
import '@tanstack/react-query-persist-client';
|
|
22
|
-
import '
|
|
23
|
-
import '@xstate/react';
|
|
24
|
-
import 'eventemitter3';
|
|
22
|
+
import 'rxjs';
|
|
25
23
|
import 'immer';
|
|
26
24
|
import 'pluralize';
|
|
25
|
+
import 'eventemitter3';
|
|
27
26
|
import '@statelyai/inspect';
|
|
28
|
-
import 'rxjs';
|
|
29
27
|
import 'drizzle-orm/sqlite-proxy';
|
|
30
28
|
import '@zenfs/dom';
|
|
31
29
|
import 'arweave';
|
|
32
|
-
|
|
30
|
+
import 'use-immer';
|
|
31
|
+
import '@xstate/react';
|
|
32
|
+
//# sourceMappingURL=index-B3xp2pDI.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-
|
|
1
|
+
{"version":3,"file":"index-B3xp2pDI.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -2,7 +2,7 @@ import { b as __awaiter, d as __rest, i as internalPropertyNames, I as INTERNAL_
|
|
|
2
2
|
import path, { basename } from 'path';
|
|
3
3
|
import 'reflect-metadata';
|
|
4
4
|
import { Type } from '@sinclair/typebox';
|
|
5
|
-
import { fromCallback,
|
|
5
|
+
import { fromCallback, createActor, waitFor, setup, assign, raise } from 'xstate';
|
|
6
6
|
import { sql, relations, or, eq, and, max, count, isNotNull, isNull, gt, inArray, like, getTableColumns } from 'drizzle-orm';
|
|
7
7
|
import { fs, configureSingle } from '@zenfs/core';
|
|
8
8
|
import 'dayjs';
|
|
@@ -16,16 +16,16 @@ import { QueryClient } from '@tanstack/react-query';
|
|
|
16
16
|
import { GraphQLClient } from 'graphql-request';
|
|
17
17
|
import { createSyncStoragePersister } from '@tanstack/query-sync-storage-persister';
|
|
18
18
|
import { persistQueryClient } from '@tanstack/react-query-persist-client';
|
|
19
|
-
import {
|
|
20
|
-
import { useSelector } from '@xstate/react';
|
|
21
|
-
import EventEmitter from 'eventemitter3';
|
|
19
|
+
import { BehaviorSubject } from 'rxjs';
|
|
22
20
|
import { immerable, produce, enableMapSet } from 'immer';
|
|
23
21
|
import pluralize from 'pluralize';
|
|
22
|
+
import EventEmitter from 'eventemitter3';
|
|
24
23
|
import { createBrowserInspector } from '@statelyai/inspect';
|
|
25
|
-
import { BehaviorSubject } from 'rxjs';
|
|
26
24
|
import { drizzle } from 'drizzle-orm/sqlite-proxy';
|
|
27
25
|
import { WebAccess } from '@zenfs/dom';
|
|
28
26
|
import Arweave from 'arweave';
|
|
27
|
+
import { useImmer } from 'use-immer';
|
|
28
|
+
import { useSelector } from '@xstate/react';
|
|
29
29
|
import { ZERO_ADDRESS } from 'thirdweb';
|
|
30
30
|
import { SchemaEncoder } from '@ethereum-attestation-service/eas-sdk';
|
|
31
31
|
|
|
@@ -1068,7 +1068,7 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
1068
1068
|
if (propertyRecordSchema &&
|
|
1069
1069
|
propertyRecordSchema.storageType &&
|
|
1070
1070
|
propertyRecordSchema.storageType === 'ItemStorage') {
|
|
1071
|
-
const { Item } = yield import('./index-
|
|
1071
|
+
const { Item } = yield import('./index-B3xp2pDI.js');
|
|
1072
1072
|
const item = yield Item.find({
|
|
1073
1073
|
seedLocalId,
|
|
1074
1074
|
modelName: itemModelName,
|
|
@@ -1299,140 +1299,6 @@ const EAS_ENDPOINT = process.env.NEXT_PUBLIC_EAS_ENDPOINT ||
|
|
|
1299
1299
|
const ARWEAVE_HOST = process.env.NEXT_PUBLIC_ARWEAVE_HOST || 'permagate.io';
|
|
1300
1300
|
const ARWEAVE_ENDPOINT = `https://${ARWEAVE_HOST}/graphql`;
|
|
1301
1301
|
|
|
1302
|
-
const queryClient = new QueryClient({
|
|
1303
|
-
defaultOptions: {
|
|
1304
|
-
queries: {
|
|
1305
|
-
networkMode: 'offlineFirst',
|
|
1306
|
-
gcTime: 1000 * 60 * 60 * 24, // 24 hours
|
|
1307
|
-
},
|
|
1308
|
-
},
|
|
1309
|
-
});
|
|
1310
|
-
const localStoragePersister = createSyncStoragePersister({
|
|
1311
|
-
storage: typeof window !== 'undefined' ? window.localStorage : null,
|
|
1312
|
-
});
|
|
1313
|
-
persistQueryClient({
|
|
1314
|
-
queryClient,
|
|
1315
|
-
persister: localStoragePersister,
|
|
1316
|
-
});
|
|
1317
|
-
const easClient = new GraphQLClient(EAS_ENDPOINT);
|
|
1318
|
-
const arweaveClient = new GraphQLClient(ARWEAVE_ENDPOINT);
|
|
1319
|
-
const getCorrectId = (localIdOrUid) => {
|
|
1320
|
-
const id = {
|
|
1321
|
-
localId: undefined,
|
|
1322
|
-
uid: undefined,
|
|
1323
|
-
};
|
|
1324
|
-
if (!localIdOrUid) {
|
|
1325
|
-
return id;
|
|
1326
|
-
}
|
|
1327
|
-
if (localIdOrUid.length === 10) {
|
|
1328
|
-
id.localId = localIdOrUid;
|
|
1329
|
-
}
|
|
1330
|
-
if (localIdOrUid.startsWith('0x') && localIdOrUid.length === 66) {
|
|
1331
|
-
id.uid = localIdOrUid;
|
|
1332
|
-
}
|
|
1333
|
-
return id;
|
|
1334
|
-
};
|
|
1335
|
-
const getContentUrlFromPath = (path) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1336
|
-
const imageFileExists = yield fs.promises.exists(path);
|
|
1337
|
-
if (!imageFileExists) {
|
|
1338
|
-
return;
|
|
1339
|
-
}
|
|
1340
|
-
const fileContents = yield fs.promises.readFile(path);
|
|
1341
|
-
const fileHandler = new File([fileContents], basename(path));
|
|
1342
|
-
return URL.createObjectURL(fileHandler);
|
|
1343
|
-
});
|
|
1344
|
-
const updateMachineContext = {
|
|
1345
|
-
actions: assign(({ context, event }) => {
|
|
1346
|
-
const newContext = Object.assign({}, context);
|
|
1347
|
-
for (let i = 0; i < Object.keys(event).length; i++) {
|
|
1348
|
-
const key = Object.keys(event)[i];
|
|
1349
|
-
if (key === 'type') {
|
|
1350
|
-
continue;
|
|
1351
|
-
}
|
|
1352
|
-
newContext[key] = event[key];
|
|
1353
|
-
}
|
|
1354
|
-
return Object.assign({}, newContext);
|
|
1355
|
-
}),
|
|
1356
|
-
};
|
|
1357
|
-
|
|
1358
|
-
const getSchemaUidForModel = (modelName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1359
|
-
const modeType = modelName.toLowerCase();
|
|
1360
|
-
const modelSchemaQuery = yield queryClient.fetchQuery({
|
|
1361
|
-
queryKey: [`getPropertySchema${modelName}`],
|
|
1362
|
-
queryFn: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1363
|
-
return easClient.request(GET_SCHEMAS, {
|
|
1364
|
-
where: {
|
|
1365
|
-
schemaNames: {
|
|
1366
|
-
some: {
|
|
1367
|
-
name: {
|
|
1368
|
-
equals: modeType,
|
|
1369
|
-
},
|
|
1370
|
-
},
|
|
1371
|
-
},
|
|
1372
|
-
},
|
|
1373
|
-
});
|
|
1374
|
-
}),
|
|
1375
|
-
});
|
|
1376
|
-
const foundSchema = modelSchemaQuery.schemas[0];
|
|
1377
|
-
return foundSchema.id;
|
|
1378
|
-
});
|
|
1379
|
-
|
|
1380
|
-
debug('app:write');
|
|
1381
|
-
const createSeed = (_a) => __awaiter(void 0, [_a], void 0, function* ({ type, seedUid }) {
|
|
1382
|
-
const schemaUid = yield getSchemaUidForModel(type);
|
|
1383
|
-
if (!schemaUid) {
|
|
1384
|
-
throw new Error(`No schema found for model type: ${type}`);
|
|
1385
|
-
}
|
|
1386
|
-
const appDb = getAppDb();
|
|
1387
|
-
const newSeedLocalId = generateId();
|
|
1388
|
-
yield appDb.insert(seeds).values({
|
|
1389
|
-
localId: newSeedLocalId,
|
|
1390
|
-
type,
|
|
1391
|
-
uid: seedUid,
|
|
1392
|
-
createdAt: Date.now(),
|
|
1393
|
-
schemaUid,
|
|
1394
|
-
});
|
|
1395
|
-
return newSeedLocalId;
|
|
1396
|
-
});
|
|
1397
|
-
const createNewItem = (_a) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1398
|
-
var _b;
|
|
1399
|
-
var { modelName } = _a, propertyData = __rest(_a, ["modelName"]);
|
|
1400
|
-
if (!modelName) {
|
|
1401
|
-
throw new Error('A model name is required for createNewItem');
|
|
1402
|
-
}
|
|
1403
|
-
const seedType = modelName.toLowerCase();
|
|
1404
|
-
const newSeedId = yield createSeed({ type: seedType });
|
|
1405
|
-
const newVersionId = yield createVersion({ seedLocalId: newSeedId });
|
|
1406
|
-
const propertySchemas = (_b = getModel(modelName)) === null || _b === void 0 ? void 0 : _b.schema;
|
|
1407
|
-
for (const [propertyName, propertyValue] of Object.entries(propertyData)) {
|
|
1408
|
-
let propertyRecordSchema;
|
|
1409
|
-
if (propertySchemas && propertySchemas[propertyName]) {
|
|
1410
|
-
propertyRecordSchema = propertySchemas[propertyName];
|
|
1411
|
-
}
|
|
1412
|
-
yield createMetadata({
|
|
1413
|
-
seedLocalId: newSeedId,
|
|
1414
|
-
versionLocalId: newVersionId,
|
|
1415
|
-
propertyName,
|
|
1416
|
-
propertyValue,
|
|
1417
|
-
modelName,
|
|
1418
|
-
}, propertyRecordSchema);
|
|
1419
|
-
// await appDb.run(
|
|
1420
|
-
// sql.raw(
|
|
1421
|
-
// `INSERT INTO metadata (seed_local_id, version_local_id, property_name, property_value, model_type, created_at,
|
|
1422
|
-
// attestation_created_at)
|
|
1423
|
-
// VALUES ('${newSeedId}', '${newVersionId}', '${propertyName}', '${propertyValue}', '${seedType}', ${Date.now()},
|
|
1424
|
-
// ${Date.now()});`,
|
|
1425
|
-
// ),
|
|
1426
|
-
// )
|
|
1427
|
-
}
|
|
1428
|
-
// eventEmitter.emit(`item.requestAll`, { modelName })
|
|
1429
|
-
return {
|
|
1430
|
-
modelName,
|
|
1431
|
-
seedLocalId: newSeedId,
|
|
1432
|
-
versionLocalId: newVersionId,
|
|
1433
|
-
};
|
|
1434
|
-
});
|
|
1435
|
-
|
|
1436
1302
|
const eventEmitter = new EventEmitter();
|
|
1437
1303
|
|
|
1438
1304
|
var _a$2;
|
|
@@ -2635,7 +2501,7 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
2635
2501
|
if (!models$1) {
|
|
2636
2502
|
return;
|
|
2637
2503
|
}
|
|
2638
|
-
const { models: SeedModels } = yield import('./seed.schema.config-
|
|
2504
|
+
const { models: SeedModels } = yield import('./seed.schema.config-BRGl01il.js');
|
|
2639
2505
|
const allModels = Object.assign(Object.assign({}, SeedModels), models$1);
|
|
2640
2506
|
let hasModelsInDb = false;
|
|
2641
2507
|
const schemaDefsByModelName = new Map();
|
|
@@ -5799,35 +5665,18 @@ const getPublishPayload = (seedLocalId) => __awaiter(void 0, void 0, void 0, fun
|
|
|
5799
5665
|
const listOfAttestations = [];
|
|
5800
5666
|
const propertiesToUpdate = [];
|
|
5801
5667
|
for (const [propertyName, itemProperty] of Object.entries(item.properties)) {
|
|
5802
|
-
if (!itemProperty.value) {
|
|
5668
|
+
if (!itemProperty.value || !itemProperty.propertyDef) {
|
|
5803
5669
|
continue;
|
|
5804
5670
|
}
|
|
5805
|
-
const foundPropertySchema = yield
|
|
5806
|
-
|
|
5807
|
-
|
|
5808
|
-
return easClient.request(GET_SCHEMAS, {
|
|
5809
|
-
where: {
|
|
5810
|
-
id: {
|
|
5811
|
-
equals: itemProperty.schemaUid,
|
|
5812
|
-
},
|
|
5813
|
-
},
|
|
5814
|
-
});
|
|
5815
|
-
}),
|
|
5816
|
-
});
|
|
5817
|
-
if (!foundPropertySchema ||
|
|
5818
|
-
!foundPropertySchema.schemas ||
|
|
5819
|
-
foundPropertySchema.schemas.length === 0) {
|
|
5820
|
-
console.error(`Property schema not found for ${propertyName}`);
|
|
5821
|
-
continue;
|
|
5822
|
-
}
|
|
5823
|
-
if (!itemProperty.propertyDef) {
|
|
5824
|
-
continue;
|
|
5671
|
+
const foundPropertySchema = yield getSchemaForProperty(itemProperty);
|
|
5672
|
+
if (!foundPropertySchema) {
|
|
5673
|
+
throw new Error(`No schema found for property ${itemProperty.propertyName} ${itemProperty.localId}`);
|
|
5825
5674
|
}
|
|
5826
5675
|
const easDataType = INTERNAL_DATA_TYPES[itemProperty.propertyDef.dataType].eas;
|
|
5827
5676
|
const data = [
|
|
5828
5677
|
{ name: propertyName, type: easDataType, value: itemProperty.value },
|
|
5829
5678
|
];
|
|
5830
|
-
const easSchemaDefinition = foundPropertySchema.
|
|
5679
|
+
const easSchemaDefinition = foundPropertySchema.schema;
|
|
5831
5680
|
const dataEncoder = new SchemaEncoder(easSchemaDefinition);
|
|
5832
5681
|
const encodedData = dataEncoder.encodeData(data);
|
|
5833
5682
|
listOfAttestations.push({
|
|
@@ -6101,6 +5950,170 @@ class Item {
|
|
|
6101
5950
|
_a$1 = immerable;
|
|
6102
5951
|
Item.instanceCache = new Map();
|
|
6103
5952
|
|
|
5953
|
+
const queryClient = new QueryClient({
|
|
5954
|
+
defaultOptions: {
|
|
5955
|
+
queries: {
|
|
5956
|
+
networkMode: 'offlineFirst',
|
|
5957
|
+
gcTime: 1000 * 60 * 60 * 24, // 24 hours
|
|
5958
|
+
},
|
|
5959
|
+
},
|
|
5960
|
+
});
|
|
5961
|
+
const localStoragePersister = createSyncStoragePersister({
|
|
5962
|
+
storage: typeof window !== 'undefined' ? window.localStorage : null,
|
|
5963
|
+
});
|
|
5964
|
+
persistQueryClient({
|
|
5965
|
+
queryClient,
|
|
5966
|
+
persister: localStoragePersister,
|
|
5967
|
+
});
|
|
5968
|
+
const easClient = new GraphQLClient(EAS_ENDPOINT);
|
|
5969
|
+
const arweaveClient = new GraphQLClient(ARWEAVE_ENDPOINT);
|
|
5970
|
+
const getCorrectId = (localIdOrUid) => {
|
|
5971
|
+
const id = {
|
|
5972
|
+
localId: undefined,
|
|
5973
|
+
uid: undefined,
|
|
5974
|
+
};
|
|
5975
|
+
if (!localIdOrUid) {
|
|
5976
|
+
return id;
|
|
5977
|
+
}
|
|
5978
|
+
if (localIdOrUid.length === 10) {
|
|
5979
|
+
id.localId = localIdOrUid;
|
|
5980
|
+
}
|
|
5981
|
+
if (localIdOrUid.startsWith('0x') && localIdOrUid.length === 66) {
|
|
5982
|
+
id.uid = localIdOrUid;
|
|
5983
|
+
}
|
|
5984
|
+
return id;
|
|
5985
|
+
};
|
|
5986
|
+
const getContentUrlFromPath = (path) => __awaiter(void 0, void 0, void 0, function* () {
|
|
5987
|
+
const imageFileExists = yield fs.promises.exists(path);
|
|
5988
|
+
if (!imageFileExists) {
|
|
5989
|
+
return;
|
|
5990
|
+
}
|
|
5991
|
+
const fileContents = yield fs.promises.readFile(path);
|
|
5992
|
+
const fileHandler = new File([fileContents], basename(path));
|
|
5993
|
+
return URL.createObjectURL(fileHandler);
|
|
5994
|
+
});
|
|
5995
|
+
const updateMachineContext = {
|
|
5996
|
+
actions: assign(({ context, event }) => {
|
|
5997
|
+
const newContext = Object.assign({}, context);
|
|
5998
|
+
for (let i = 0; i < Object.keys(event).length; i++) {
|
|
5999
|
+
const key = Object.keys(event)[i];
|
|
6000
|
+
if (key === 'type') {
|
|
6001
|
+
continue;
|
|
6002
|
+
}
|
|
6003
|
+
newContext[key] = event[key];
|
|
6004
|
+
}
|
|
6005
|
+
return Object.assign({}, newContext);
|
|
6006
|
+
}),
|
|
6007
|
+
};
|
|
6008
|
+
const getSchemaForProperty = (_a) => __awaiter(void 0, [_a], void 0, function* ({ schemaUid, propertyName, }) {
|
|
6009
|
+
let queryParams = {
|
|
6010
|
+
where: {
|
|
6011
|
+
id: {
|
|
6012
|
+
equals: schemaUid,
|
|
6013
|
+
},
|
|
6014
|
+
},
|
|
6015
|
+
};
|
|
6016
|
+
if (!schemaUid || schemaUid === 'null' || schemaUid === 'undefined') {
|
|
6017
|
+
queryParams = {
|
|
6018
|
+
where: {
|
|
6019
|
+
schemaNames: {
|
|
6020
|
+
some: {
|
|
6021
|
+
name: {
|
|
6022
|
+
equals: toSnakeCase(propertyName),
|
|
6023
|
+
},
|
|
6024
|
+
},
|
|
6025
|
+
},
|
|
6026
|
+
},
|
|
6027
|
+
};
|
|
6028
|
+
}
|
|
6029
|
+
const foundPropertySchema = yield queryClient.fetchQuery({
|
|
6030
|
+
queryKey: [`getPropertySchema${propertyName}`],
|
|
6031
|
+
queryFn: () => __awaiter(void 0, void 0, void 0, function* () { return easClient.request(GET_SCHEMAS, queryParams); }),
|
|
6032
|
+
networkMode: 'offlineFirst',
|
|
6033
|
+
});
|
|
6034
|
+
if (foundPropertySchema && foundPropertySchema.schemas.length > 0) {
|
|
6035
|
+
return foundPropertySchema.schemas[0];
|
|
6036
|
+
}
|
|
6037
|
+
});
|
|
6038
|
+
|
|
6039
|
+
const getSchemaUidForModel = (modelName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
6040
|
+
const modeType = modelName.toLowerCase();
|
|
6041
|
+
const modelSchemaQuery = yield queryClient.fetchQuery({
|
|
6042
|
+
queryKey: [`getPropertySchema${modelName}`],
|
|
6043
|
+
queryFn: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
6044
|
+
return easClient.request(GET_SCHEMAS, {
|
|
6045
|
+
where: {
|
|
6046
|
+
schemaNames: {
|
|
6047
|
+
some: {
|
|
6048
|
+
name: {
|
|
6049
|
+
equals: modeType,
|
|
6050
|
+
},
|
|
6051
|
+
},
|
|
6052
|
+
},
|
|
6053
|
+
},
|
|
6054
|
+
});
|
|
6055
|
+
}),
|
|
6056
|
+
});
|
|
6057
|
+
const foundSchema = modelSchemaQuery.schemas[0];
|
|
6058
|
+
return foundSchema.id;
|
|
6059
|
+
});
|
|
6060
|
+
|
|
6061
|
+
debug('app:write');
|
|
6062
|
+
const createSeed = (_a) => __awaiter(void 0, [_a], void 0, function* ({ type, seedUid }) {
|
|
6063
|
+
const schemaUid = yield getSchemaUidForModel(type);
|
|
6064
|
+
if (!schemaUid) {
|
|
6065
|
+
throw new Error(`No schema found for model type: ${type}`);
|
|
6066
|
+
}
|
|
6067
|
+
const appDb = getAppDb();
|
|
6068
|
+
const newSeedLocalId = generateId();
|
|
6069
|
+
yield appDb.insert(seeds).values({
|
|
6070
|
+
localId: newSeedLocalId,
|
|
6071
|
+
type,
|
|
6072
|
+
uid: seedUid,
|
|
6073
|
+
createdAt: Date.now(),
|
|
6074
|
+
schemaUid,
|
|
6075
|
+
});
|
|
6076
|
+
return newSeedLocalId;
|
|
6077
|
+
});
|
|
6078
|
+
const createNewItem = (_a) => __awaiter(void 0, void 0, void 0, function* () {
|
|
6079
|
+
var _b;
|
|
6080
|
+
var { modelName } = _a, propertyData = __rest(_a, ["modelName"]);
|
|
6081
|
+
if (!modelName) {
|
|
6082
|
+
throw new Error('A model name is required for createNewItem');
|
|
6083
|
+
}
|
|
6084
|
+
const seedType = modelName.toLowerCase();
|
|
6085
|
+
const newSeedId = yield createSeed({ type: seedType });
|
|
6086
|
+
const newVersionId = yield createVersion({ seedLocalId: newSeedId });
|
|
6087
|
+
const propertySchemas = (_b = getModel(modelName)) === null || _b === void 0 ? void 0 : _b.schema;
|
|
6088
|
+
for (const [propertyName, propertyValue] of Object.entries(propertyData)) {
|
|
6089
|
+
let propertyRecordSchema;
|
|
6090
|
+
if (propertySchemas && propertySchemas[propertyName]) {
|
|
6091
|
+
propertyRecordSchema = propertySchemas[propertyName];
|
|
6092
|
+
}
|
|
6093
|
+
yield createMetadata({
|
|
6094
|
+
seedLocalId: newSeedId,
|
|
6095
|
+
versionLocalId: newVersionId,
|
|
6096
|
+
propertyName,
|
|
6097
|
+
propertyValue,
|
|
6098
|
+
modelName,
|
|
6099
|
+
}, propertyRecordSchema);
|
|
6100
|
+
// await appDb.run(
|
|
6101
|
+
// sql.raw(
|
|
6102
|
+
// `INSERT INTO metadata (seed_local_id, version_local_id, property_name, property_value, model_type, created_at,
|
|
6103
|
+
// attestation_created_at)
|
|
6104
|
+
// VALUES ('${newSeedId}', '${newVersionId}', '${propertyName}', '${propertyValue}', '${seedType}', ${Date.now()},
|
|
6105
|
+
// ${Date.now()});`,
|
|
6106
|
+
// ),
|
|
6107
|
+
// )
|
|
6108
|
+
}
|
|
6109
|
+
// eventEmitter.emit(`item.requestAll`, { modelName })
|
|
6110
|
+
return {
|
|
6111
|
+
modelName,
|
|
6112
|
+
seedLocalId: newSeedId,
|
|
6113
|
+
versionLocalId: newVersionId,
|
|
6114
|
+
};
|
|
6115
|
+
});
|
|
6116
|
+
|
|
6104
6117
|
const logger$4 = debug('app:react:services');
|
|
6105
6118
|
const finalStrings = ['idle', 'ready', 'done', 'success', 'initialized'];
|
|
6106
6119
|
const getServiceName = (service) => {
|
|
@@ -6637,7 +6650,7 @@ const client = {
|
|
|
6637
6650
|
console.error('fs listeners not ready during init');
|
|
6638
6651
|
}
|
|
6639
6652
|
globalService.send({ type: 'init', endpoints, models, addresses });
|
|
6640
|
-
import('./seed.schema.config-
|
|
6653
|
+
import('./seed.schema.config-BRGl01il.js').then(({ models }) => {
|
|
6641
6654
|
for (const [key, value] of Object.entries(models)) {
|
|
6642
6655
|
setModel(key, value);
|
|
6643
6656
|
}
|
|
@@ -6856,7 +6869,8 @@ const updateItemPropertyValue = (_a) => __awaiter(void 0, [_a], void 0, function
|
|
|
6856
6869
|
});
|
|
6857
6870
|
|
|
6858
6871
|
const analyzeInput = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
6859
|
-
const { localId, propertyName: propertyNameRaw, seedLocalId, versionLocalId, versionUid, propertyValue: existingValue, propertyRecordSchema, itemModelName,
|
|
6872
|
+
const { localId, propertyName: propertyNameRaw, seedLocalId, versionLocalId, versionUid, propertyValue: existingValue, propertyRecordSchema, itemModelName, } = context;
|
|
6873
|
+
let { schemaUid } = context;
|
|
6860
6874
|
let newValue;
|
|
6861
6875
|
if (event) {
|
|
6862
6876
|
newValue = event.newValue;
|
|
@@ -6895,8 +6909,14 @@ const analyzeInput = fromCallback(({ sendBack, input: { context, event } }) => {
|
|
|
6895
6909
|
});
|
|
6896
6910
|
return false;
|
|
6897
6911
|
}
|
|
6912
|
+
if (!schemaUid) {
|
|
6913
|
+
const schemaFromEas = yield getSchemaForProperty({ propertyName });
|
|
6914
|
+
if (schemaFromEas) {
|
|
6915
|
+
schemaUid = schemaFromEas.id;
|
|
6916
|
+
}
|
|
6917
|
+
}
|
|
6898
6918
|
yield updateItemPropertyValue({
|
|
6899
|
-
localId
|
|
6919
|
+
localId,
|
|
6900
6920
|
propertyName,
|
|
6901
6921
|
newValue,
|
|
6902
6922
|
seedLocalId,
|
|
@@ -7575,4 +7595,4 @@ if (isNode()) {
|
|
|
7575
7595
|
}
|
|
7576
7596
|
|
|
7577
7597
|
export { GET_SCHEMAS as G, Item as I, Json as J, List as L, Model as M, Property as P, Relation as R, Text as T, GET_SCHEMA_BY_NAME as a, GET_SEEDS as b, GET_SEED_IDS as c, GET_STORAGE_TRANSACTION_ID as d, GET_VERSIONS as e, GET_PROPERTIES as f, GET_ALL_PROPERTIES_FOR_ALL_VERSIONS as g, itemMachineAll as h, itemMachineSingle as i, ImageSrc as j, ItemProperty as k, useItem as l, useItemProperties as m, useCreateItem as n, useItemProperty as o, useDeleteItem as p, useGlobalServiceStatus as q, useServices as r, getGlobalService as s, client as t, useItems as u, getCorrectId as v, withSeed as w };
|
|
7578
|
-
//# sourceMappingURL=index-
|
|
7598
|
+
//# sourceMappingURL=index-j7sFsIYr.js.map
|