@seedprotocol/sdk 0.1.91 → 0.1.93

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.
Files changed (28) hide show
  1. package/dist/{index-j7sFsIYr.js → index-DOiudQnZ.js} +187 -174
  2. package/dist/index-DOiudQnZ.js.map +1 -0
  3. package/dist/{index-B3xp2pDI.js → index-DRR_FeN7.js} +6 -6
  4. package/dist/{index-B3xp2pDI.js.map → index-DRR_FeN7.js.map} +1 -1
  5. package/dist/main.js +5 -5
  6. package/dist/{seed.schema.config-BRGl01il.js → seed.schema.config-CmrNDFvc.js} +6 -6
  7. package/dist/{seed.schema.config-BRGl01il.js.map → seed.schema.config-CmrNDFvc.js.map} +1 -1
  8. package/dist/src/actors.ts +7 -289
  9. package/dist/src/analyzeInput.ts +3 -2
  10. package/dist/src/getPublishPayload.ts +19 -2
  11. package/dist/src/getSchemaForItemProperty.ts +48 -0
  12. package/dist/src/index.ts +10 -62
  13. package/dist/src/publishMachine.ts +1 -1
  14. package/dist/src/updateMachineContext.ts +21 -0
  15. package/dist/types/src/browser/db/read/getPublishPayload.d.ts.map +1 -1
  16. package/dist/types/src/browser/helpers/getSchemaForItemProperty.d.ts +9 -0
  17. package/dist/types/src/browser/helpers/getSchemaForItemProperty.d.ts.map +1 -0
  18. package/dist/types/src/browser/{helpers.d.ts → helpers/index.d.ts} +1 -13
  19. package/dist/types/src/browser/helpers/index.d.ts.map +1 -0
  20. package/dist/types/src/browser/helpers/updateMachineContext.d.ts +7 -0
  21. package/dist/types/src/browser/helpers/updateMachineContext.d.ts.map +1 -0
  22. package/dist/types/src/browser/property/ItemProperty.d.ts +4 -4
  23. package/dist/types/src/browser/property/actors/saveValueToDb/analyzeInput.d.ts.map +1 -1
  24. package/dist/types/src/browser/property/propertyMachine.d.ts +8 -8
  25. package/dist/types/src/browser/services/global/globalMachine.d.ts +22 -22
  26. package/package.json +1 -1
  27. package/dist/index-j7sFsIYr.js.map +0 -1
  28. package/dist/types/src/browser/helpers.d.ts.map +0 -1
@@ -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 { BehaviorSubject } from 'rxjs';
19
+ import { useImmer } from 'use-immer';
20
+ import { useSelector } from '@xstate/react';
21
+ import EventEmitter from 'eventemitter3';
20
22
  import { immerable, produce, enableMapSet } from 'immer';
21
23
  import pluralize from 'pluralize';
22
- import EventEmitter from 'eventemitter3';
23
24
  import { createBrowserInspector } from '@statelyai/inspect';
25
+ import { BehaviorSubject } from 'rxjs';
24
26
  import { drizzle } from 'drizzle-orm/sqlite-proxy';
25
27
  import { WebAccess } from '@zenfs/dom';
26
28
  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-B3xp2pDI.js');
