@seedprotocol/sdk 0.1.5 → 0.1.7

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { n as __awaiter, D as DB_NAME_SDK_CONFIG, o as models, S as SCHEMA_NJK, p as SCHEMA_TS, q as SDK_DB_CONFIG, r as SEED_DB_CONFIG, A as APP_DB_CONFIG, s as addModelsToInternalDb } from './index-CNBlL-jO.js';
2
+ import { n as __awaiter, D as DB_NAME_SDK_CONFIG, o as models, S as SCHEMA_NJK, p as SCHEMA_TS, q as SDK_DB_CONFIG, r as SEED_DB_CONFIG, A as APP_DB_CONFIG, s as addModelsToInternalDb } from './index-B8GMq1lE.js';
3
3
  import path from 'path';
4
4
  import fs from 'fs';
5
5
  import { exec as exec$1 } from 'child_process';
@@ -17,7 +17,7 @@ import { camelCase, snakeCase } from 'lodash-es';
17
17
  import * as nunjucks from 'nunjucks';
18
18
  import Database from 'better-sqlite3';
19
19
  import { drizzle } from 'drizzle-orm/better-sqlite3';
20
- import './seed.schema.config-CFp_quWt.js';
20
+ import './seed.schema.config-Bq0uQNxG.js';
21
21
  import { defineConfig } from 'drizzle-kit';
22
22
  import dotenv from 'dotenv';
23
23
  import 'reflect-metadata';
@@ -1650,7 +1650,7 @@ const hydrateFromDb = fromCallback(({ sendBack, input: { context } }) => {
1650
1650
  renderValue: refResolvedDisplayValue,
1651
1651
  });
