@ai-matrx/records 0.58.111 → 0.58.113

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog — @ai-matrx/records
2
2
 
3
+ ## 0.58.113
4
+
5
+ Automatic changed-only republish (docs/metadata drift since the last tag — see
6
+ `git diff npm/records/v0.58.112..npm/records/v0.58.113 -- apps/shared/records`).
7
+ No source changes intended and no consumer action required.
8
+
9
+ ## 0.58.112
10
+
11
+ Automatic changed-only republish (docs/metadata drift since the last tag — see
12
+ `git diff npm/records/v0.58.111..npm/records/v0.58.112 -- apps/shared/records`).
13
+ No source changes intended and no consumer action required.
14
+
3
15
  ## 0.58.111
4
16
  ### Unreleased
5
17
 
@@ -40832,6 +40832,51 @@ function createRecordsClient(config) {
40832
40832
  "recordRead"
40833
40833
  );
40834
40834
  }
40835
+ const readOrgs = (filter) => {
40836
+ if (filter) return [filter];
40837
+ const all = [...org ? [org] : [], ...config.organizationIds ?? []];
40838
+ const unique = [...new Set(all)];
40839
+ return unique.length > 0 ? unique : [org];
40840
+ };
40841
+ const siblings = /* @__PURE__ */ new Map();
40842
+ const clientFor = (target) => {
40843
+ if (target === org) return client;
40844
+ const key = target;
40845
+ let sibling = siblings.get(key);
40846
+ if (!sibling) {
40847
+ sibling = createRecordsClient({ ...config, organizationId: target, organizationIds: [] });
40848
+ siblings.set(key, sibling);
40849
+ }
40850
+ return sibling;
40851
+ };
40852
+ const recordOrgs = /* @__PURE__ */ new Map();
40853
+ async function acrossOrgs(filter, ask, merge) {
40854
+ const targets = readOrgs(filter);
40855
+ if (targets.length === 1) return ask(clientFor(targets[0] ?? null));
40856
+ const answers = await Promise.all(targets.map((t) => ask(clientFor(t))));
40857
+ const parts = [];
40858
+ let firstError = null;
40859
+ for (const a of answers) {
40860
+ if (a.ok) parts.push(a.data);
40861
+ else firstError ??= a.error;
40862
+ }
40863
+ if (parts.length === 0 && firstError) return err(firstError);
40864
+ return ok(merge(parts));
40865
+ }
40866
+ async function openInOwnOrg(recordId, filter, ask, found) {
40867
+ const known = recordOrgs.get(recordId);
40868
+ const targets = filter ? [filter] : known !== void 0 ? [known, ...readOrgs().filter((t) => t !== known)] : readOrgs();
40869
+ let last = null;
40870
+ for (const t of targets) {
40871
+ const answer = await ask(clientFor(t));
40872
+ if (answer.ok && found(answer.data)) {
40873
+ recordOrgs.set(recordId, t);
40874
+ return answer;
40875
+ }
40876
+ last ??= answer;
40877
+ }
40878
+ return last;
40879
+ }
40835
40880
  const client = {
40836
40881
  config,
40837
40882
  async recordWrite({ table_id, data }) {
@@ -40960,7 +41005,18 @@ function createRecordsClient(config) {
40960
41005
  "tableArchive"
40961
41006
  );
40962
41007
  },
40963
- async recordRead({ record_id, withComputed = false }) {
41008
+ async recordRead({ record_id, withComputed = false, organization_id }) {
41009
+ if (organization_id && organization_id !== org) {
41010
+ return clientFor(organization_id).recordRead({ record_id, withComputed, organization_id });
41011
+ }
41012
+ if (readOrgs(organization_id).length > 1) {
41013
+ return openInOwnOrg(
41014
+ record_id,
41015
+ organization_id,
41016
+ (sub) => sub.recordRead({ record_id, withComputed, organization_id: sub.config.organizationId }),
41017
+ () => true
41018
+ );
41019
+ }
40964
41020
  const door = await callDoor(
40965
41021
  DOORS.readRecord,
40966
41022
  { p_organization_id: org, p_record_id: record_id },
@@ -40996,8 +41052,18 @@ function createRecordsClient(config) {
40996
41052
  })
40997
41053
  );
40998
41054
  },
40999
- async tableFacts() {
41055
+ async tableFacts(args) {
41000
41056
  if (!doorExists(DOORS.tableFacts)) return ok(null);
41057
+ if (args?.organization_id && args.organization_id !== org) {
41058
+ return clientFor(args.organization_id).tableFacts(args);
41059
+ }
41060
+ if (readOrgs(args?.organization_id).length > 1) {
41061
+ return acrossOrgs(
41062
+ args?.organization_id,
41063
+ (sub) => sub.tableFacts({ organization_id: sub.config.organizationId }),
41064
+ (parts) => parts.flatMap((p) => p ?? [])
41065
+ );
41066
+ }
41001
41067
  return callDoor(DOORS.tableFacts, { p_organization_id: org }, "tableFacts");
41002
41068
  },
41003
41069
  async tablesLiveWhere({ table_ids }) {
@@ -41257,7 +41323,18 @@ function createRecordsClient(config) {
41257
41323
  offset: plan.read.offset
41258
41324
  });
41259
41325
  },
41260
- async tableRead({ table_id }) {
41326
+ async tableRead({ table_id, organization_id }) {
41327
+ if (organization_id && organization_id !== org) {
41328
+ return clientFor(organization_id).tableRead({ table_id, organization_id });
41329
+ }
41330
+ if (readOrgs(organization_id).length > 1) {
41331
+ return openInOwnOrg(
41332
+ table_id,
41333
+ organization_id,
41334
+ (sub) => sub.tableRead({ table_id, organization_id: sub.config.organizationId }),
41335
+ (t) => t !== null
41336
+ );
41337
+ }
41261
41338
  const kernel = await tableKernel("tableRead.kernel");
41262
41339
  if (!kernel.ok) return err(kernel.error);
41263
41340
  const door = await callDoor(
@@ -41271,7 +41348,19 @@ function createRecordsClient(config) {
41271
41348
  const { document: document2 } = unfold(row.document);
41272
41349
  return ok({ ...document2, id: row.id, organization_id: org });
41273
41350
  },
41274
- async tableList() {
41351
+ async tableList(args) {
41352
+ if (args?.organization_id && args.organization_id !== org) {
41353
+ return clientFor(args.organization_id).tableList(args);
41354
+ }
41355
+ if (readOrgs(args?.organization_id).length > 1) {
41356
+ const merged = await acrossOrgs(
41357
+ args?.organization_id,
41358
+ (sub) => sub.tableList({ organization_id: sub.config.organizationId }),
41359
+ (parts) => parts.flat()
41360
+ );
41361
+ if (merged.ok) merged.data.sort((a, b) => (a.name ?? "").localeCompare(b.name ?? ""));
41362
+ return merged;
41363
+ }
41275
41364
  const kernel = await tableKernel("tableList.kernel");
41276
41365
  if (!kernel.ok) return err(kernel.error);
41277
41366
  const door = await callDoor(
@@ -42326,7 +42415,18 @@ function createRecordsClient(config) {
42326
42415
  answered.data.map((row) => ({ ...row, id: row["signature_id"] }))
42327
42416
  );
42328
42417
  },
42329
- async recordValuesVersioned({ record_id }) {
42418
+ async recordValuesVersioned({ record_id, organization_id }) {
42419
+ if (organization_id && organization_id !== org) {
42420
+ return clientFor(organization_id).recordValuesVersioned({ record_id, organization_id });
42421
+ }
42422
+ if (readOrgs(organization_id).length > 1) {
42423
+ return openInOwnOrg(
42424
+ record_id,
42425
+ organization_id,
42426
+ (sub) => sub.recordValuesVersioned({ record_id, organization_id: sub.config.organizationId }),
42427
+ (values) => values.length > 0
42428
+ );
42429
+ }
42330
42430
  return readValues(record_id);
42331
42431
  },
42332
42432
  async revisions({ record_id }) {
@@ -42336,7 +42436,7 @@ function createRecordsClient(config) {
42336
42436
  "revisions"
42337
42437
  );
42338
42438
  },
42339
- async recordScopeContext({ record_id, relations, history, siblings }) {
42439
+ async recordScopeContext({ record_id, relations, history, siblings: siblings2 }) {
42340
42440
  return callDoor(
42341
42441
  DOORS.recordScopeContext,
42342
42442
  {
@@ -42344,7 +42444,7 @@ function createRecordsClient(config) {
42344
42444
  p_record_id: record_id,
42345
42445
  p_relations: relations ?? 12,
42346
42446
  p_history: history ?? 15,
42347
- p_siblings: siblings ?? 8
42447
+ p_siblings: siblings2 ?? 8
42348
42448
  },
42349
42449
  "recordScopeContext"
42350
42450
  );
@@ -42374,7 +42474,7 @@ function createRecordsClient(config) {
42374
42474
  "conversationScopeUnbind"
42375
42475
  );
42376
42476
  },
42377
- async conversationScopeContext({ conversation_id, relations, history, siblings }) {
42477
+ async conversationScopeContext({ conversation_id, relations, history, siblings: siblings2 }) {
42378
42478
  return callDoor(
42379
42479
  DOORS.conversationScopeContext,
42380
42480
  {
@@ -42382,7 +42482,7 @@ function createRecordsClient(config) {
42382
42482
  p_conversation_id: conversation_id,
42383
42483
  p_relations: relations ?? 12,
42384
42484
  p_history: history ?? 15,
42385
- p_siblings: siblings ?? 8
42485
+ p_siblings: siblings2 ?? 8
42386
42486
  },
42387
42487
  "conversationScopeContext"
42388
42488
  );