1071
+ const { Item } = yield import('./index-DRR_FeN7.js');
1072
1072
  const item = yield Item.find({
1073
1073
  seedLocalId,
1074
1074
  modelName: itemModelName,
@@ -1299,6 +1299,127 @@ 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
+
1345
+ const getSchemaUidForModel = (modelName) => __awaiter(void 0, void 0, void 0, function* () {
1346
+ const modeType = modelName.toLowerCase();
1347
+ const modelSchemaQuery = yield queryClient.fetchQuery({
1348
+ queryKey: [`getPropertySchema${modelName}`],
1349
+ queryFn: () => __awaiter(void 0, void 0, void 0, function* () {
1350
+ return easClient.request(GET_SCHEMAS, {
1351
+ where: {
1352
+ schemaNames: {
1353
+ some: {
1354
+ name: {
1355
+ equals: modeType,
1356
+ },
1357
+ },
1358
+ },
1359
+ },
1360
+ });
1361
+ }),
1362
+ });
1363
+ const foundSchema = modelSchemaQuery.schemas[0];
1364
+ return foundSchema.id;
1365
+ });
1366
+
1367
+ debug('app:write');
1368
+ const createSeed = (_a) => __awaiter(void 0, [_a], void 0, function* ({ type, seedUid }) {
1369
+ const schemaUid = yield getSchemaUidForModel(type);
1370
+ if (!schemaUid) {
1371
+ throw new Error(`No schema found for model type: ${type}`);
1372
+ }
1373
+ const appDb = getAppDb();
1374
+ const newSeedLocalId = generateId();
1375
+ yield appDb.insert(seeds).values({
1376
+ localId: newSeedLocalId,
1377
+ type,
1378
+ uid: seedUid,
1379
+ createdAt: Date.now(),
1380
+ schemaUid,
1381
+ });
1382
+ return newSeedLocalId;
1383
+ });
1384
+ const createNewItem = (_a) => __awaiter(void 0, void 0, void 0, function* () {
1385
+ var _b;
1386
+ var { modelName } = _a, propertyData = __rest(_a, ["modelName"]);
1387
+ if (!modelName) {
1388
+ throw new Error('A model name is required for createNewItem');
1389
+ }
1390
+ const seedType = modelName.toLowerCase();
1391
+ const newSeedId = yield createSeed({ type: seedType });
1392
+ const newVersionId = yield createVersion({ seedLocalId: newSeedId });
1393
+ const propertySchemas = (_b = getModel(modelName)) === null || _b === void 0 ? void 0 : _b.schema;
1394
+ for (const [propertyName, propertyValue] of Object.entries(propertyData)) {
1395
+ let propertyRecordSchema;
1396
+ if (propertySchemas && propertySchemas[propertyName]) {
1397
+ propertyRecordSchema = propertySchemas[propertyName];
1398
+ }
1399
+ yield createMetadata({
1400
+ seedLocalId: newSeedId,
1401
+ versionLocalId: newVersionId,
1402
+ propertyName,
1403
+ propertyValue,
1404
+ modelName,
1405
+ }, propertyRecordSchema);
1406
+ // await appDb.run(
1407
+ // sql.raw(
1408
+ // `INSERT INTO metadata (seed_local_id, version_local_id, property_name, property_value, model_type, created_at,
1409
+ // attestation_created_at)
1410
+ // VALUES ('${newSeedId}', '${newVersionId}', '${propertyName}', '${propertyValue}', '${seedType}', ${Date.now()},
1411
+ // ${Date.now()});`,
1412
+ // ),
1413
+ // )
1414
+ }
1415
+ // eventEmitter.emit(`item.requestAll`, { modelName })
1416
+ return {
1417
+ modelName,
1418
+ seedLocalId: newSeedId,
1419
+ versionLocalId: newVersionId,
1420
+ };
1421
+ });
1422
+
1302
1423
  const eventEmitter = new EventEmitter();
1303
1424
 
1304
1425
  var _a$2;
@@ -2501,7 +2622,7 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
2501
2622
  if (!models$1) {
2502
2623
  return;
2503
2624
  }
2504
- const { models: SeedModels } = yield import('./seed.schema.config-BRGl01il.js');
2625
+ const { models: SeedModels } = yield import('./seed.schema.config-CmrNDFvc.js');
2505
2626
  const allModels = Object.assign(Object.assign({}, SeedModels), models$1);
2506
2627
  let hasModelsInDb = false;
2507
2628
  const schemaDefsByModelName = new Map();
@@ -4683,6 +4804,20 @@ const createPublishAttempt = fromCallback(({ sendBack, input: { context } }) =>
4683
4804
  });
4684
4805
  });
4685
4806
 
