ofsync-bridge-ofpos 0.1.0-alpha.0 → 0.1.0-alpha.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.esm.js CHANGED
@@ -1 +1 @@
1
- import{POS_DOMAIN_TABLES as C}from"ofpos-shared-core";const p="ofpos";function I(t){if(!t||typeof t!="object")return null;const n=t;return typeof n.applyRemoteChanges=="function"||typeof n.collectLocalChanges=="function"||typeof n.domain=="string"&&n.domain.trim().length>0?n:null}const B=t=>{const n=t instanceof Set?t:new Set(t);return e=>e.startsWith("ofpos_")||e.startsWith("ofauth_")||e.startsWith("ofsync_")||e.startsWith("__")?e:n.has(e)?`ofpos_${e}`:e};function D(t){const n=new Set;for(const e of t){const o=e.payload,r=String(o.table??e.entity??"");if(r!=="inventory_logs"&&r!=="ofpos_inventory_logs")continue;const g=o.record&&typeof o.record=="object"?o.record:{},c=String(g.productId??"");c&&n.add(c)}return[...n]}function w(t){const{dbAdapter:n,onChangesApplied:e,defaultBranchId:o,inventoryCacheInvalidator:r}=t,g=B(C);return{domain:p,collectLocalChanges:async()=>[],applyRemoteChanges:async(c,l)=>{const y=l.branchId||o||"",f=l.tenantId;for(const i of c){const d=i.payload,S=String(d.table??i.entity??""),h=d.record&&typeof d.record=="object"?d.record:{},a=String(i.recordId??h.id??"");if(!S||!a)continue;const s=g(S);if(i.type==="DELETE"){try{await n.delete(s,a)}catch{}continue}const u={...h,id:a,branchId:y,...f?{tenantId:f}:{}},m=await n.query(s,{filters:{and:[{field:"id",value:a},{field:"branchId",value:y}]},limit:1});(m.length>0?m:await n.query(s,{filters:{id:a},limit:1})).length>0?await n.update(s,a,u):await n.create(s,u)}if(r){const i=D(c);i.length>0&&typeof r.invalidateProductsStock=="function"?await r.invalidateProductsStock(i):typeof r.clearStockCache=="function"&&await r.clearStockCache()}e&&await e(c)}}}function R(t,n){const e=I(n);if(e){t.registerDomainBridge({domain:e.domain||p,collectLocalChanges:e.collectLocalChanges,applyRemoteChanges:e.applyRemoteChanges});return}const o=n;t.registerDomainBridge({domain:p,collectLocalChanges:o.collectSyncChanges,applyRemoteChanges:o.applySyncChanges})}export{p as BRIDGE_DOMAIN,w as createPosSyncBridge,B as createPosTableNameMapper,R as registerSyncBridge};
1
+ import{POS_DOMAIN_TABLES as m}from"ofpos-shared-core";const p="ofpos";function C(t){if(!t||typeof t!="object")return null;const n=t;return typeof n.applyRemoteChanges=="function"||typeof n.collectLocalChanges=="function"||typeof n.domain=="string"&&n.domain.trim().length>0?n:null}const I=t=>{const n=t instanceof Set?t:new Set(t);return e=>e.startsWith("ofpos_")||e.startsWith("ofauth_")||e.startsWith("ofsync_")||e.startsWith("__")?e:n.has(e)?`ofpos_${e}`:e};function B(t){const n=new Set;for(const e of t){const o=e.payload,r=String(o.table??e.entity??"");if(r!=="inventory_logs"&&r!=="ofpos_inventory_logs")continue;const g=o.record&&typeof o.record=="object"?o.record:{},c=String(g.productId??"");c&&n.add(c)}return[...n]}function v(t){const{dbAdapter:n,onChangesApplied:e,defaultBranchId:o,inventoryCacheInvalidator:r}=t,g=I(m);return{domain:p,collectLocalChanges:async()=>[],applyRemoteChanges:async(c,l)=>{const y=l.branchId||o||"",f=l.tenantId;for(const i of c){const s=i.payload,S=String(s.table??i.entity??""),h=s.record&&typeof s.record=="object"?s.record:{},a=String(i.recordId??h.id??"");if(!S||!a)continue;const d=g(S);if(i.type==="DELETE"){try{await n.delete(d,a)}catch{}continue}const u={...h,id:a,branchId:y,...f?{tenantId:f}:{}};(await n.query(d,{filters:{and:[{field:"id",value:a},{field:"branchId",value:y}]},limit:1})).length>0?await n.update(d,a,u):await n.create(d,u)}if(r){const i=B(c);i.length>0&&typeof r.invalidateProductsStock=="function"?await r.invalidateProductsStock(i):typeof r.clearStockCache=="function"&&await r.clearStockCache()}e&&await e(c)}}}function w(t,n){const e=C(n);if(e){t.registerDomainBridge({domain:e.domain||p,collectLocalChanges:e.collectLocalChanges,applyRemoteChanges:e.applyRemoteChanges});return}const o=n;t.registerDomainBridge({domain:p,collectLocalChanges:o.collectSyncChanges,applyRemoteChanges:o.applySyncChanges})}export{p as BRIDGE_DOMAIN,v as createPosSyncBridge,I as createPosTableNameMapper,w as registerSyncBridge};
package/dist/index.js CHANGED
@@ -92,19 +92,11 @@ function createPosSyncBridge(options) {
92
92
  branchId,
93
93
  ...(tenantId ? { tenantId } : {}),
94
94
  };
95
- // Prefer scoped lookup first.
96
95
  const existingScoped = await dbAdapter.query(tableName, {
97
96
  filters: { and: [{ field: 'id', value: recordId }, { field: 'branchId', value: branchId }] },
98
97
  limit: 1,
99
98
  });
100
- // Fallback for legacy local rows that may exist with stale/missing scope.
101
- const existingAnyScope = existingScoped.length > 0
102
- ? existingScoped
103
- : await dbAdapter.query(tableName, {
104
- filters: { id: recordId },
105
- limit: 1,
106
- });
107
- if (existingAnyScope.length > 0) {
99
+ if (existingScoped.length > 0) {
108
100
  await dbAdapter.update(tableName, recordId, upsertPayload);
109
101
  }
110
102
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ofsync-bridge-ofpos",
3
- "version": "0.1.0-alpha.0",
3
+ "version": "0.1.0-alpha.2",
4
4
  "private": false,
5
5
  "description": "Sync bridge adapter for wiring ofpos domain changes into ofsync-shared-core runtime.",
6
6
  "author": {
@@ -32,7 +32,7 @@
32
32
  "prepack": "npm run build"
33
33
  },
34
34
  "devDependencies": {
35
- "ofpos-shared-core": "2.0.0-alpha.0",
35
+ "ofpos-shared-core": "2.0.0-alpha.1",
36
36
  "esbuild": "^0.25.11",
37
37
  "typescript": "^5.9.3",
38
38
  "@types/node": "^20.19.0"
@@ -41,8 +41,8 @@
41
41
  "access": "public"
42
42
  },
43
43
  "peerDependencies": {
44
- "ofsync-shared-core": "0.2.0-alpha.1",
45
- "ofpos-shared-core": "2.0.0-alpha.0"
44
+ "ofsync-shared-core": "0.2.0-alpha.2",
45
+ "ofpos-shared-core": "2.0.0-alpha.1"
46
46
  },
47
47
  "peerDependenciesMeta": {
48
48
  "ofsync-shared-core": {