@datrix/adapter-json 0.1.0 → 0.1.2

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.mjs CHANGED
@@ -707,7 +707,7 @@ var JsonTransaction = class {
707
707
  };
708
708
 
709
709
  // src/adapter.ts
710
- import { FORJA_META_MODEL as FORJA_META_MODEL2, FORJA_META_KEY_PREFIX } from "@datrix/core";
710
+ import { DATRIX_META_MODEL as DATRIX_META_MODEL2, DATRIX_META_KEY_PREFIX } from "@datrix/core";
711
711
 
712
712
  // src/table-utils.ts
713
713
  import {
@@ -717,7 +717,7 @@ import {
717
717
  throwUniqueConstraintField,
718
718
  throwUniqueConstraintIndex
719
719
  } from "@datrix/core";
720
- import { FORJA_META_MODEL } from "@datrix/core";
720
+ import { DATRIX_META_MODEL } from "@datrix/core";
721
721
  function validateTableName(tableName) {
722
722
  if (tableName.includes("\0")) {
723
723
  throwMigrationError({
@@ -742,13 +742,13 @@ function validateTableName(tableName) {
742
742
  }
743
743
  }
744
744
  async function createMetaTable(adapter) {
745
- const metaExists = await adapter.tableExists(FORJA_META_MODEL);
745
+ const metaExists = await adapter.tableExists(DATRIX_META_MODEL);
746
746
  if (metaExists) {
747
747
  return;
748
748
  }
749
749
  const metaSchema = {
750
- name: FORJA_META_MODEL,
751
- tableName: FORJA_META_MODEL,
750
+ name: DATRIX_META_MODEL,
751
+ tableName: DATRIX_META_MODEL,
752
752
  fields: {
753
753
  id: { type: "number", autoIncrement: true },
754
754
  key: { type: "string", required: true, unique: true, maxLength: 255 },
@@ -1617,8 +1617,8 @@ var JsonAdapter = class {
1617
1617
  * @param tableName - Physical table name (e.g. "users")
1618
1618
  */
1619
1619
  async readTableSchema(tableName) {
1620
- const metaFile = await this.readTable(FORJA_META_MODEL2);
1621
- const metaKey = `${FORJA_META_KEY_PREFIX}${tableName}`;
1620
+ const metaFile = await this.readTable(DATRIX_META_MODEL2);
1621
+ const metaKey = `${DATRIX_META_KEY_PREFIX}${tableName}`;
1622
1622
  const row = metaFile.data.find(
1623
1623
  (r) => r["key"] === metaKey
1624
1624
  );
@@ -1633,9 +1633,9 @@ var JsonAdapter = class {
1633
1633
  * Upsert schema into _datrix metadata table
1634
1634
  */
1635
1635
  async upsertSchemaMeta(schema, skipWrite) {
1636
- const metaKey = `${FORJA_META_KEY_PREFIX}${schema.tableName ?? schema.name}`;
1636
+ const metaKey = `${DATRIX_META_KEY_PREFIX}${schema.tableName ?? schema.name}`;
1637
1637
  const metaValue = JSON.stringify(schema);
1638
- const metaFile = await this.readTable(FORJA_META_MODEL2);
1638
+ const metaFile = await this.readTable(DATRIX_META_MODEL2);
1639
1639
  const existingIndex = metaFile.data.findIndex(
1640
1640
  (r) => r["key"] === metaKey
1641
1641
  );
@@ -1652,15 +1652,15 @@ var JsonAdapter = class {
1652
1652
  }
1653
1653
  metaFile.meta.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
1654
1654
  if (skipWrite) {
1655
- this.activeTransactionCache.set(FORJA_META_MODEL2, {
1655
+ this.activeTransactionCache.set(DATRIX_META_MODEL2, {
1656
1656
  data: metaFile,
1657
1657
  mtime: Date.now()
1658
1658
  });
1659
- this.activeTransactionModifiedTables.add(FORJA_META_MODEL2);
1659
+ this.activeTransactionModifiedTables.add(DATRIX_META_MODEL2);
1660
1660
  } else {
1661
- const filePath = this.getTablePath(FORJA_META_MODEL2);
1661
+ const filePath = this.getTablePath(DATRIX_META_MODEL2);
1662
1662
  await fs2.writeFile(filePath, JSON.stringify(metaFile, null, 2), "utf-8");
1663
- await this.updateCache(FORJA_META_MODEL2, metaFile);
1663
+ await this.updateCache(DATRIX_META_MODEL2, metaFile);
1664
1664
  }
1665
1665
  }
1666
1666
  /**
@@ -1822,12 +1822,12 @@ var JsonAdapter = class {
1822
1822
  await this.updateCache(tableName, initialContent);
1823
1823
  }
1824
1824
  if (!isImport) {
1825
- if (schema.name !== FORJA_META_MODEL2) {
1826
- const metaExists = await this.tableExists(FORJA_META_MODEL2);
1825
+ if (schema.name !== DATRIX_META_MODEL2) {
1826
+ const metaExists = await this.tableExists(DATRIX_META_MODEL2);
1827
1827
  if (!metaExists) {
1828
1828
  throwMigrationError2({
1829
1829
  adapter: "json",
1830
- message: `Cannot create table '${schema.name}': '${FORJA_META_MODEL2}' table does not exist yet. Create '${FORJA_META_MODEL2}' first.`
1830
+ message: `Cannot create table '${schema.name}': '${DATRIX_META_MODEL2}' table does not exist yet. Create '${DATRIX_META_MODEL2}' first.`
1831
1831
  });
1832
1832
  }
1833
1833
  }
@@ -1877,27 +1877,27 @@ var JsonAdapter = class {
1877
1877
  await fs2.unlink(filePath);
1878
1878
  this.invalidateCache(tableName);
1879
1879
  }
1880
- if (!isImport && tableName !== FORJA_META_MODEL2) {
1881
- const metaKey = `${FORJA_META_KEY_PREFIX}${tableName}`;
1882
- const metaFile = await this.readTable(FORJA_META_MODEL2);
1880
+ if (!isImport && tableName !== DATRIX_META_MODEL2) {
1881
+ const metaKey = `${DATRIX_META_KEY_PREFIX}${tableName}`;
1882
+ const metaFile = await this.readTable(DATRIX_META_MODEL2);
1883
1883
  metaFile.data = metaFile.data.filter(
1884
1884
  (r) => r["key"] !== metaKey
1885
1885
  );
1886
1886
  metaFile.meta.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
1887
1887
  if (skipWrite) {
1888
- this.activeTransactionCache.set(FORJA_META_MODEL2, {
1888
+ this.activeTransactionCache.set(DATRIX_META_MODEL2, {
1889
1889
  data: metaFile,
1890
1890
  mtime: Date.now()
1891
1891
  });
1892
- this.activeTransactionModifiedTables.add(FORJA_META_MODEL2);
1892
+ this.activeTransactionModifiedTables.add(DATRIX_META_MODEL2);
1893
1893
  } else {
1894
- const filePath = this.getTablePath(FORJA_META_MODEL2);
1894
+ const filePath = this.getTablePath(DATRIX_META_MODEL2);
1895
1895
  await fs2.writeFile(
1896
1896
  filePath,
1897
1897
  JSON.stringify(metaFile, null, 2),
1898
1898
  "utf-8"
1899
1899
  );
1900
- await this.updateCache(FORJA_META_MODEL2, metaFile);
1900
+ await this.updateCache(DATRIX_META_MODEL2, metaFile);
1901
1901
  }
1902
1902
  }
1903
1903
  }
@@ -2181,7 +2181,7 @@ var JsonAdapter = class {
2181
2181
  await fs2.writeFile(filePath, JSON.stringify(json, null, 2), "utf-8");
2182
2182
  await this.updateCache(tableName, json);
2183
2183
  }
2184
- if (tableName !== FORJA_META_MODEL2) {
2184
+ if (tableName !== DATRIX_META_MODEL2) {
2185
2185
  await this.applyOperationsToMetaSchema(tableName, operations, skipWrite);
2186
2186
  }
2187
2187
  }
@@ -2240,10 +2240,10 @@ var JsonAdapter = class {
2240
2240
  this.invalidateCache(from);
2241
2241
  await this.updateCache(to, json);
2242
2242
  }
2243
- if (from !== FORJA_META_MODEL2 && to !== FORJA_META_MODEL2) {
2244
- const oldKey = `${FORJA_META_KEY_PREFIX}${from}`;
2245
- const newKey = `${FORJA_META_KEY_PREFIX}${to}`;
2246
- const metaFile = await this.readTable(FORJA_META_MODEL2);
2243
+ if (from !== DATRIX_META_MODEL2 && to !== DATRIX_META_MODEL2) {
2244
+ const oldKey = `${DATRIX_META_KEY_PREFIX}${from}`;
2245
+ const newKey = `${DATRIX_META_KEY_PREFIX}${to}`;
2246
+ const metaFile = await this.readTable(DATRIX_META_MODEL2);
2247
2247
  const row = metaFile.data.find(
2248
2248
  (r) => r["key"] === oldKey
2249
2249
  );
@@ -2251,19 +2251,19 @@ var JsonAdapter = class {
2251
2251
  row["key"] = newKey;
2252
2252
  metaFile.meta.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
2253
2253
  if (skipWrite) {
2254
- this.activeTransactionCache.set(FORJA_META_MODEL2, {
2254
+ this.activeTransactionCache.set(DATRIX_META_MODEL2, {
2255
2255
  data: metaFile,
2256
2256
  mtime: Date.now()
2257
2257
  });
2258
- this.activeTransactionModifiedTables.add(FORJA_META_MODEL2);
2258
+ this.activeTransactionModifiedTables.add(DATRIX_META_MODEL2);
2259
2259
  } else {
2260
- const metaPath = this.getTablePath(FORJA_META_MODEL2);
2260
+ const metaPath = this.getTablePath(DATRIX_META_MODEL2);
2261
2261
  await fs2.writeFile(
2262
2262
  metaPath,
2263
2263
  JSON.stringify(metaFile, null, 2),
2264
2264
  "utf-8"
2265
2265
  );
2266
- await this.updateCache(FORJA_META_MODEL2, metaFile);
2266
+ await this.updateCache(DATRIX_META_MODEL2, metaFile);
2267
2267
  }
2268
2268
  }
2269
2269
  }