@fctc/interface-logic 4.3.2 → 4.3.4
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/hooks.js +766 -550
- package/dist/hooks.mjs +766 -550
- package/dist/provider.js +766 -550
- package/dist/provider.mjs +766 -550
- package/dist/services.js +766 -550
- package/dist/services.mjs +766 -550
- package/dist/utils.d.mts +2 -1
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +9 -0
- package/dist/utils.mjs +8 -0
- package/package.json +1 -1
package/dist/hooks.js
CHANGED
|
@@ -2351,6 +2351,13 @@ function cleanObject(obj) {
|
|
|
2351
2351
|
}
|
|
2352
2352
|
return result;
|
|
2353
2353
|
}
|
|
2354
|
+
var extractIdFromDomain = (domain) => {
|
|
2355
|
+
if (!domain || !Array.isArray(domain)) return null;
|
|
2356
|
+
const idCond = domain.find(
|
|
2357
|
+
([field, operator]) => field === "id" && operator === "="
|
|
2358
|
+
);
|
|
2359
|
+
return idCond ? Number(idCond[2]) : null;
|
|
2360
|
+
};
|
|
2354
2361
|
|
|
2355
2362
|
// src/provider/react-query-provider.tsx
|
|
2356
2363
|
var import_react2 = require("react");
|
|
@@ -5226,116 +5233,638 @@ var getASessionService = (env) => {
|
|
|
5226
5233
|
|
|
5227
5234
|
// src/services/pos-service/add-entity.ts
|
|
5228
5235
|
var import_react18 = require("react");
|
|
5229
|
-
var addEntityService = (env) => {
|
|
5230
|
-
const addEntity = (0, import_react18.useCallback)(
|
|
5231
|
-
({
|
|
5232
|
-
model,
|
|
5233
|
-
values,
|
|
5234
|
-
xNode,
|
|
5235
|
-
service,
|
|
5236
|
-
isCreateEndpoint = false
|
|
5237
|
-
}) => {
|
|
5238
|
-
const jsonData = {
|
|
5239
|
-
model,
|
|
5240
|
-
values
|
|
5241
|
-
};
|
|
5242
|
-
return env?.requests.post(
|
|
5243
|
-
isCreateEndpoint ? "/create" /* CREATE_PATH */ : "/call" /* CALL_PATH */,
|
|
5244
|
-
jsonData,
|
|
5245
|
-
{
|
|
5246
|
-
headers: {
|
|
5247
|
-
"Content-Type": "application/json",
|
|
5248
|
-
...xNode ? { "X-Node": xNode } : {}
|
|
5249
|
-
}
|
|
5250
|
-
},
|
|
5251
|
-
service
|
|
5252
|
-
);
|
|
5253
|
-
},
|
|
5254
|
-
[env]
|
|
5255
|
-
);
|
|
5256
|
-
return {
|
|
5257
|
-
addEntity
|
|
5258
|
-
};
|
|
5259
|
-
};
|
|
5260
5236
|
|
|
5261
|
-
// src/services/
|
|
5262
|
-
var
|
|
5263
|
-
var
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
|
|
5271
|
-
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
|
|
5275
|
-
|
|
5276
|
-
|
|
5277
|
-
|
|
5278
|
-
|
|
5279
|
-
|
|
5280
|
-
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
|
|
5297
|
-
|
|
5237
|
+
// src/services/filesystem-service/file-service.ts
|
|
5238
|
+
var import_filesystem = require("@capacitor/filesystem");
|
|
5239
|
+
var fileService = {
|
|
5240
|
+
read: async (path) => {
|
|
5241
|
+
try {
|
|
5242
|
+
const res = await import_filesystem.Filesystem.readFile({
|
|
5243
|
+
path,
|
|
5244
|
+
directory: import_filesystem.Directory.Data,
|
|
5245
|
+
encoding: import_filesystem.Encoding.UTF8
|
|
5246
|
+
});
|
|
5247
|
+
if (typeof res.data === "string") return res.data;
|
|
5248
|
+
if (res.data instanceof Blob) return await res.data.text();
|
|
5249
|
+
return null;
|
|
5250
|
+
} catch {
|
|
5251
|
+
return null;
|
|
5252
|
+
}
|
|
5253
|
+
},
|
|
5254
|
+
write: async (path, data) => {
|
|
5255
|
+
await import_filesystem.Filesystem.writeFile({
|
|
5256
|
+
path,
|
|
5257
|
+
data,
|
|
5258
|
+
directory: import_filesystem.Directory.Data,
|
|
5259
|
+
encoding: import_filesystem.Encoding.UTF8,
|
|
5260
|
+
recursive: true
|
|
5261
|
+
});
|
|
5262
|
+
},
|
|
5263
|
+
writeAtomic: async (path, data) => {
|
|
5264
|
+
const tempPath = path + ".tmp";
|
|
5265
|
+
await import_filesystem.Filesystem.writeFile({
|
|
5266
|
+
path: tempPath,
|
|
5267
|
+
data,
|
|
5268
|
+
directory: import_filesystem.Directory.Data,
|
|
5269
|
+
encoding: import_filesystem.Encoding.UTF8,
|
|
5270
|
+
recursive: true
|
|
5271
|
+
});
|
|
5272
|
+
try {
|
|
5273
|
+
await import_filesystem.Filesystem.deleteFile({
|
|
5274
|
+
path,
|
|
5275
|
+
directory: import_filesystem.Directory.Data
|
|
5276
|
+
});
|
|
5277
|
+
} catch {
|
|
5278
|
+
}
|
|
5279
|
+
await import_filesystem.Filesystem.rename({
|
|
5280
|
+
from: tempPath,
|
|
5281
|
+
to: path,
|
|
5282
|
+
directory: import_filesystem.Directory.Data
|
|
5283
|
+
});
|
|
5284
|
+
},
|
|
5285
|
+
delete: async (path) => {
|
|
5286
|
+
try {
|
|
5287
|
+
await import_filesystem.Filesystem.deleteFile({
|
|
5288
|
+
path,
|
|
5289
|
+
directory: import_filesystem.Directory.Data
|
|
5290
|
+
});
|
|
5291
|
+
} catch {
|
|
5292
|
+
}
|
|
5293
|
+
},
|
|
5294
|
+
exists: async (path) => {
|
|
5295
|
+
try {
|
|
5296
|
+
await import_filesystem.Filesystem.stat({
|
|
5297
|
+
path,
|
|
5298
|
+
directory: import_filesystem.Directory.Data
|
|
5299
|
+
});
|
|
5300
|
+
return true;
|
|
5301
|
+
} catch {
|
|
5302
|
+
return false;
|
|
5303
|
+
}
|
|
5304
|
+
},
|
|
5305
|
+
mkdir: async (path) => {
|
|
5306
|
+
try {
|
|
5307
|
+
await import_filesystem.Filesystem.mkdir({
|
|
5308
|
+
path,
|
|
5309
|
+
directory: import_filesystem.Directory.Data,
|
|
5310
|
+
recursive: true
|
|
5311
|
+
});
|
|
5312
|
+
} catch (e) {
|
|
5313
|
+
if (!String(e?.message).includes("Exists")) {
|
|
5314
|
+
throw e;
|
|
5315
|
+
}
|
|
5316
|
+
}
|
|
5317
|
+
},
|
|
5318
|
+
list: async (path) => {
|
|
5319
|
+
return import_filesystem.Filesystem.readdir({
|
|
5320
|
+
path,
|
|
5321
|
+
directory: import_filesystem.Directory.Data
|
|
5322
|
+
});
|
|
5323
|
+
},
|
|
5324
|
+
getUri: async (path) => {
|
|
5325
|
+
return import_filesystem.Filesystem.getUri({
|
|
5326
|
+
path,
|
|
5327
|
+
directory: import_filesystem.Directory.Data
|
|
5328
|
+
});
|
|
5329
|
+
}
|
|
5298
5330
|
};
|
|
5299
5331
|
|
|
5300
|
-
// src/services/
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
5317
|
-
|
|
5318
|
-
|
|
5319
|
-
|
|
5320
|
-
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
|
|
5324
|
-
|
|
5325
|
-
|
|
5326
|
-
|
|
5327
|
-
|
|
5328
|
-
|
|
5329
|
-
|
|
5330
|
-
|
|
5331
|
-
|
|
5332
|
-
|
|
5333
|
-
|
|
5334
|
-
|
|
5332
|
+
// src/services/filesystem-service/json-worker.ts
|
|
5333
|
+
function createWorkerBlob() {
|
|
5334
|
+
const workerCode = `
|
|
5335
|
+
self.addEventListener("message", async (ev) => {
|
|
5336
|
+
const { id, cmd, payload } = ev.data;
|
|
5337
|
+
try {
|
|
5338
|
+
if (cmd === "parse") {
|
|
5339
|
+
const parsed = JSON.parse(payload);
|
|
5340
|
+
self.postMessage({ id, ok: true, result: parsed });
|
|
5341
|
+
} else if (cmd === "stringify") {
|
|
5342
|
+
const str = JSON.stringify(payload);
|
|
5343
|
+
self.postMessage({ id, ok: true, result: str });
|
|
5344
|
+
}
|
|
5345
|
+
} catch (err) {
|
|
5346
|
+
self.postMessage({ id, ok: false, error: err?.message || String(err) });
|
|
5347
|
+
}
|
|
5348
|
+
});
|
|
5349
|
+
`;
|
|
5350
|
+
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
5351
|
+
return URL.createObjectURL(blob);
|
|
5352
|
+
}
|
|
5353
|
+
function spawnParseWorker(raw) {
|
|
5354
|
+
return new Promise((resolve, reject) => {
|
|
5355
|
+
const workerUrl = createWorkerBlob();
|
|
5356
|
+
const worker = new Worker(workerUrl);
|
|
5357
|
+
const id = Math.random().toString(36).slice(2);
|
|
5358
|
+
worker.onmessage = (ev) => {
|
|
5359
|
+
const { ok, result, error } = ev.data;
|
|
5360
|
+
if (ok) {
|
|
5361
|
+
resolve(result);
|
|
5362
|
+
} else {
|
|
5363
|
+
reject(new Error(error));
|
|
5364
|
+
}
|
|
5365
|
+
URL.revokeObjectURL(workerUrl);
|
|
5366
|
+
worker.terminate();
|
|
5367
|
+
};
|
|
5368
|
+
worker.onerror = (err) => {
|
|
5369
|
+
reject(err);
|
|
5370
|
+
URL.revokeObjectURL(workerUrl);
|
|
5371
|
+
worker.terminate();
|
|
5372
|
+
};
|
|
5373
|
+
worker.postMessage({ id, cmd: "parse", payload: raw });
|
|
5374
|
+
});
|
|
5375
|
+
}
|
|
5376
|
+
function spawnStringifyWorker(obj) {
|
|
5377
|
+
return new Promise((resolve, reject) => {
|
|
5378
|
+
const workerUrl = createWorkerBlob();
|
|
5379
|
+
const worker = new Worker(workerUrl);
|
|
5380
|
+
worker.onmessage = (ev) => {
|
|
5381
|
+
const { ok, result, error } = ev.data;
|
|
5382
|
+
if (ok) resolve(result);
|
|
5383
|
+
else reject(new Error(error));
|
|
5384
|
+
URL.revokeObjectURL(workerUrl);
|
|
5385
|
+
worker.terminate();
|
|
5386
|
+
};
|
|
5387
|
+
worker.onerror = (err) => {
|
|
5388
|
+
reject(err);
|
|
5389
|
+
URL.revokeObjectURL(workerUrl);
|
|
5390
|
+
worker.terminate();
|
|
5391
|
+
};
|
|
5392
|
+
worker.postMessage({ cmd: "stringify", payload: obj });
|
|
5393
|
+
});
|
|
5394
|
+
}
|
|
5335
5395
|
|
|
5336
|
-
// src/services/
|
|
5337
|
-
var
|
|
5338
|
-
var
|
|
5396
|
+
// src/services/filesystem-service/manifest.ts
|
|
5397
|
+
var MANIFEST_PATH = "pos/manifest.json";
|
|
5398
|
+
var MANIFEST_BAK_PATH = "pos/manifest.bak.json";
|
|
5399
|
+
async function writeManifest(manifest) {
|
|
5400
|
+
const oldRaw = await fileService.read(MANIFEST_PATH);
|
|
5401
|
+
if (oldRaw !== null) {
|
|
5402
|
+
await fileService.writeAtomic(MANIFEST_BAK_PATH, oldRaw);
|
|
5403
|
+
}
|
|
5404
|
+
await fileService.writeAtomic(MANIFEST_PATH, JSON.stringify(manifest));
|
|
5405
|
+
try {
|
|
5406
|
+
await fileService.delete(MANIFEST_BAK_PATH);
|
|
5407
|
+
} catch {
|
|
5408
|
+
}
|
|
5409
|
+
}
|
|
5410
|
+
|
|
5411
|
+
// src/services/filesystem-service/import-snapshot.ts
|
|
5412
|
+
var DATA_DIR = "pos";
|
|
5413
|
+
var MODELS_DIR = `${DATA_DIR}/models`;
|
|
5414
|
+
var MODELS_META_DIR = `${DATA_DIR}/models_meta`;
|
|
5415
|
+
var importSnapshot = async ({ data, onProgress }) => {
|
|
5416
|
+
onProgress?.(1, "Parsing snapshot");
|
|
5417
|
+
const parsed = await spawnParseWorker(data);
|
|
5418
|
+
const modelNames = Object.keys(parsed);
|
|
5419
|
+
const total = modelNames.length;
|
|
5420
|
+
const manifest = { version: (/* @__PURE__ */ new Date()).toISOString(), models: {} };
|
|
5421
|
+
const TMP_PREFIX = `pos/data/tmp_import_${Date.now()}`;
|
|
5422
|
+
await fileService.writeAtomic(`${TMP_PREFIX}/.marker`, "1");
|
|
5423
|
+
let i = 0;
|
|
5424
|
+
for (const model of modelNames) {
|
|
5425
|
+
i++;
|
|
5426
|
+
onProgress?.(
|
|
5427
|
+
Math.round(i / total * 100),
|
|
5428
|
+
`Processing ${model} (${i}/${total})`
|
|
5429
|
+
);
|
|
5430
|
+
const block = parsed[model];
|
|
5431
|
+
const dataPart = block?.data ?? block ?? [];
|
|
5432
|
+
const fields = block?.fields ?? [];
|
|
5433
|
+
const relations = block?.relations ?? {};
|
|
5434
|
+
const serialized = await spawnStringifyWorker(dataPart);
|
|
5435
|
+
const tmpModelPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.json`;
|
|
5436
|
+
await fileService.writeAtomic(tmpModelPath, serialized);
|
|
5437
|
+
const meta = {
|
|
5438
|
+
fields,
|
|
5439
|
+
relations,
|
|
5440
|
+
count: Array.isArray(dataPart) ? dataPart.length : 0,
|
|
5441
|
+
writtenAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
5442
|
+
};
|
|
5443
|
+
const tmpMetaPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`;
|
|
5444
|
+
await fileService.writeAtomic(tmpMetaPath, JSON.stringify(meta));
|
|
5445
|
+
manifest.models[model] = {
|
|
5446
|
+
file: `${MODELS_DIR}/${encodeURIComponent(model)}.json`,
|
|
5447
|
+
metaFile: `${MODELS_META_DIR}/${encodeURIComponent(model)}.meta.json`,
|
|
5448
|
+
count: meta.count,
|
|
5449
|
+
updatedAt: meta.writtenAt
|
|
5450
|
+
};
|
|
5451
|
+
}
|
|
5452
|
+
onProgress?.(95, "Committing import (moving files)");
|
|
5453
|
+
for (const model of modelNames) {
|
|
5454
|
+
const tmpModelPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.json`;
|
|
5455
|
+
const finalModelPath = `${MODELS_DIR}/${encodeURIComponent(model)}.json`;
|
|
5456
|
+
const tmpMetaPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`;
|
|
5457
|
+
const finalMetaPath = `${MODELS_META_DIR}/${encodeURIComponent(
|
|
5458
|
+
model
|
|
5459
|
+
)}.meta.json`;
|
|
5460
|
+
const tmpRaw = await fileService.read(tmpModelPath);
|
|
5461
|
+
if (tmpRaw !== null) await fileService.writeAtomic(finalModelPath, tmpRaw);
|
|
5462
|
+
const tmpMetaRaw = await fileService.read(tmpMetaPath);
|
|
5463
|
+
if (tmpMetaRaw !== null)
|
|
5464
|
+
await fileService.writeAtomic(finalMetaPath, tmpMetaRaw);
|
|
5465
|
+
onProgress?.(
|
|
5466
|
+
95 + Math.round(
|
|
5467
|
+
(Object.keys(manifest.models).indexOf(model) + 1) / modelNames.length * 5
|
|
5468
|
+
),
|
|
5469
|
+
`Committed ${model}`
|
|
5470
|
+
);
|
|
5471
|
+
}
|
|
5472
|
+
await writeManifest(manifest);
|
|
5473
|
+
try {
|
|
5474
|
+
for (const model of modelNames) {
|
|
5475
|
+
await fileService.delete(
|
|
5476
|
+
`${TMP_PREFIX}/${encodeURIComponent(model)}.json`
|
|
5477
|
+
);
|
|
5478
|
+
await fileService.delete(
|
|
5479
|
+
`${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`
|
|
5480
|
+
);
|
|
5481
|
+
}
|
|
5482
|
+
await fileService.delete(`${TMP_PREFIX}/.marker`);
|
|
5483
|
+
} catch (e) {
|
|
5484
|
+
console.log("Failed to cleanup tmp import files:", e);
|
|
5485
|
+
}
|
|
5486
|
+
onProgress?.(100, "Import complete");
|
|
5487
|
+
return manifest;
|
|
5488
|
+
};
|
|
5489
|
+
var import_snapshot_default = importSnapshot;
|
|
5490
|
+
|
|
5491
|
+
// src/services/filesystem-service/memory-cache.ts
|
|
5492
|
+
var MemoryCache = class {
|
|
5493
|
+
map = /* @__PURE__ */ new Map();
|
|
5494
|
+
get(k) {
|
|
5495
|
+
const e = this.map.get(k);
|
|
5496
|
+
if (!e) return null;
|
|
5497
|
+
if (e.ttl && Date.now() - e.t > e.ttl) {
|
|
5498
|
+
this.map.delete(k);
|
|
5499
|
+
return null;
|
|
5500
|
+
}
|
|
5501
|
+
return e.value;
|
|
5502
|
+
}
|
|
5503
|
+
set(k, v, ttl = 5 * 60 * 1e3) {
|
|
5504
|
+
this.map.set(k, { value: v, t: Date.now(), ttl });
|
|
5505
|
+
}
|
|
5506
|
+
del(k) {
|
|
5507
|
+
this.map.delete(k);
|
|
5508
|
+
}
|
|
5509
|
+
clear() {
|
|
5510
|
+
this.map.clear();
|
|
5511
|
+
}
|
|
5512
|
+
};
|
|
5513
|
+
var memoryCache = new MemoryCache();
|
|
5514
|
+
|
|
5515
|
+
// src/services/filesystem-service/model-loader.ts
|
|
5516
|
+
var MODELS_DIR2 = "pos/models";
|
|
5517
|
+
var MODELS_META_DIR2 = "pos/models_meta";
|
|
5518
|
+
async function loadModelData(modelName, includeMeta = true) {
|
|
5519
|
+
const key = `model:${modelName}:meta:${includeMeta}`;
|
|
5520
|
+
const cached = memoryCache.get(key);
|
|
5521
|
+
if (cached) return cached;
|
|
5522
|
+
const dataPath = `${MODELS_DIR2}/${encodeURIComponent(modelName)}.json`;
|
|
5523
|
+
const metaPath = `${MODELS_META_DIR2}/${encodeURIComponent(
|
|
5524
|
+
modelName
|
|
5525
|
+
)}.meta.json`;
|
|
5526
|
+
const rawData = await fileService.read(dataPath);
|
|
5527
|
+
if (!rawData) return null;
|
|
5528
|
+
const parsedData = await spawnParseWorker(rawData);
|
|
5529
|
+
const data = Array.isArray(parsedData) ? parsedData : [];
|
|
5530
|
+
if (!includeMeta) {
|
|
5531
|
+
const result2 = { data };
|
|
5532
|
+
memoryCache.set(key, result2, 1e3 * 60 * 60);
|
|
5533
|
+
return result2;
|
|
5534
|
+
}
|
|
5535
|
+
const rawMeta = await fileService.read(metaPath);
|
|
5536
|
+
let fields = [];
|
|
5537
|
+
let relations = {};
|
|
5538
|
+
if (rawMeta) {
|
|
5539
|
+
const parsedMeta = await spawnParseWorker(rawMeta);
|
|
5540
|
+
fields = parsedMeta?.fields ?? [];
|
|
5541
|
+
relations = parsedMeta?.relations ?? {};
|
|
5542
|
+
}
|
|
5543
|
+
const result = {
|
|
5544
|
+
data,
|
|
5545
|
+
fields,
|
|
5546
|
+
relations
|
|
5547
|
+
};
|
|
5548
|
+
memoryCache.set(key, result, 1e3 * 60 * 60);
|
|
5549
|
+
return result;
|
|
5550
|
+
}
|
|
5551
|
+
async function loadData(includeMeta = true) {
|
|
5552
|
+
try {
|
|
5553
|
+
const listResult = await fileService.list(MODELS_DIR2);
|
|
5554
|
+
if (!listResult || !Array.isArray(listResult.files)) {
|
|
5555
|
+
console.log("No models found");
|
|
5556
|
+
return {};
|
|
5557
|
+
}
|
|
5558
|
+
const result = {};
|
|
5559
|
+
for (const file of listResult.files) {
|
|
5560
|
+
if (file.type !== "file") continue;
|
|
5561
|
+
if (!file.name.endsWith(".json")) continue;
|
|
5562
|
+
const fileName = file.name;
|
|
5563
|
+
const modelName = fileName.replace(/\.json$/, "");
|
|
5564
|
+
const dataPath = `${MODELS_DIR2}/${fileName}`;
|
|
5565
|
+
const rawData = await fileService.read(dataPath);
|
|
5566
|
+
if (!rawData) continue;
|
|
5567
|
+
const parsedData = await spawnParseWorker(rawData);
|
|
5568
|
+
const data = Array.isArray(parsedData) ? parsedData : [];
|
|
5569
|
+
if (!includeMeta) {
|
|
5570
|
+
result[modelName] = { data };
|
|
5571
|
+
continue;
|
|
5572
|
+
}
|
|
5573
|
+
const metaPath = `${MODELS_META_DIR2}/${encodeURIComponent(
|
|
5574
|
+
modelName
|
|
5575
|
+
)}.meta.json`;
|
|
5576
|
+
const rawMeta = await fileService.read(metaPath);
|
|
5577
|
+
let fields = [];
|
|
5578
|
+
let relations = {};
|
|
5579
|
+
if (rawMeta) {
|
|
5580
|
+
const parsedMeta = await spawnParseWorker(rawMeta);
|
|
5581
|
+
fields = parsedMeta?.fields ?? [];
|
|
5582
|
+
relations = parsedMeta?.relations ?? {};
|
|
5583
|
+
}
|
|
5584
|
+
result[modelName] = {
|
|
5585
|
+
data,
|
|
5586
|
+
fields,
|
|
5587
|
+
relations
|
|
5588
|
+
};
|
|
5589
|
+
}
|
|
5590
|
+
return result;
|
|
5591
|
+
} catch (error) {
|
|
5592
|
+
console.error("Error loading data:", error);
|
|
5593
|
+
throw error;
|
|
5594
|
+
}
|
|
5595
|
+
}
|
|
5596
|
+
|
|
5597
|
+
// src/services/filesystem-service/snapshot-helper.ts
|
|
5598
|
+
var createEmptySnapshot = () => {
|
|
5599
|
+
return {
|
|
5600
|
+
data: []
|
|
5601
|
+
};
|
|
5602
|
+
};
|
|
5603
|
+
var generateNextId = (existingIds, startFrom = 1) => {
|
|
5604
|
+
if (!existingIds || existingIds.length === 0) {
|
|
5605
|
+
return startFrom;
|
|
5606
|
+
}
|
|
5607
|
+
const maxId = Math.max(...existingIds, startFrom - 1);
|
|
5608
|
+
return maxId + 1;
|
|
5609
|
+
};
|
|
5610
|
+
var loadSnapshot = async ({
|
|
5611
|
+
modelName
|
|
5612
|
+
}) => {
|
|
5613
|
+
try {
|
|
5614
|
+
const snapshot = await loadModelData(modelName);
|
|
5615
|
+
if (!snapshot || typeof snapshot !== "object") {
|
|
5616
|
+
console.warn("invalid snapshot, creating new one");
|
|
5617
|
+
return createEmptySnapshot();
|
|
5618
|
+
}
|
|
5619
|
+
return {
|
|
5620
|
+
data: Array.isArray(snapshot.data) ? snapshot.data : []
|
|
5621
|
+
};
|
|
5622
|
+
} catch (error) {
|
|
5623
|
+
console.error("Failed to load snapshot:", error);
|
|
5624
|
+
return createEmptySnapshot();
|
|
5625
|
+
}
|
|
5626
|
+
};
|
|
5627
|
+
var getExistingIds = (snapshot) => {
|
|
5628
|
+
return snapshot.data.map((order) => order.id).filter((id) => typeof id === "number");
|
|
5629
|
+
};
|
|
5630
|
+
var saveSnapshot = async ({
|
|
5631
|
+
snapshot,
|
|
5632
|
+
modelName
|
|
5633
|
+
}) => {
|
|
5634
|
+
try {
|
|
5635
|
+
await import_snapshot_default({
|
|
5636
|
+
data: JSON.stringify({
|
|
5637
|
+
[modelName]: snapshot
|
|
5638
|
+
})
|
|
5639
|
+
});
|
|
5640
|
+
return true;
|
|
5641
|
+
} catch (error) {
|
|
5642
|
+
console.error("failed to save snapshot:", error);
|
|
5643
|
+
return false;
|
|
5644
|
+
}
|
|
5645
|
+
};
|
|
5646
|
+
|
|
5647
|
+
// src/services/filesystem-service/model-repository.ts
|
|
5648
|
+
var ModelRepository = class {
|
|
5649
|
+
getRecord = async ({
|
|
5650
|
+
id,
|
|
5651
|
+
modelName
|
|
5652
|
+
}) => {
|
|
5653
|
+
try {
|
|
5654
|
+
const snapshot = await loadSnapshot({
|
|
5655
|
+
modelName
|
|
5656
|
+
});
|
|
5657
|
+
return snapshot.data.find((record) => record.id === id) || null;
|
|
5658
|
+
} catch (error) {
|
|
5659
|
+
console.error("failed to get record:", error);
|
|
5660
|
+
return null;
|
|
5661
|
+
}
|
|
5662
|
+
};
|
|
5663
|
+
addRecord = async ({
|
|
5664
|
+
newRecord,
|
|
5665
|
+
modelName
|
|
5666
|
+
}) => {
|
|
5667
|
+
try {
|
|
5668
|
+
const snapshot = await loadSnapshot({
|
|
5669
|
+
modelName
|
|
5670
|
+
});
|
|
5671
|
+
console.log("modelName", modelName);
|
|
5672
|
+
console.log("snapshot", snapshot);
|
|
5673
|
+
const existingIds = getExistingIds(snapshot);
|
|
5674
|
+
console.log("existingIds", existingIds);
|
|
5675
|
+
const newId = generateNextId(existingIds, snapshot.data.length);
|
|
5676
|
+
console.log("newId", newId);
|
|
5677
|
+
snapshot.data.push({
|
|
5678
|
+
...newRecord,
|
|
5679
|
+
id: newId
|
|
5680
|
+
});
|
|
5681
|
+
const saved = await saveSnapshot({
|
|
5682
|
+
snapshot,
|
|
5683
|
+
modelName
|
|
5684
|
+
});
|
|
5685
|
+
if (!saved) {
|
|
5686
|
+
console.error("failed to add new record");
|
|
5687
|
+
return [];
|
|
5688
|
+
}
|
|
5689
|
+
console.log(`\u2705 ${snapshot.data.length} records saved`);
|
|
5690
|
+
console.log(snapshot.data);
|
|
5691
|
+
return snapshot.data;
|
|
5692
|
+
} catch (error) {
|
|
5693
|
+
console.error("failed to add new record:", error);
|
|
5694
|
+
return [];
|
|
5695
|
+
}
|
|
5696
|
+
};
|
|
5697
|
+
updateRecord = async ({
|
|
5698
|
+
id,
|
|
5699
|
+
update,
|
|
5700
|
+
modelName
|
|
5701
|
+
}) => {
|
|
5702
|
+
try {
|
|
5703
|
+
const snapshot = await loadSnapshot({
|
|
5704
|
+
modelName
|
|
5705
|
+
});
|
|
5706
|
+
const index = snapshot.data.findIndex((record) => record.id === id);
|
|
5707
|
+
if (index === -1) {
|
|
5708
|
+
console.error(`record with id ${id} not found`);
|
|
5709
|
+
return false;
|
|
5710
|
+
}
|
|
5711
|
+
snapshot.data[index] = {
|
|
5712
|
+
...snapshot.data[index],
|
|
5713
|
+
...update
|
|
5714
|
+
};
|
|
5715
|
+
return await saveSnapshot({
|
|
5716
|
+
snapshot,
|
|
5717
|
+
modelName
|
|
5718
|
+
});
|
|
5719
|
+
} catch (error) {
|
|
5720
|
+
console.error("error updating record:", error);
|
|
5721
|
+
return false;
|
|
5722
|
+
}
|
|
5723
|
+
};
|
|
5724
|
+
deleteRecord = async ({
|
|
5725
|
+
id,
|
|
5726
|
+
modelName
|
|
5727
|
+
}) => {
|
|
5728
|
+
try {
|
|
5729
|
+
const snapshot = await loadSnapshot({
|
|
5730
|
+
modelName
|
|
5731
|
+
});
|
|
5732
|
+
const before = snapshot.data.length;
|
|
5733
|
+
snapshot.data = snapshot.data.filter((record) => record.id !== id);
|
|
5734
|
+
if (snapshot.data.length === before) {
|
|
5735
|
+
console.error(`record with id ${id} not found`);
|
|
5736
|
+
return false;
|
|
5737
|
+
}
|
|
5738
|
+
return await saveSnapshot({
|
|
5739
|
+
snapshot,
|
|
5740
|
+
modelName
|
|
5741
|
+
});
|
|
5742
|
+
} catch (error) {
|
|
5743
|
+
console.error("error deleting record:", error);
|
|
5744
|
+
return false;
|
|
5745
|
+
}
|
|
5746
|
+
};
|
|
5747
|
+
};
|
|
5748
|
+
|
|
5749
|
+
// src/services/pos-service/add-entity.ts
|
|
5750
|
+
var addEntityService = (env) => {
|
|
5751
|
+
const isLocalMode = env?.isLocalMode;
|
|
5752
|
+
const repo = new ModelRepository();
|
|
5753
|
+
const addEntity = (0, import_react18.useCallback)(
|
|
5754
|
+
({
|
|
5755
|
+
model,
|
|
5756
|
+
values,
|
|
5757
|
+
xNode,
|
|
5758
|
+
service,
|
|
5759
|
+
isCreateEndpoint = false
|
|
5760
|
+
}) => {
|
|
5761
|
+
if (isLocalMode) {
|
|
5762
|
+
return repo.addRecord({
|
|
5763
|
+
newRecord: values,
|
|
5764
|
+
modelName: model
|
|
5765
|
+
});
|
|
5766
|
+
}
|
|
5767
|
+
const jsonData = {
|
|
5768
|
+
model,
|
|
5769
|
+
values
|
|
5770
|
+
};
|
|
5771
|
+
return env?.requests.post(
|
|
5772
|
+
isCreateEndpoint ? "/create" /* CREATE_PATH */ : "/call" /* CALL_PATH */,
|
|
5773
|
+
jsonData,
|
|
5774
|
+
{
|
|
5775
|
+
headers: {
|
|
5776
|
+
"Content-Type": "application/json",
|
|
5777
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
5778
|
+
}
|
|
5779
|
+
},
|
|
5780
|
+
service
|
|
5781
|
+
);
|
|
5782
|
+
},
|
|
5783
|
+
[env, isLocalMode]
|
|
5784
|
+
);
|
|
5785
|
+
return {
|
|
5786
|
+
addEntity
|
|
5787
|
+
};
|
|
5788
|
+
};
|
|
5789
|
+
|
|
5790
|
+
// src/services/pos-service/change-order-preparation-state.ts
|
|
5791
|
+
var import_react19 = require("react");
|
|
5792
|
+
var changOrderPreparationStateService = (env) => {
|
|
5793
|
+
const changeOrderPreparationState = (0, import_react19.useCallback)(
|
|
5794
|
+
({
|
|
5795
|
+
orderId,
|
|
5796
|
+
stageId,
|
|
5797
|
+
preparationDisplayId,
|
|
5798
|
+
xNode,
|
|
5799
|
+
service
|
|
5800
|
+
}) => {
|
|
5801
|
+
const jsonData = {
|
|
5802
|
+
model: "pos_preparation_display.order" /* POS_PREPARATION_ORDER */,
|
|
5803
|
+
method: "change_order_stage" /* CHANGE_ORDER_STAGE */,
|
|
5804
|
+
ids: orderId,
|
|
5805
|
+
kwargs: {
|
|
5806
|
+
stage_id: stageId,
|
|
5807
|
+
preparation_display_id: preparationDisplayId
|
|
5808
|
+
}
|
|
5809
|
+
};
|
|
5810
|
+
return env?.requests.post(
|
|
5811
|
+
"/call" /* CALL_PATH */,
|
|
5812
|
+
jsonData,
|
|
5813
|
+
{
|
|
5814
|
+
headers: {
|
|
5815
|
+
"Content-Type": "application/json",
|
|
5816
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
5817
|
+
}
|
|
5818
|
+
},
|
|
5819
|
+
service
|
|
5820
|
+
);
|
|
5821
|
+
},
|
|
5822
|
+
[env]
|
|
5823
|
+
);
|
|
5824
|
+
return {
|
|
5825
|
+
changeOrderPreparationState
|
|
5826
|
+
};
|
|
5827
|
+
};
|
|
5828
|
+
|
|
5829
|
+
// src/services/pos-service/check-payment.ts
|
|
5830
|
+
var import_react20 = require("react");
|
|
5831
|
+
var checkPaymentService = (env) => {
|
|
5832
|
+
const checkPayment = (0, import_react20.useCallback)(
|
|
5833
|
+
({
|
|
5834
|
+
model,
|
|
5835
|
+
ids,
|
|
5836
|
+
withContext,
|
|
5837
|
+
xNode,
|
|
5838
|
+
service
|
|
5839
|
+
}) => {
|
|
5840
|
+
const jsonData = {
|
|
5841
|
+
model,
|
|
5842
|
+
method: "check" /* CHECK */,
|
|
5843
|
+
ids,
|
|
5844
|
+
with_context: withContext
|
|
5845
|
+
};
|
|
5846
|
+
return env?.requests.post(
|
|
5847
|
+
"/call" /* CALL_PATH */,
|
|
5848
|
+
jsonData,
|
|
5849
|
+
{
|
|
5850
|
+
headers: {
|
|
5851
|
+
"Content-Type": "application/json",
|
|
5852
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
5853
|
+
}
|
|
5854
|
+
},
|
|
5855
|
+
service
|
|
5856
|
+
);
|
|
5857
|
+
},
|
|
5858
|
+
[env]
|
|
5859
|
+
);
|
|
5860
|
+
return {
|
|
5861
|
+
checkPayment
|
|
5862
|
+
};
|
|
5863
|
+
};
|
|
5864
|
+
|
|
5865
|
+
// src/services/pos-service/create-e-invoice.ts
|
|
5866
|
+
var import_react21 = require("react");
|
|
5867
|
+
var createEInvoiceService = (env) => {
|
|
5339
5868
|
const createEInvoice = (0, import_react21.useCallback)(
|
|
5340
5869
|
async ({
|
|
5341
5870
|
service,
|
|
@@ -5373,6 +5902,8 @@ var createEInvoiceService = (env) => {
|
|
|
5373
5902
|
// src/services/pos-service/create-entity.ts
|
|
5374
5903
|
var import_react22 = require("react");
|
|
5375
5904
|
var createEntityService = (env) => {
|
|
5905
|
+
const isLocalMode = env?.isLocalMode;
|
|
5906
|
+
const repo = new ModelRepository();
|
|
5376
5907
|
const createEntity = (0, import_react22.useCallback)(
|
|
5377
5908
|
({
|
|
5378
5909
|
model,
|
|
@@ -5380,6 +5911,12 @@ var createEntityService = (env) => {
|
|
|
5380
5911
|
xNode,
|
|
5381
5912
|
service
|
|
5382
5913
|
}) => {
|
|
5914
|
+
if (isLocalMode) {
|
|
5915
|
+
return repo.addRecord({
|
|
5916
|
+
newRecord: args,
|
|
5917
|
+
modelName: model
|
|
5918
|
+
});
|
|
5919
|
+
}
|
|
5383
5920
|
const jsonData = {
|
|
5384
5921
|
model,
|
|
5385
5922
|
method: "create" /* CREATE */,
|
|
@@ -5397,7 +5934,7 @@ var createEntityService = (env) => {
|
|
|
5397
5934
|
service
|
|
5398
5935
|
);
|
|
5399
5936
|
},
|
|
5400
|
-
[env]
|
|
5937
|
+
[env, isLocalMode]
|
|
5401
5938
|
);
|
|
5402
5939
|
return {
|
|
5403
5940
|
createEntity
|
|
@@ -5482,6 +6019,8 @@ var createSessionService = (env) => {
|
|
|
5482
6019
|
// src/services/pos-service/delete-entity.ts
|
|
5483
6020
|
var import_react25 = require("react");
|
|
5484
6021
|
var deleteEntityService = (env) => {
|
|
6022
|
+
const isLocalMode = env?.isLocalMode;
|
|
6023
|
+
const repo = new ModelRepository();
|
|
5485
6024
|
const deleteEntity = (0, import_react25.useCallback)(
|
|
5486
6025
|
({
|
|
5487
6026
|
model,
|
|
@@ -5490,6 +6029,14 @@ var deleteEntityService = (env) => {
|
|
|
5490
6029
|
service,
|
|
5491
6030
|
method
|
|
5492
6031
|
}) => {
|
|
6032
|
+
if (isLocalMode) {
|
|
6033
|
+
const id = ids[0];
|
|
6034
|
+
if (!id) return;
|
|
6035
|
+
return repo.deleteRecord({
|
|
6036
|
+
modelName: model,
|
|
6037
|
+
id
|
|
6038
|
+
});
|
|
6039
|
+
}
|
|
5493
6040
|
const jsonData = {
|
|
5494
6041
|
model,
|
|
5495
6042
|
ids,
|
|
@@ -5507,7 +6054,7 @@ var deleteEntityService = (env) => {
|
|
|
5507
6054
|
service
|
|
5508
6055
|
);
|
|
5509
6056
|
},
|
|
5510
|
-
[env]
|
|
6057
|
+
[env, isLocalMode]
|
|
5511
6058
|
);
|
|
5512
6059
|
return {
|
|
5513
6060
|
deleteEntity
|
|
@@ -5840,356 +6387,111 @@ var handleCloseSessionService = (env) => {
|
|
|
5840
6387
|
const handleCloseSession = (0, import_react34.useCallback)(
|
|
5841
6388
|
({
|
|
5842
6389
|
model,
|
|
5843
|
-
ids,
|
|
5844
|
-
xNode,
|
|
5845
|
-
service,
|
|
5846
|
-
method
|
|
5847
|
-
}) => {
|
|
5848
|
-
const jsonData = {
|
|
5849
|
-
model,
|
|
5850
|
-
ids,
|
|
5851
|
-
method
|
|
5852
|
-
};
|
|
5853
|
-
return env?.requests.post(
|
|
5854
|
-
"/call" /* CALL_PATH */,
|
|
5855
|
-
jsonData,
|
|
5856
|
-
{
|
|
5857
|
-
headers: {
|
|
5858
|
-
"Content-Type": "application/json",
|
|
5859
|
-
...xNode ? { "X-Node": xNode } : {}
|
|
5860
|
-
}
|
|
5861
|
-
},
|
|
5862
|
-
service
|
|
5863
|
-
);
|
|
5864
|
-
},
|
|
5865
|
-
[env]
|
|
5866
|
-
);
|
|
5867
|
-
return {
|
|
5868
|
-
handleCloseSession
|
|
5869
|
-
};
|
|
5870
|
-
};
|
|
5871
|
-
|
|
5872
|
-
// src/services/pos-service/handle-closing-detail-session.ts
|
|
5873
|
-
var import_react35 = require("react");
|
|
5874
|
-
var handleClosingDetailSessionService = (env) => {
|
|
5875
|
-
const handleClosingDetailSession = (0, import_react35.useCallback)(
|
|
5876
|
-
({
|
|
5877
|
-
model,
|
|
5878
|
-
ids,
|
|
5879
|
-
method,
|
|
5880
|
-
xNode,
|
|
5881
|
-
service,
|
|
5882
|
-
kwargs
|
|
5883
|
-
}) => {
|
|
5884
|
-
const jsonData = {
|
|
5885
|
-
model,
|
|
5886
|
-
ids,
|
|
5887
|
-
method,
|
|
5888
|
-
kwargs
|
|
5889
|
-
};
|
|
5890
|
-
return env?.requests.post(
|
|
5891
|
-
"/call" /* CALL_PATH */,
|
|
5892
|
-
jsonData,
|
|
5893
|
-
{
|
|
5894
|
-
headers: {
|
|
5895
|
-
"Content-Type": "application/json",
|
|
5896
|
-
...xNode ? { "X-Node": xNode } : {}
|
|
5897
|
-
}
|
|
5898
|
-
},
|
|
5899
|
-
service
|
|
5900
|
-
);
|
|
5901
|
-
},
|
|
5902
|
-
[env]
|
|
5903
|
-
);
|
|
5904
|
-
return {
|
|
5905
|
-
handleClosingDetailSession
|
|
5906
|
-
};
|
|
5907
|
-
};
|
|
5908
|
-
|
|
5909
|
-
// src/services/pos-service/handle-closing-session.ts
|
|
5910
|
-
var import_react36 = require("react");
|
|
5911
|
-
var handleClosingSessionService = (env) => {
|
|
5912
|
-
const handleClosingSession = (0, import_react36.useCallback)(
|
|
5913
|
-
({
|
|
5914
|
-
model,
|
|
5915
|
-
method,
|
|
5916
|
-
ids,
|
|
5917
|
-
kwargs,
|
|
5918
|
-
xNode,
|
|
5919
|
-
service
|
|
5920
|
-
}) => {
|
|
5921
|
-
const jsonData = {
|
|
5922
|
-
model,
|
|
5923
|
-
method,
|
|
5924
|
-
ids,
|
|
5925
|
-
kwargs
|
|
5926
|
-
};
|
|
5927
|
-
return env?.requests.post(
|
|
5928
|
-
"/call" /* CALL_PATH */,
|
|
5929
|
-
jsonData,
|
|
5930
|
-
{
|
|
5931
|
-
headers: {
|
|
5932
|
-
"Content-Type": "application/json",
|
|
5933
|
-
...xNode ? { "X-Node": xNode } : {}
|
|
5934
|
-
}
|
|
5935
|
-
},
|
|
5936
|
-
service
|
|
5937
|
-
);
|
|
5938
|
-
},
|
|
5939
|
-
[env]
|
|
5940
|
-
);
|
|
5941
|
-
return {
|
|
5942
|
-
handleClosingSession
|
|
5943
|
-
};
|
|
5944
|
-
};
|
|
5945
|
-
|
|
5946
|
-
// src/services/pos-service/load-data-pos-session.ts
|
|
5947
|
-
var import_react37 = require("react");
|
|
5948
|
-
|
|
5949
|
-
// src/services/filesystem-service/file-service.ts
|
|
5950
|
-
var import_filesystem = require("@capacitor/filesystem");
|
|
5951
|
-
var fileService = {
|
|
5952
|
-
async read(path) {
|
|
5953
|
-
try {
|
|
5954
|
-
const res = await import_filesystem.Filesystem.readFile({
|
|
5955
|
-
path,
|
|
5956
|
-
directory: import_filesystem.Directory.Data,
|
|
5957
|
-
encoding: import_filesystem.Encoding.UTF8
|
|
5958
|
-
});
|
|
5959
|
-
if (typeof res.data === "string") return res.data;
|
|
5960
|
-
if (res.data instanceof Blob) return await res.data.text();
|
|
5961
|
-
return null;
|
|
5962
|
-
} catch {
|
|
5963
|
-
return null;
|
|
5964
|
-
}
|
|
5965
|
-
},
|
|
5966
|
-
async write(path, data) {
|
|
5967
|
-
await import_filesystem.Filesystem.writeFile({
|
|
5968
|
-
path,
|
|
5969
|
-
data,
|
|
5970
|
-
directory: import_filesystem.Directory.Data,
|
|
5971
|
-
encoding: import_filesystem.Encoding.UTF8,
|
|
5972
|
-
recursive: true
|
|
5973
|
-
});
|
|
5974
|
-
},
|
|
5975
|
-
async writeAtomic(path, data) {
|
|
5976
|
-
const tempPath = path + ".tmp";
|
|
5977
|
-
await import_filesystem.Filesystem.writeFile({
|
|
5978
|
-
path: tempPath,
|
|
5979
|
-
data,
|
|
5980
|
-
directory: import_filesystem.Directory.Data,
|
|
5981
|
-
encoding: import_filesystem.Encoding.UTF8,
|
|
5982
|
-
recursive: true
|
|
5983
|
-
});
|
|
5984
|
-
try {
|
|
5985
|
-
await import_filesystem.Filesystem.deleteFile({
|
|
5986
|
-
path,
|
|
5987
|
-
directory: import_filesystem.Directory.Data
|
|
5988
|
-
});
|
|
5989
|
-
} catch {
|
|
5990
|
-
}
|
|
5991
|
-
await import_filesystem.Filesystem.rename({
|
|
5992
|
-
from: tempPath,
|
|
5993
|
-
to: path,
|
|
5994
|
-
directory: import_filesystem.Directory.Data
|
|
5995
|
-
});
|
|
5996
|
-
},
|
|
5997
|
-
async delete(path) {
|
|
5998
|
-
try {
|
|
5999
|
-
await import_filesystem.Filesystem.deleteFile({
|
|
6000
|
-
path,
|
|
6001
|
-
directory: import_filesystem.Directory.Data
|
|
6002
|
-
});
|
|
6003
|
-
} catch {
|
|
6004
|
-
}
|
|
6005
|
-
},
|
|
6006
|
-
async exists(path) {
|
|
6007
|
-
try {
|
|
6008
|
-
await import_filesystem.Filesystem.stat({
|
|
6009
|
-
path,
|
|
6010
|
-
directory: import_filesystem.Directory.Data
|
|
6011
|
-
});
|
|
6012
|
-
return true;
|
|
6013
|
-
} catch {
|
|
6014
|
-
return false;
|
|
6015
|
-
}
|
|
6016
|
-
},
|
|
6017
|
-
async mkdir(path) {
|
|
6018
|
-
try {
|
|
6019
|
-
await import_filesystem.Filesystem.mkdir({
|
|
6020
|
-
path,
|
|
6021
|
-
directory: import_filesystem.Directory.Data,
|
|
6022
|
-
recursive: true
|
|
6023
|
-
});
|
|
6024
|
-
} catch (e) {
|
|
6025
|
-
if (!String(e?.message).includes("Exists")) {
|
|
6026
|
-
throw e;
|
|
6027
|
-
}
|
|
6028
|
-
}
|
|
6029
|
-
},
|
|
6030
|
-
async list(path) {
|
|
6031
|
-
return import_filesystem.Filesystem.readdir({
|
|
6032
|
-
path,
|
|
6033
|
-
directory: import_filesystem.Directory.Data
|
|
6034
|
-
});
|
|
6035
|
-
},
|
|
6036
|
-
async getUri(path) {
|
|
6037
|
-
return import_filesystem.Filesystem.getUri({
|
|
6038
|
-
path,
|
|
6039
|
-
directory: import_filesystem.Directory.Data
|
|
6040
|
-
});
|
|
6041
|
-
}
|
|
6042
|
-
};
|
|
6043
|
-
|
|
6044
|
-
// src/services/filesystem-service/json-worker.ts
|
|
6045
|
-
function createWorkerBlob() {
|
|
6046
|
-
const workerCode = `
|
|
6047
|
-
self.addEventListener("message", async (ev) => {
|
|
6048
|
-
const { id, cmd, payload } = ev.data;
|
|
6049
|
-
try {
|
|
6050
|
-
if (cmd === "parse") {
|
|
6051
|
-
const parsed = JSON.parse(payload);
|
|
6052
|
-
self.postMessage({ id, ok: true, result: parsed });
|
|
6053
|
-
} else if (cmd === "stringify") {
|
|
6054
|
-
const str = JSON.stringify(payload);
|
|
6055
|
-
self.postMessage({ id, ok: true, result: str });
|
|
6056
|
-
}
|
|
6057
|
-
} catch (err) {
|
|
6058
|
-
self.postMessage({ id, ok: false, error: err?.message || String(err) });
|
|
6059
|
-
}
|
|
6060
|
-
});
|
|
6061
|
-
`;
|
|
6062
|
-
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
6063
|
-
return URL.createObjectURL(blob);
|
|
6064
|
-
}
|
|
6065
|
-
function spawnParseWorker(raw) {
|
|
6066
|
-
return new Promise((resolve, reject) => {
|
|
6067
|
-
const workerUrl = createWorkerBlob();
|
|
6068
|
-
const worker = new Worker(workerUrl);
|
|
6069
|
-
const id = Math.random().toString(36).slice(2);
|
|
6070
|
-
worker.onmessage = (ev) => {
|
|
6071
|
-
const { ok, result, error } = ev.data;
|
|
6072
|
-
if (ok) {
|
|
6073
|
-
resolve(result);
|
|
6074
|
-
} else {
|
|
6075
|
-
reject(new Error(error));
|
|
6076
|
-
}
|
|
6077
|
-
URL.revokeObjectURL(workerUrl);
|
|
6078
|
-
worker.terminate();
|
|
6079
|
-
};
|
|
6080
|
-
worker.onerror = (err) => {
|
|
6081
|
-
reject(err);
|
|
6082
|
-
URL.revokeObjectURL(workerUrl);
|
|
6083
|
-
worker.terminate();
|
|
6084
|
-
};
|
|
6085
|
-
worker.postMessage({ id, cmd: "parse", payload: raw });
|
|
6086
|
-
});
|
|
6087
|
-
}
|
|
6088
|
-
function spawnStringifyWorker(obj) {
|
|
6089
|
-
return new Promise((resolve, reject) => {
|
|
6090
|
-
const workerUrl = createWorkerBlob();
|
|
6091
|
-
const worker = new Worker(workerUrl);
|
|
6092
|
-
worker.onmessage = (ev) => {
|
|
6093
|
-
const { ok, result, error } = ev.data;
|
|
6094
|
-
if (ok) resolve(result);
|
|
6095
|
-
else reject(new Error(error));
|
|
6096
|
-
URL.revokeObjectURL(workerUrl);
|
|
6097
|
-
worker.terminate();
|
|
6098
|
-
};
|
|
6099
|
-
worker.onerror = (err) => {
|
|
6100
|
-
reject(err);
|
|
6101
|
-
URL.revokeObjectURL(workerUrl);
|
|
6102
|
-
worker.terminate();
|
|
6103
|
-
};
|
|
6104
|
-
worker.postMessage({ cmd: "stringify", payload: obj });
|
|
6105
|
-
});
|
|
6106
|
-
}
|
|
6390
|
+
ids,
|
|
6391
|
+
xNode,
|
|
6392
|
+
service,
|
|
6393
|
+
method
|
|
6394
|
+
}) => {
|
|
6395
|
+
const jsonData = {
|
|
6396
|
+
model,
|
|
6397
|
+
ids,
|
|
6398
|
+
method
|
|
6399
|
+
};
|
|
6400
|
+
return env?.requests.post(
|
|
6401
|
+
"/call" /* CALL_PATH */,
|
|
6402
|
+
jsonData,
|
|
6403
|
+
{
|
|
6404
|
+
headers: {
|
|
6405
|
+
"Content-Type": "application/json",
|
|
6406
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
6407
|
+
}
|
|
6408
|
+
},
|
|
6409
|
+
service
|
|
6410
|
+
);
|
|
6411
|
+
},
|
|
6412
|
+
[env]
|
|
6413
|
+
);
|
|
6414
|
+
return {
|
|
6415
|
+
handleCloseSession
|
|
6416
|
+
};
|
|
6417
|
+
};
|
|
6107
6418
|
|
|
6108
|
-
// src/services/
|
|
6109
|
-
var
|
|
6110
|
-
|
|
6111
|
-
|
|
6112
|
-
|
|
6113
|
-
|
|
6114
|
-
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
|
|
6121
|
-
|
|
6122
|
-
|
|
6123
|
-
|
|
6124
|
-
|
|
6125
|
-
|
|
6126
|
-
|
|
6127
|
-
|
|
6128
|
-
|
|
6419
|
+
// src/services/pos-service/handle-closing-detail-session.ts
|
|
6420
|
+
var import_react35 = require("react");
|
|
6421
|
+
var handleClosingDetailSessionService = (env) => {
|
|
6422
|
+
const handleClosingDetailSession = (0, import_react35.useCallback)(
|
|
6423
|
+
({
|
|
6424
|
+
model,
|
|
6425
|
+
ids,
|
|
6426
|
+
method,
|
|
6427
|
+
xNode,
|
|
6428
|
+
service,
|
|
6429
|
+
kwargs
|
|
6430
|
+
}) => {
|
|
6431
|
+
const jsonData = {
|
|
6432
|
+
model,
|
|
6433
|
+
ids,
|
|
6434
|
+
method,
|
|
6435
|
+
kwargs
|
|
6436
|
+
};
|
|
6437
|
+
return env?.requests.post(
|
|
6438
|
+
"/call" /* CALL_PATH */,
|
|
6439
|
+
jsonData,
|
|
6440
|
+
{
|
|
6441
|
+
headers: {
|
|
6442
|
+
"Content-Type": "application/json",
|
|
6443
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
6444
|
+
}
|
|
6445
|
+
},
|
|
6446
|
+
service
|
|
6447
|
+
);
|
|
6448
|
+
},
|
|
6449
|
+
[env]
|
|
6450
|
+
);
|
|
6451
|
+
return {
|
|
6452
|
+
handleClosingDetailSession
|
|
6453
|
+
};
|
|
6129
6454
|
};
|
|
6130
|
-
var memoryCache = new MemoryCache();
|
|
6131
6455
|
|
|
6132
|
-
// src/services/
|
|
6133
|
-
var
|
|
6134
|
-
var
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
}
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
|
|
6148
|
-
|
|
6149
|
-
const fileName = file.name;
|
|
6150
|
-
const modelName = fileName.replace(/\.json$/, "");
|
|
6151
|
-
const dataPath = `${MODELS_DIR}/${fileName}`;
|
|
6152
|
-
console.log("\u{1F4C2} Reading data from:", dataPath);
|
|
6153
|
-
const rawData = await fileService.read(dataPath);
|
|
6154
|
-
console.log("\u2705 Data read, length:", rawData?.length);
|
|
6155
|
-
if (!rawData) continue;
|
|
6156
|
-
console.log("\u{1F504} Parsing data...");
|
|
6157
|
-
const parsedData = await spawnParseWorker(rawData);
|
|
6158
|
-
console.log("\u2705 Data parsed");
|
|
6159
|
-
const data = Array.isArray(parsedData) ? parsedData : [];
|
|
6160
|
-
if (!includeMeta) {
|
|
6161
|
-
result[modelName] = { data };
|
|
6162
|
-
continue;
|
|
6163
|
-
}
|
|
6164
|
-
const metaPath = `${MODELS_META_DIR}/${encodeURIComponent(
|
|
6165
|
-
modelName
|
|
6166
|
-
)}.meta.json`;
|
|
6167
|
-
console.log("\u{1F4C2} Reading meta from:", metaPath);
|
|
6168
|
-
const rawMeta = await fileService.read(metaPath);
|
|
6169
|
-
let fields = [];
|
|
6170
|
-
let relations = {};
|
|
6171
|
-
if (rawMeta) {
|
|
6172
|
-
console.log("\u{1F504} Parsing meta...");
|
|
6173
|
-
const parsedMeta = await spawnParseWorker(rawMeta);
|
|
6174
|
-
fields = parsedMeta?.fields ?? [];
|
|
6175
|
-
relations = parsedMeta?.relations ?? {};
|
|
6176
|
-
console.log("\u2705 Meta parsed");
|
|
6177
|
-
}
|
|
6178
|
-
result[modelName] = {
|
|
6179
|
-
data,
|
|
6180
|
-
fields,
|
|
6181
|
-
relations
|
|
6456
|
+
// src/services/pos-service/handle-closing-session.ts
|
|
6457
|
+
var import_react36 = require("react");
|
|
6458
|
+
var handleClosingSessionService = (env) => {
|
|
6459
|
+
const handleClosingSession = (0, import_react36.useCallback)(
|
|
6460
|
+
({
|
|
6461
|
+
model,
|
|
6462
|
+
method,
|
|
6463
|
+
ids,
|
|
6464
|
+
kwargs,
|
|
6465
|
+
xNode,
|
|
6466
|
+
service
|
|
6467
|
+
}) => {
|
|
6468
|
+
const jsonData = {
|
|
6469
|
+
model,
|
|
6470
|
+
method,
|
|
6471
|
+
ids,
|
|
6472
|
+
kwargs
|
|
6182
6473
|
};
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
}
|
|
6474
|
+
return env?.requests.post(
|
|
6475
|
+
"/call" /* CALL_PATH */,
|
|
6476
|
+
jsonData,
|
|
6477
|
+
{
|
|
6478
|
+
headers: {
|
|
6479
|
+
"Content-Type": "application/json",
|
|
6480
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
6481
|
+
}
|
|
6482
|
+
},
|
|
6483
|
+
service
|
|
6484
|
+
);
|
|
6485
|
+
},
|
|
6486
|
+
[env]
|
|
6487
|
+
);
|
|
6488
|
+
return {
|
|
6489
|
+
handleClosingSession
|
|
6490
|
+
};
|
|
6491
|
+
};
|
|
6191
6492
|
|
|
6192
6493
|
// src/services/pos-service/load-data-pos-session.ts
|
|
6494
|
+
var import_react37 = require("react");
|
|
6193
6495
|
var loadDataPosSessionService = (env) => {
|
|
6194
6496
|
const isLocalMode = env?.isLocalMode;
|
|
6195
6497
|
const loadDataPosSession = (0, import_react37.useCallback)(
|
|
@@ -6202,10 +6504,8 @@ var loadDataPosSessionService = (env) => {
|
|
|
6202
6504
|
modelsToLoad = [],
|
|
6203
6505
|
searchParams
|
|
6204
6506
|
}) => {
|
|
6205
|
-
console.log("isLocalMode", isLocalMode);
|
|
6206
6507
|
if (isLocalMode) {
|
|
6207
6508
|
const data = await loadData();
|
|
6208
|
-
console.log("\u2705 loadData resolved:", data);
|
|
6209
6509
|
return data;
|
|
6210
6510
|
}
|
|
6211
6511
|
const jsonData = {
|
|
@@ -6459,6 +6759,8 @@ var updateClosedSessionService = (env) => {
|
|
|
6459
6759
|
// src/services/pos-service/update-entity.ts
|
|
6460
6760
|
var import_react44 = require("react");
|
|
6461
6761
|
var updateEntityService = (env) => {
|
|
6762
|
+
const isLocalMode = env?.isLocalMode;
|
|
6763
|
+
const repo = new ModelRepository();
|
|
6462
6764
|
const updateEntity = (0, import_react44.useCallback)(
|
|
6463
6765
|
({
|
|
6464
6766
|
model,
|
|
@@ -6468,6 +6770,15 @@ var updateEntityService = (env) => {
|
|
|
6468
6770
|
xNode,
|
|
6469
6771
|
service
|
|
6470
6772
|
}) => {
|
|
6773
|
+
if (isLocalMode) {
|
|
6774
|
+
const id = extractIdFromDomain(domain);
|
|
6775
|
+
if (!id) return;
|
|
6776
|
+
return repo.updateRecord({
|
|
6777
|
+
update: values,
|
|
6778
|
+
modelName: model,
|
|
6779
|
+
id
|
|
6780
|
+
});
|
|
6781
|
+
}
|
|
6471
6782
|
const jsonData = {
|
|
6472
6783
|
model,
|
|
6473
6784
|
domain,
|
|
@@ -6485,7 +6796,7 @@ var updateEntityService = (env) => {
|
|
|
6485
6796
|
service
|
|
6486
6797
|
);
|
|
6487
6798
|
},
|
|
6488
|
-
[env]
|
|
6799
|
+
[env, isLocalMode]
|
|
6489
6800
|
);
|
|
6490
6801
|
return {
|
|
6491
6802
|
updateEntity
|
|
@@ -6567,101 +6878,6 @@ var usePosService = () => {
|
|
|
6567
6878
|
return service;
|
|
6568
6879
|
};
|
|
6569
6880
|
|
|
6570
|
-
// src/services/filesystem-service/manifest.ts
|
|
6571
|
-
var MANIFEST_PATH = "pos/manifest.json";
|
|
6572
|
-
var MANIFEST_BAK_PATH = "pos/manifest.bak.json";
|
|
6573
|
-
async function writeManifest(manifest) {
|
|
6574
|
-
const oldRaw = await fileService.read(MANIFEST_PATH);
|
|
6575
|
-
if (oldRaw !== null) {
|
|
6576
|
-
await fileService.writeAtomic(MANIFEST_BAK_PATH, oldRaw);
|
|
6577
|
-
}
|
|
6578
|
-
await fileService.writeAtomic(MANIFEST_PATH, JSON.stringify(manifest));
|
|
6579
|
-
try {
|
|
6580
|
-
await fileService.delete(MANIFEST_BAK_PATH);
|
|
6581
|
-
} catch {
|
|
6582
|
-
}
|
|
6583
|
-
}
|
|
6584
|
-
|
|
6585
|
-
// src/services/filesystem-service/import-snapshot.ts
|
|
6586
|
-
var DATA_DIR = "pos";
|
|
6587
|
-
var MODELS_DIR2 = `${DATA_DIR}/models`;
|
|
6588
|
-
var MODELS_META_DIR2 = `${DATA_DIR}/models_meta`;
|
|
6589
|
-
var importSnapshot = async ({ data, onProgress }) => {
|
|
6590
|
-
onProgress?.(1, "Parsing snapshot");
|
|
6591
|
-
const parsed = await spawnParseWorker(data);
|
|
6592
|
-
const modelNames = Object.keys(parsed);
|
|
6593
|
-
const total = modelNames.length;
|
|
6594
|
-
const manifest = { version: (/* @__PURE__ */ new Date()).toISOString(), models: {} };
|
|
6595
|
-
const TMP_PREFIX = `pos/data/tmp_import_${Date.now()}`;
|
|
6596
|
-
await fileService.writeAtomic(`${TMP_PREFIX}/.marker`, "1");
|
|
6597
|
-
let i = 0;
|
|
6598
|
-
for (const model of modelNames) {
|
|
6599
|
-
i++;
|
|
6600
|
-
onProgress?.(
|
|
6601
|
-
Math.round(i / total * 100),
|
|
6602
|
-
`Processing ${model} (${i}/${total})`
|
|
6603
|
-
);
|
|
6604
|
-
const block = parsed[model];
|
|
6605
|
-
const dataPart = block?.data ?? block ?? [];
|
|
6606
|
-
const fields = block?.fields ?? [];
|
|
6607
|
-
const relations = block?.relations ?? {};
|
|
6608
|
-
const serialized = await spawnStringifyWorker(dataPart);
|
|
6609
|
-
const tmpModelPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.json`;
|
|
6610
|
-
await fileService.writeAtomic(tmpModelPath, serialized);
|
|
6611
|
-
const meta = {
|
|
6612
|
-
fields,
|
|
6613
|
-
relations,
|
|
6614
|
-
count: Array.isArray(dataPart) ? dataPart.length : 0,
|
|
6615
|
-
writtenAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
6616
|
-
};
|
|
6617
|
-
const tmpMetaPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`;
|
|
6618
|
-
await fileService.writeAtomic(tmpMetaPath, JSON.stringify(meta));
|
|
6619
|
-
manifest.models[model] = {
|
|
6620
|
-
file: `${MODELS_DIR2}/${encodeURIComponent(model)}.json`,
|
|
6621
|
-
metaFile: `${MODELS_META_DIR2}/${encodeURIComponent(model)}.meta.json`,
|
|
6622
|
-
count: meta.count,
|
|
6623
|
-
updatedAt: meta.writtenAt
|
|
6624
|
-
};
|
|
6625
|
-
}
|
|
6626
|
-
onProgress?.(95, "Committing import (moving files)");
|
|
6627
|
-
for (const model of modelNames) {
|
|
6628
|
-
const tmpModelPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.json`;
|
|
6629
|
-
const finalModelPath = `${MODELS_DIR2}/${encodeURIComponent(model)}.json`;
|
|
6630
|
-
const tmpMetaPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`;
|
|
6631
|
-
const finalMetaPath = `${MODELS_META_DIR2}/${encodeURIComponent(
|
|
6632
|
-
model
|
|
6633
|
-
)}.meta.json`;
|
|
6634
|
-
const tmpRaw = await fileService.read(tmpModelPath);
|
|
6635
|
-
if (tmpRaw !== null) await fileService.writeAtomic(finalModelPath, tmpRaw);
|
|
6636
|
-
const tmpMetaRaw = await fileService.read(tmpMetaPath);
|
|
6637
|
-
if (tmpMetaRaw !== null)
|
|
6638
|
-
await fileService.writeAtomic(finalMetaPath, tmpMetaRaw);
|
|
6639
|
-
onProgress?.(
|
|
6640
|
-
95 + Math.round(
|
|
6641
|
-
(Object.keys(manifest.models).indexOf(model) + 1) / modelNames.length * 5
|
|
6642
|
-
),
|
|
6643
|
-
`Committed ${model}`
|
|
6644
|
-
);
|
|
6645
|
-
}
|
|
6646
|
-
await writeManifest(manifest);
|
|
6647
|
-
try {
|
|
6648
|
-
for (const model of modelNames) {
|
|
6649
|
-
await fileService.delete(
|
|
6650
|
-
`${TMP_PREFIX}/${encodeURIComponent(model)}.json`
|
|
6651
|
-
);
|
|
6652
|
-
await fileService.delete(
|
|
6653
|
-
`${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`
|
|
6654
|
-
);
|
|
6655
|
-
}
|
|
6656
|
-
await fileService.delete(`${TMP_PREFIX}/.marker`);
|
|
6657
|
-
} catch (e) {
|
|
6658
|
-
console.log("Failed to cleanup tmp import files:", e);
|
|
6659
|
-
}
|
|
6660
|
-
onProgress?.(100, "Import complete");
|
|
6661
|
-
return manifest;
|
|
6662
|
-
};
|
|
6663
|
-
var import_snapshot_default = importSnapshot;
|
|
6664
|
-
|
|
6665
6881
|
// src/services/filesystem-service/init-snapshot.ts
|
|
6666
6882
|
var isSnapshotReady = async () => {
|
|
6667
6883
|
try {
|