4807
+ const updateMachineContext = {
4808
+ actions: assign(({ context, event }) => {
4809
+ const newContext = Object.assign({}, context);
4810
+ for (let i = 0; i < Object.keys(event).length; i++) {
4811
+ const key = Object.keys(event)[i];
4812
+ if (key === 'type') {
4813
+ continue;
4814
+ }
4815
+ newContext[key] = event[key];
4816
+ }
4817
+ return Object.assign({}, newContext);
4818
+ }),
4819
+ };
4820
+
4686
4821
  const preparePublishRequestData = fromCallback(({ sendBack, input: { context } }) => {
4687
4822
  const { localId } = context;
4688
4823
  const _preparePublishRequestData = () => __awaiter(void 0, void 0, void 0, function* () {
@@ -5652,6 +5787,37 @@ const getItem = (_a) => __awaiter(void 0, [_a], void 0, function* ({ modelName,
5652
5787
  return Item.create(itemInitObj);
5653
5788
  });
5654
5789
 
5790
+ const getSchemaForItemProperty = (_a) => __awaiter(void 0, [_a], void 0, function* ({ schemaUid, propertyName, }) {
5791
+ let queryParams = {
5792
+ where: {
5793
+ id: {
5794
+ equals: schemaUid,
5795
+ },
5796
+ },
5797
+ };
5798
+ if (!schemaUid || schemaUid === 'null' || schemaUid === 'undefined') {
5799
+ queryParams = {
5800
+ where: {
5801
+ schemaNames: {
5802
+ some: {
5803
+ name: {
5804
+ equals: toSnakeCase(propertyName),
5805
+ },
5806
+ },
5807
+ },
5808
+ },
5809
+ };
5810
+ }
5811
+ const foundPropertySchema = yield queryClient.fetchQuery({
5812
+ queryKey: [`getPropertySchema${propertyName}`],
5813
+ queryFn: () => __awaiter(void 0, void 0, void 0, function* () { return easClient.request(GET_SCHEMAS, queryParams); }),
5814
+ networkMode: 'offlineFirst',
5815
+ });
5816
+ if (foundPropertySchema && foundPropertySchema.schemas.length > 0) {
5817
+ return foundPropertySchema.schemas[0];
5818
+ }
5819
+ });
5820
+
5655
5821
  const getPublishPayload = (seedLocalId) => __awaiter(void 0, void 0, void 0, function* () {
5656
5822
  const item = yield getItem({ seedLocalId });
5657
5823
  if (!item) {
@@ -5668,7 +5834,18 @@ const getPublishPayload = (seedLocalId) => __awaiter(void 0, void 0, void 0, fun
5668
5834
  if (!itemProperty.value || !itemProperty.propertyDef) {
5669
5835
  continue;
5670
5836
  }
5671
- const foundPropertySchema = yield getSchemaForProperty(itemProperty);
5837
+ let propertyNameForSchema = propertyName;
5838
+ if (itemProperty.propertyDef.dataType === 'Relation') {
5839
+ propertyNameForSchema = `${propertyName}Id`;
5840
+ }
5841
+ if (itemProperty.propertyDef.dataType === 'List' &&
5842
+ itemProperty.propertyDef.ref) {
5843
+ propertyNameForSchema = `${propertyName}Ids`;
5844
+ }
5845
+ const foundPropertySchema = yield getSchemaForItemProperty({
5846
+ schemaUid: itemProperty.schemaUid,
5847
+ propertyName: propertyNameForSchema,
5848
+ });
5672
5849
  if (!foundPropertySchema) {
5673
5850
  throw new Error(`No schema found for property ${itemProperty.propertyName} ${itemProperty.localId}`);
5674
5851
  }
@@ -5950,170 +6127,6 @@ class Item {
5950
6127
  _a$1 = immerable;
5951
6128
  Item.instanceCache = new Map();
5952
6129
 
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
-
6117
6130
  const logger$4 = debug('app:react:services');
6118
6131
  const finalStrings = ['idle', 'ready', 'done', 'success', 'initialized'];
6119
6132
  const getServiceName = (service) => {
@@ -6650,7 +6663,7 @@ const client = {
6650
6663
  console.error('fs listeners not ready during init');
6651
6664
  }
6652
6665
  globalService.send({ type: 'init', endpoints, models, addresses });
6653
- import('./seed.schema.config-BRGl01il.js').then(({ models }) => {
6666
+ import('./seed.schema.config-CmrNDFvc.js').then(({ models }) => {
6654
6667
  for (const [key, value] of Object.entries(models)) {
6655
6668
  setModel(key, value);
6656
6669
  }
@@ -6910,7 +6923,7 @@ const analyzeInput = fromCallback(({ sendBack, input: { context, event } }) => {
6910
6923
  return false;
6911
6924
  }
6912
6925
  if (!schemaUid) {
6913
- const schemaFromEas = yield getSchemaForProperty({ propertyName });
6926
+ const schemaFromEas = yield getSchemaForItemProperty({ propertyName });
6914
6927
  if (schemaFromEas) {
6915
6928
  schemaUid = schemaFromEas.id;
6916
6929
  }
@@ -7595,4 +7608,4 @@ if (isNode()) {
7595
7608
  }
7596
7609
 
7597
7610
  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 };
7598
- //# sourceMappingURL=index-j7sFsIYr.js.map
7611
+ //# sourceMappingURL=index-DOiudQnZ.js.map