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