1652
1652
  if (propertyNameFromDb === 'storageTransactionId') {
1653
- const { Item } = yield import('./index-o-DJt8pS.js');
1653
+ const { Item } = yield import('./index-Bc3TXOPI.js');
1654
1654
  const item = yield Item.find({
1655
1655
  seedLocalId,
1656
1656
  modelName: itemModelName,
@@ -2116,7 +2116,7 @@ const addModelsToDb = fromCallback(({ sendBack, input: { context } }) => {
2116
2116
  if (!models$1) {
2117
2117
  return;
2118
2118
  }
2119
- const { models: SeedModels } = yield import('./seed.schema.config-CFp_quWt.js');
2119
+ const { models: SeedModels } = yield import('./seed.schema.config-Bq0uQNxG.js');
2120
2120
  const allModels = Object.assign(Object.assign({}, SeedModels), models$1);
2121
2121
  let hasModelsInDb = false;
2122
2122
  const schemaDefsByModelName = new Map();
@@ -4236,11 +4236,11 @@ const globalMachine = setup({
4236
4236
  (_a) => __awaiter(void 0, [_a], void 0, function* ({ context }) {
4237
4237
  let SeedClass;
4238
4238
  if (context.environment === 'node') {
4239
- const { SeedNode } = yield import('./seed-DykcKEyf.js');
4239
+ const { SeedNode } = yield import('./seed-67gCBvdP.js');
4240
4240
  SeedClass = SeedNode;
4241
4241
  }
4242
4242
  else {
4243
- const { SeedBrowser } = yield import('./seed-Drx1JpCZ.js');
4243
+ const { SeedBrowser } = yield import('./seed-C7Q0_oW_.js');
4244
4244
  SeedClass = SeedBrowser;
4245
4245
  }
4246
4246
  return SeedClass;
@@ -5696,9 +5696,10 @@ const useItem = ({ modelName, seedLocalId, seedUid }) => {
5696
5696
  }
5697
5697
  }, [internalStatus, status]);
5698
5698
  useEffect(() => {
5699
- eventEmitter.addListener(`item.${modelName}.${seedLocalId}.update`, readFromDb);
5699
+ const seedId = seedUid || seedLocalId;
5700
+ eventEmitter.addListener(`item.${modelName}.${seedId}.update`, readFromDb);
5700
5701
  return () => {
5701
- eventEmitter.removeListener(`item.${modelName}.${seedLocalId}.update`, readFromDb);
5702
+ eventEmitter.removeListener(`item.${modelName}.${seedId}.update`, readFromDb);
5702
5703
  };
5703
5704
  }, []);
5704
5705
  return {
@@ -5950,6 +5951,12 @@ const getVersionData = (_a) => __awaiter(void 0, [_a], void 0, function* ({ seed
5950
5951
  });
5951
5952
 
5952
5953
  const logger$1 = debug('app:write');
5954
+ const sendItemUpdateEvent = ({ modelName, seedLocalId, seedUid }) => {
5955
+ if (!modelName || (!seedLocalId && !seedUid)) {
5956
+ return;
5957
+ }
5958
+ eventEmitter.emit(`item.${modelName}.${seedUid || seedLocalId}.update`);
5959
+ };
5953
5960
  const createSeed = (_a) => __awaiter(void 0, [_a], void 0, function* ({ type }) {
5954
5961
  const appDb = getAppDb();
5955
5962
  const newSeedLocalId = generateId();
@@ -6053,7 +6060,7 @@ const updateItemPropertyValue = (_a) => __awaiter(void 0, [_a], void 0, function
6053
6060
  const propertyNameFromDb = mostRecentRecord[2];
6054
6061
  const propertyValueFromDb = mostRecentRecord[3];
6055
6062
  const modelType = mostRecentRecord[4];
6056
- mostRecentRecord[5];
6063
+ const seedUid = mostRecentRecord[5];
6057
6064
  const seedLocalIdFromDb = mostRecentRecord[6];
6058
6065
  const versionLocalId = mostRecentRecord[7];
6059
6066
  mostRecentRecord[8];
@@ -6073,7 +6080,7 @@ const updateItemPropertyValue = (_a) => __awaiter(void 0, [_a], void 0, function
6073
6080
  updated_at = ${Date.now()}
6074
6081
  WHERE local_id = '${localId}';`;
6075
6082
  yield runQueryForStatement(updatePropertyStatement);
6076
- eventEmitter.emit(`item.${modelName}.${seedLocalId}.update`);
6083
+ sendItemUpdateEvent({ modelName, seedLocalId, seedUid });
6077
6084
  return;
6078
6085
  }
6079
6086
  const seedDataFromDb = yield getSeedData({ seedLocalId });
@@ -6109,7 +6116,7 @@ const updateItemPropertyValue = (_a) => __awaiter(void 0, [_a], void 0, function
6109
6116
  ${refResolvedDisplayValue ? `'${refResolvedDisplayValue}'` : 'NULL'},
6110
6117
  ${Date.now()});`;
6111
6118
  yield runQueryForStatement(newPropertyStatement);
6112
- eventEmitter.emit(`item.${modelName}.${seedLocalId}.update`);
6119
+ sendItemUpdateEvent({ modelName, seedLocalId, seedUid });
6113
6120
  return;
6114
6121
  }
6115
6122
  // Here there are no records for this property on this seed so we should create one
@@ -6153,137 +6160,8 @@ const updateItemPropertyValue = (_a) => __awaiter(void 0, [_a], void 0, function
6153
6160
  ${refResolvedDisplayValue ? `'${refResolvedDisplayValue}'` : 'NULL'},
6154
6161
  ${Date.now()});`;
6155
6162
  yield runQueryForStatement(newPropertyStatement);
6156
- eventEmitter.emit(`item.${modelName}.${seedLocalId}.update`);
6163
+ sendItemUpdateEvent({ modelName, seedLocalId, seedUid });
6157
6164
  });
6158
- // if (propertyLocalId) {
6159
- // const existingItemPropertyStatement = `SELECT local_id,
6160
- // uid,
6161
- // property_name,
6162
- // property_value,
6163
- // model_type,
6164
- // seed_uid,
6165
- // seed_local_id,
6166
- // version_local_id,
6167
- // version_uid,
6168
- // schema_uid
6169
- // FROM metadata
6170
- // WHERE local_id = '${propertyLocalId}';`
6171
- //
6172
- // const { rows } = await runQueryForStatement(existingItemPropertyStatement)
6173
- //
6174
- // if (!rows || rows.length === 0) {
6175
- // logger(
6176
- // `[db/write] [updateItemPropertyValue] no property found for local_id: ${propertyLocalId}`,
6177
- // )
6178
- // return
6179
- // }
6180
- //
6181
- // const propertyValues = rows[0]
6182
- // const propertyUid = propertyValues[1]
6183
- //
6184
- // if (!propertyUid) {
6185
- // const updatePropertyStatement = `UPDATE metadata
6186
- // SET property_value = '${safeNewValue}',
6187
- // ref_seed_type = ${refSeedType ? `'${refSeedType}'` : 'NULL'},
6188
- // ref_resolved_value = ${refResolvedValue ? `'${refResolvedValue}'` : 'NULL'},
6189
- // ref_resolved_display_value = ${refResolvedDisplayValue ? `'${refResolvedDisplayValue}'` : 'NULL'},
6190
- // updated_at = ${Date.now()}
6191
- // WHERE local_id = '${propertyLocalId}';`
6192
- //
6193
- // await runQueryForStatement(updatePropertyStatement)
6194
- //
6195
- // return
6196
- // }
6197
- // const newLocalId = generateId()
6198
- // const propertyNameFromDb = propertyValues[2]
6199
- // const modelType = propertyValues[4]
6200
- // const seedUid = propertyValues[5]
6201
- // const seedLocaIdFromDb = propertyValues[6]
6202
- // const versionLocalId = propertyValues[7]
6203
- // const versionUid = propertyValues[8]
6204
- // const schemaUid = propertyValues[9]
6205
- // const easDataType = propertyValues[10]
6206
- //
6207
- // const newPropertyStatement = `INSERT INTO metadata (local_id,
6208
- // property_name,
6209
- // property_value,
6210
- // model_type,
6211
- // seed_uid,
6212
- // seed_local_id,
6213
- // version_local_id,
6214
- // version_uid,
6215
- // schema_uid,
6216
- // eas_data_type,
6217
- // created_at)
6218
- // VALUES ('${newLocalId}',
6219
- // '${propertyNameFromDb}',
6220
- // '${safeNewValue}',
6221
- // '${modelType}',
6222
- // '${seedUid}',
6223
- // '${seedLocaIdFromDb}',
6224
- // '${versionLocalId}',
6225
- // '${versionUid}',
6226
- // '${schemaUid}',
6227
- // '${easDataType}',
6228
- // ${Date.now()});`
6229
- //
6230
- // await runQueryForStatement(newPropertyStatement)
6231
- //
6232
- // return
6233
- // }
6234
- //
6235
- // if (seedLocalId && propertyName) {
6236
- // const existingItemPropertyStatement = `SELECT local_id, uid
6237
- // FROM metadata
6238
- // WHERE seed_local_id = '${seedLocalId}'
6239
- // AND property_name = '${propertyName}'
6240
- // ORDER BY COALESCE(attestation_created_at, created_at) DESC;`
6241
- //
6242
- // const { rows } = await runQueryForStatement(existingItemPropertyStatement)
6243
- //
6244
- // if (!rows || rows.length === 0) {
6245
- // // This means that there's no existing record for this property_name on the seed
6246
- // const createMetadataStatement = `INSERT INTO metadata (local_id,
6247
- // seed_local_id,
6248
- // property_name,
6249
- // property_value,
6250
- // model_type,
6251
- // ref_seed_type,
6252
- // ref_resolved_value,
6253
- // ref_resolved_display_value,
6254
- // version_local_id,
6255
- // schema_uid,
6256
- // created_at,
6257
- // updated_at)
6258
- // VALUES ('${generateId()}',
6259
- // '${seedLocalId}',
6260
- // '${propertyName}',
6261
- // '${safeNewValue}',
6262
- // '${modelName}',
6263
- // ${refSeedType ? `'${refSeedType}'` : 'NULL'},
6264
- // ${refResolvedValue ? `'${refResolvedValue}'` : 'NULL'},
6265
- // ${refResolvedDisplayValue ? `'${refResolvedDisplayValue}'` : 'NULL'},
6266
- // '${versionLocalId}',
6267
- // '${schemaUid}',
6268
- // ${Date.now()},
6269
- // ${Date.now()});`
6270
- //
6271
- // await runQueryForStatement(createMetadataStatement)
6272
- //
6273
- // return
6274
- // }
6275
- //
6276
- // const updatePropertyStatement = `UPDATE metadata
6277
- // SET property_value = '${newValue}',
6278
- // ref_seed_type = ${refSeedType ? `'${refSeedType}'` : 'NULL'},
6279
- // ref_resolved_value = ${refResolvedValue ? `'${refResolvedValue}'` : 'NULL'},
6280
- // ref_resolved_display_value = ${refResolvedDisplayValue ? `'${refResolvedDisplayValue}'` : 'NULL'}
6281
- // WHERE seed_local_id = '${seedLocalId}'
6282
- // AND property_name = '${propertyName}';`
6283
- //
6284
- // await runQueryForStatement(updatePropertyStatement)
6285
- //
6286
- // return
6287
6165
 
6288
6166
  const saveValueToDb = fromCallback(({ sendBack, input: { context, event } }) => {
6289
6167
  const { localId, propertyName: propertyNameRaw, seedLocalId, propertyValue: existingValue, propertyRecordSchema, itemModelName, schemaUid, } = context;
@@ -6916,7 +6794,7 @@ const client = {
6916
6794
  console.error('fs listeners not ready during init');
6917
6795
  }
6918
6796
  globalService.send({ type: 'init', endpoints, models, addresses });
6919
- import('./seed.schema.config-CFp_quWt.js').then(({ models }) => {
6797
+ import('./seed.schema.config-Bq0uQNxG.js').then(({ models }) => {
6920
6798
  for (const [key, value] of Object.entries(models)) {
6921
6799
  modelStore.set(key, value);
6922
6800
  }
@@ -6974,4 +6852,4 @@ const client = {
6974
6852
  };
6975
6853
 
6976
6854
  export { APP_DB_CONFIG as A, useCreateItem as B, CHILD_SNAPSHOT as C, DB_NAME_SDK_CONFIG as D, useItemProperty as E, useDeleteItem as F, GET_SCHEMAS as G, getGlobalService as H, Item as I, Json as J, getCorrectId as K, List as L, Model as M, Property as P, Relation as R, SCHEMA_NJK as S, Text as T, __decorate as _, GET_SEEDS as a, GET_SEED_IDS as b, GET_STORAGE_TRANSACTION_ID as c, GET_VERSIONS as d, GET_PROPERTIES as e, GET_ALL_PROPERTIES_FOR_ALL_VERSIONS as f, itemMachineAll as g, __metadata as h, itemMachineSingle as i, internalMachine as j, isNode as k, isBrowser as l, isReactNative as m, __awaiter as n, models as o, SCHEMA_TS as p, SDK_DB_CONFIG as q, SEED_DB_CONFIG as r, addModelsToInternalDb as s, client as t, ImageSrc as u, ItemProperty as v, withSeed as w, useItems as x, useItem as y, useItemProperties as z };
6977
- //# sourceMappingURL=index-CNBlL-jO.js.map
6855
+ //# sourceMappingURL=index-B8GMq1lE.js.map