@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/provider.js
CHANGED
|
@@ -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,116 +5215,638 @@ var getASessionService = (env) => {
|
|
|
5208
5215
|
|
|
5209
5216
|
// src/services/pos-service/add-entity.ts
|
|
5210
5217
|
var import_react14 = require("react");
|
|
5211
|
-
var addEntityService = (env) => {
|
|
5212
|
-
const addEntity = (0, import_react14.useCallback)(
|
|
5213
|
-
({
|
|
5214
|
-
model,
|
|
5215
|
-
values,
|
|
5216
|
-
xNode,
|
|
5217
|
-
service,
|
|
5218
|
-
isCreateEndpoint = false
|
|
5219
|
-
}) => {
|
|
5220
|
-
const jsonData = {
|
|
5221
|
-
model,
|
|
5222
|
-
values
|
|
5223
|
-
};
|
|
5224
|
-
return env?.requests.post(
|
|
5225
|
-
isCreateEndpoint ? "/create" /* CREATE_PATH */ : "/call" /* CALL_PATH */,
|
|
5226
|
-
jsonData,
|
|
5227
|
-
{
|
|
5228
|
-
headers: {
|
|
5229
|
-
"Content-Type": "application/json",
|
|
5230
|
-
...xNode ? { "X-Node": xNode } : {}
|
|
5231
|
-
}
|
|
5232
|
-
},
|
|
5233
|
-
service
|
|
5234
|
-
);
|
|
5235
|
-
},
|
|
5236
|
-
[env]
|
|
5237
|
-
);
|
|
5238
|
-
return {
|
|
5239
|
-
addEntity
|
|
5240
|
-
};
|
|
5241
|
-
};
|
|
5242
5218
|
|
|
5243
|
-
// src/services/
|
|
5244
|
-
var
|
|
5245
|
-
var
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
|
|
5271
|
-
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
|
|
5275
|
-
|
|
5276
|
-
|
|
5277
|
-
|
|
5278
|
-
|
|
5279
|
-
|
|
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
|
+
}
|
|
5280
5312
|
};
|
|
5281
5313
|
|
|
5282
|
-
// src/services/
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
|
|
5297
|
-
|
|
5298
|
-
|
|
5299
|
-
|
|
5300
|
-
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
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 });
|
|
5326
|
+
}
|
|
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
|
+
}
|
|
5317
5377
|
|
|
5318
|
-
// src/services/
|
|
5319
|
-
var
|
|
5320
|
-
var
|
|
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
|
+
}
|
|
5392
|
+
|
|
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
|
+
console.log("modelName", modelName);
|
|
5654
|
+
console.log("snapshot", snapshot);
|
|
5655
|
+
const existingIds = getExistingIds(snapshot);
|
|
5656
|
+
console.log("existingIds", existingIds);
|
|
5657
|
+
const newId = generateNextId(existingIds, snapshot.data.length);
|
|
5658
|
+
console.log("newId", newId);
|
|
5659
|
+
snapshot.data.push({
|
|
5660
|
+
...newRecord,
|
|
5661
|
+
id: newId
|
|
5662
|
+
});
|
|
5663
|
+
const saved = await saveSnapshot({
|
|
5664
|
+
snapshot,
|
|
5665
|
+
modelName
|
|
5666
|
+
});
|
|
5667
|
+
if (!saved) {
|
|
5668
|
+
console.error("failed to add new record");
|
|
5669
|
+
return [];
|
|
5670
|
+
}
|
|
5671
|
+
console.log(`\u2705 ${snapshot.data.length} records saved`);
|
|
5672
|
+
console.log(snapshot.data);
|
|
5673
|
+
return snapshot.data;
|
|
5674
|
+
} catch (error) {
|
|
5675
|
+
console.error("failed to add new record:", error);
|
|
5676
|
+
return [];
|
|
5677
|
+
}
|
|
5678
|
+
};
|
|
5679
|
+
updateRecord = async ({
|
|
5680
|
+
id,
|
|
5681
|
+
update,
|
|
5682
|
+
modelName
|
|
5683
|
+
}) => {
|
|
5684
|
+
try {
|
|
5685
|
+
const snapshot = await loadSnapshot({
|
|
5686
|
+
modelName
|
|
5687
|
+
});
|
|
5688
|
+
const index = snapshot.data.findIndex((record) => record.id === id);
|
|
5689
|
+
if (index === -1) {
|
|
5690
|
+
console.error(`record with id ${id} not found`);
|
|
5691
|
+
return false;
|
|
5692
|
+
}
|
|
5693
|
+
snapshot.data[index] = {
|
|
5694
|
+
...snapshot.data[index],
|
|
5695
|
+
...update
|
|
5696
|
+
};
|
|
5697
|
+
return await saveSnapshot({
|
|
5698
|
+
snapshot,
|
|
5699
|
+
modelName
|
|
5700
|
+
});
|
|
5701
|
+
} catch (error) {
|
|
5702
|
+
console.error("error updating record:", error);
|
|
5703
|
+
return false;
|
|
5704
|
+
}
|
|
5705
|
+
};
|
|
5706
|
+
deleteRecord = async ({
|
|
5707
|
+
id,
|
|
5708
|
+
modelName
|
|
5709
|
+
}) => {
|
|
5710
|
+
try {
|
|
5711
|
+
const snapshot = await loadSnapshot({
|
|
5712
|
+
modelName
|
|
5713
|
+
});
|
|
5714
|
+
const before = snapshot.data.length;
|
|
5715
|
+
snapshot.data = snapshot.data.filter((record) => record.id !== id);
|
|
5716
|
+
if (snapshot.data.length === before) {
|
|
5717
|
+
console.error(`record with id ${id} not found`);
|
|
5718
|
+
return false;
|
|
5719
|
+
}
|
|
5720
|
+
return await saveSnapshot({
|
|
5721
|
+
snapshot,
|
|
5722
|
+
modelName
|
|
5723
|
+
});
|
|
5724
|
+
} catch (error) {
|
|
5725
|
+
console.error("error deleting record:", error);
|
|
5726
|
+
return false;
|
|
5727
|
+
}
|
|
5728
|
+
};
|
|
5729
|
+
};
|
|
5730
|
+
|
|
5731
|
+
// src/services/pos-service/add-entity.ts
|
|
5732
|
+
var addEntityService = (env) => {
|
|
5733
|
+
const isLocalMode = env?.isLocalMode;
|
|
5734
|
+
const repo = new ModelRepository();
|
|
5735
|
+
const addEntity = (0, import_react14.useCallback)(
|
|
5736
|
+
({
|
|
5737
|
+
model,
|
|
5738
|
+
values,
|
|
5739
|
+
xNode,
|
|
5740
|
+
service,
|
|
5741
|
+
isCreateEndpoint = false
|
|
5742
|
+
}) => {
|
|
5743
|
+
if (isLocalMode) {
|
|
5744
|
+
return repo.addRecord({
|
|
5745
|
+
newRecord: values,
|
|
5746
|
+
modelName: model
|
|
5747
|
+
});
|
|
5748
|
+
}
|
|
5749
|
+
const jsonData = {
|
|
5750
|
+
model,
|
|
5751
|
+
values
|
|
5752
|
+
};
|
|
5753
|
+
return env?.requests.post(
|
|
5754
|
+
isCreateEndpoint ? "/create" /* CREATE_PATH */ : "/call" /* CALL_PATH */,
|
|
5755
|
+
jsonData,
|
|
5756
|
+
{
|
|
5757
|
+
headers: {
|
|
5758
|
+
"Content-Type": "application/json",
|
|
5759
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
5760
|
+
}
|
|
5761
|
+
},
|
|
5762
|
+
service
|
|
5763
|
+
);
|
|
5764
|
+
},
|
|
5765
|
+
[env, isLocalMode]
|
|
5766
|
+
);
|
|
5767
|
+
return {
|
|
5768
|
+
addEntity
|
|
5769
|
+
};
|
|
5770
|
+
};
|
|
5771
|
+
|
|
5772
|
+
// src/services/pos-service/change-order-preparation-state.ts
|
|
5773
|
+
var import_react15 = require("react");
|
|
5774
|
+
var changOrderPreparationStateService = (env) => {
|
|
5775
|
+
const changeOrderPreparationState = (0, import_react15.useCallback)(
|
|
5776
|
+
({
|
|
5777
|
+
orderId,
|
|
5778
|
+
stageId,
|
|
5779
|
+
preparationDisplayId,
|
|
5780
|
+
xNode,
|
|
5781
|
+
service
|
|
5782
|
+
}) => {
|
|
5783
|
+
const jsonData = {
|
|
5784
|
+
model: "pos_preparation_display.order" /* POS_PREPARATION_ORDER */,
|
|
5785
|
+
method: "change_order_stage" /* CHANGE_ORDER_STAGE */,
|
|
5786
|
+
ids: orderId,
|
|
5787
|
+
kwargs: {
|
|
5788
|
+
stage_id: stageId,
|
|
5789
|
+
preparation_display_id: preparationDisplayId
|
|
5790
|
+
}
|
|
5791
|
+
};
|
|
5792
|
+
return env?.requests.post(
|
|
5793
|
+
"/call" /* CALL_PATH */,
|
|
5794
|
+
jsonData,
|
|
5795
|
+
{
|
|
5796
|
+
headers: {
|
|
5797
|
+
"Content-Type": "application/json",
|
|
5798
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
5799
|
+
}
|
|
5800
|
+
},
|
|
5801
|
+
service
|
|
5802
|
+
);
|
|
5803
|
+
},
|
|
5804
|
+
[env]
|
|
5805
|
+
);
|
|
5806
|
+
return {
|
|
5807
|
+
changeOrderPreparationState
|
|
5808
|
+
};
|
|
5809
|
+
};
|
|
5810
|
+
|
|
5811
|
+
// src/services/pos-service/check-payment.ts
|
|
5812
|
+
var import_react16 = require("react");
|
|
5813
|
+
var checkPaymentService = (env) => {
|
|
5814
|
+
const checkPayment = (0, import_react16.useCallback)(
|
|
5815
|
+
({
|
|
5816
|
+
model,
|
|
5817
|
+
ids,
|
|
5818
|
+
withContext,
|
|
5819
|
+
xNode,
|
|
5820
|
+
service
|
|
5821
|
+
}) => {
|
|
5822
|
+
const jsonData = {
|
|
5823
|
+
model,
|
|
5824
|
+
method: "check" /* CHECK */,
|
|
5825
|
+
ids,
|
|
5826
|
+
with_context: withContext
|
|
5827
|
+
};
|
|
5828
|
+
return env?.requests.post(
|
|
5829
|
+
"/call" /* CALL_PATH */,
|
|
5830
|
+
jsonData,
|
|
5831
|
+
{
|
|
5832
|
+
headers: {
|
|
5833
|
+
"Content-Type": "application/json",
|
|
5834
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
5835
|
+
}
|
|
5836
|
+
},
|
|
5837
|
+
service
|
|
5838
|
+
);
|
|
5839
|
+
},
|
|
5840
|
+
[env]
|
|
5841
|
+
);
|
|
5842
|
+
return {
|
|
5843
|
+
checkPayment
|
|
5844
|
+
};
|
|
5845
|
+
};
|
|
5846
|
+
|
|
5847
|
+
// src/services/pos-service/create-e-invoice.ts
|
|
5848
|
+
var import_react17 = require("react");
|
|
5849
|
+
var createEInvoiceService = (env) => {
|
|
5321
5850
|
const createEInvoice = (0, import_react17.useCallback)(
|
|
5322
5851
|
async ({
|
|
5323
5852
|
service,
|
|
@@ -5355,6 +5884,8 @@ var createEInvoiceService = (env) => {
|
|
|
5355
5884
|
// src/services/pos-service/create-entity.ts
|
|
5356
5885
|
var import_react18 = require("react");
|
|
5357
5886
|
var createEntityService = (env) => {
|
|
5887
|
+
const isLocalMode = env?.isLocalMode;
|
|
5888
|
+
const repo = new ModelRepository();
|
|
5358
5889
|
const createEntity = (0, import_react18.useCallback)(
|
|
5359
5890
|
({
|
|
5360
5891
|
model,
|
|
@@ -5362,6 +5893,12 @@ var createEntityService = (env) => {
|
|
|
5362
5893
|
xNode,
|
|
5363
5894
|
service
|
|
5364
5895
|
}) => {
|
|
5896
|
+
if (isLocalMode) {
|
|
5897
|
+
return repo.addRecord({
|
|
5898
|
+
newRecord: args,
|
|
5899
|
+
modelName: model
|
|
5900
|
+
});
|
|
5901
|
+
}
|
|
5365
5902
|
const jsonData = {
|
|
5366
5903
|
model,
|
|
5367
5904
|
method: "create" /* CREATE */,
|
|
@@ -5379,7 +5916,7 @@ var createEntityService = (env) => {
|
|
|
5379
5916
|
service
|
|
5380
5917
|
);
|
|
5381
5918
|
},
|
|
5382
|
-
[env]
|
|
5919
|
+
[env, isLocalMode]
|
|
5383
5920
|
);
|
|
5384
5921
|
return {
|
|
5385
5922
|
createEntity
|
|
@@ -5464,6 +6001,8 @@ var createSessionService = (env) => {
|
|
|
5464
6001
|
// src/services/pos-service/delete-entity.ts
|
|
5465
6002
|
var import_react21 = require("react");
|
|
5466
6003
|
var deleteEntityService = (env) => {
|
|
6004
|
+
const isLocalMode = env?.isLocalMode;
|
|
6005
|
+
const repo = new ModelRepository();
|
|
5467
6006
|
const deleteEntity = (0, import_react21.useCallback)(
|
|
5468
6007
|
({
|
|
5469
6008
|
model,
|
|
@@ -5472,6 +6011,14 @@ var deleteEntityService = (env) => {
|
|
|
5472
6011
|
service,
|
|
5473
6012
|
method
|
|
5474
6013
|
}) => {
|
|
6014
|
+
if (isLocalMode) {
|
|
6015
|
+
const id = ids[0];
|
|
6016
|
+
if (!id) return;
|
|
6017
|
+
return repo.deleteRecord({
|
|
6018
|
+
modelName: model,
|
|
6019
|
+
id
|
|
6020
|
+
});
|
|
6021
|
+
}
|
|
5475
6022
|
const jsonData = {
|
|
5476
6023
|
model,
|
|
5477
6024
|
ids,
|
|
@@ -5489,7 +6036,7 @@ var deleteEntityService = (env) => {
|
|
|
5489
6036
|
service
|
|
5490
6037
|
);
|
|
5491
6038
|
},
|
|
5492
|
-
[env]
|
|
6039
|
+
[env, isLocalMode]
|
|
5493
6040
|
);
|
|
5494
6041
|
return {
|
|
5495
6042
|
deleteEntity
|
|
@@ -5822,356 +6369,111 @@ var handleCloseSessionService = (env) => {
|
|
|
5822
6369
|
const handleCloseSession = (0, import_react30.useCallback)(
|
|
5823
6370
|
({
|
|
5824
6371
|
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
|
-
function createWorkerBlob() {
|
|
6028
|
-
const workerCode = `
|
|
6029
|
-
self.addEventListener("message", async (ev) => {
|
|
6030
|
-
const { id, cmd, payload } = ev.data;
|
|
6031
|
-
try {
|
|
6032
|
-
if (cmd === "parse") {
|
|
6033
|
-
const parsed = JSON.parse(payload);
|
|
6034
|
-
self.postMessage({ id, ok: true, result: parsed });
|
|
6035
|
-
} else if (cmd === "stringify") {
|
|
6036
|
-
const str = JSON.stringify(payload);
|
|
6037
|
-
self.postMessage({ id, ok: true, result: str });
|
|
6038
|
-
}
|
|
6039
|
-
} catch (err) {
|
|
6040
|
-
self.postMessage({ id, ok: false, error: err?.message || String(err) });
|
|
6041
|
-
}
|
|
6042
|
-
});
|
|
6043
|
-
`;
|
|
6044
|
-
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
6045
|
-
return URL.createObjectURL(blob);
|
|
6046
|
-
}
|
|
6047
|
-
function spawnParseWorker(raw) {
|
|
6048
|
-
return new Promise((resolve, reject) => {
|
|
6049
|
-
const workerUrl = createWorkerBlob();
|
|
6050
|
-
const worker = new Worker(workerUrl);
|
|
6051
|
-
const id = Math.random().toString(36).slice(2);
|
|
6052
|
-
worker.onmessage = (ev) => {
|
|
6053
|
-
const { ok, result, error } = ev.data;
|
|
6054
|
-
if (ok) {
|
|
6055
|
-
resolve(result);
|
|
6056
|
-
} else {
|
|
6057
|
-
reject(new Error(error));
|
|
6058
|
-
}
|
|
6059
|
-
URL.revokeObjectURL(workerUrl);
|
|
6060
|
-
worker.terminate();
|
|
6061
|
-
};
|
|
6062
|
-
worker.onerror = (err) => {
|
|
6063
|
-
reject(err);
|
|
6064
|
-
URL.revokeObjectURL(workerUrl);
|
|
6065
|
-
worker.terminate();
|
|
6066
|
-
};
|
|
6067
|
-
worker.postMessage({ id, cmd: "parse", payload: raw });
|
|
6068
|
-
});
|
|
6069
|
-
}
|
|
6070
|
-
function spawnStringifyWorker(obj) {
|
|
6071
|
-
return new Promise((resolve, reject) => {
|
|
6072
|
-
const workerUrl = createWorkerBlob();
|
|
6073
|
-
const worker = new Worker(workerUrl);
|
|
6074
|
-
worker.onmessage = (ev) => {
|
|
6075
|
-
const { ok, result, error } = ev.data;
|
|
6076
|
-
if (ok) resolve(result);
|
|
6077
|
-
else reject(new Error(error));
|
|
6078
|
-
URL.revokeObjectURL(workerUrl);
|
|
6079
|
-
worker.terminate();
|
|
6080
|
-
};
|
|
6081
|
-
worker.onerror = (err) => {
|
|
6082
|
-
reject(err);
|
|
6083
|
-
URL.revokeObjectURL(workerUrl);
|
|
6084
|
-
worker.terminate();
|
|
6085
|
-
};
|
|
6086
|
-
worker.postMessage({ cmd: "stringify", payload: obj });
|
|
6087
|
-
});
|
|
6088
|
-
}
|
|
6372
|
+
ids,
|
|
6373
|
+
xNode,
|
|
6374
|
+
service,
|
|
6375
|
+
method
|
|
6376
|
+
}) => {
|
|
6377
|
+
const jsonData = {
|
|
6378
|
+
model,
|
|
6379
|
+
ids,
|
|
6380
|
+
method
|
|
6381
|
+
};
|
|
6382
|
+
return env?.requests.post(
|
|
6383
|
+
"/call" /* CALL_PATH */,
|
|
6384
|
+
jsonData,
|
|
6385
|
+
{
|
|
6386
|
+
headers: {
|
|
6387
|
+
"Content-Type": "application/json",
|
|
6388
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
6389
|
+
}
|
|
6390
|
+
},
|
|
6391
|
+
service
|
|
6392
|
+
);
|
|
6393
|
+
},
|
|
6394
|
+
[env]
|
|
6395
|
+
);
|
|
6396
|
+
return {
|
|
6397
|
+
handleCloseSession
|
|
6398
|
+
};
|
|
6399
|
+
};
|
|
6089
6400
|
|
|
6090
|
-
// src/services/
|
|
6091
|
-
var
|
|
6092
|
-
|
|
6093
|
-
|
|
6094
|
-
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
|
|
6098
|
-
|
|
6099
|
-
|
|
6100
|
-
|
|
6101
|
-
|
|
6102
|
-
|
|
6103
|
-
|
|
6104
|
-
|
|
6105
|
-
|
|
6106
|
-
|
|
6107
|
-
|
|
6108
|
-
|
|
6109
|
-
|
|
6110
|
-
|
|
6401
|
+
// src/services/pos-service/handle-closing-detail-session.ts
|
|
6402
|
+
var import_react31 = require("react");
|
|
6403
|
+
var handleClosingDetailSessionService = (env) => {
|
|
6404
|
+
const handleClosingDetailSession = (0, import_react31.useCallback)(
|
|
6405
|
+
({
|
|
6406
|
+
model,
|
|
6407
|
+
ids,
|
|
6408
|
+
method,
|
|
6409
|
+
xNode,
|
|
6410
|
+
service,
|
|
6411
|
+
kwargs
|
|
6412
|
+
}) => {
|
|
6413
|
+
const jsonData = {
|
|
6414
|
+
model,
|
|
6415
|
+
ids,
|
|
6416
|
+
method,
|
|
6417
|
+
kwargs
|
|
6418
|
+
};
|
|
6419
|
+
return env?.requests.post(
|
|
6420
|
+
"/call" /* CALL_PATH */,
|
|
6421
|
+
jsonData,
|
|
6422
|
+
{
|
|
6423
|
+
headers: {
|
|
6424
|
+
"Content-Type": "application/json",
|
|
6425
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
6426
|
+
}
|
|
6427
|
+
},
|
|
6428
|
+
service
|
|
6429
|
+
);
|
|
6430
|
+
},
|
|
6431
|
+
[env]
|
|
6432
|
+
);
|
|
6433
|
+
return {
|
|
6434
|
+
handleClosingDetailSession
|
|
6435
|
+
};
|
|
6111
6436
|
};
|
|
6112
|
-
var memoryCache = new MemoryCache();
|
|
6113
6437
|
|
|
6114
|
-
// src/services/
|
|
6115
|
-
var
|
|
6116
|
-
var
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
|
|
6121
|
-
|
|
6122
|
-
|
|
6123
|
-
|
|
6124
|
-
|
|
6125
|
-
}
|
|
6126
|
-
|
|
6127
|
-
|
|
6128
|
-
|
|
6129
|
-
|
|
6130
|
-
|
|
6131
|
-
const fileName = file.name;
|
|
6132
|
-
const modelName = fileName.replace(/\.json$/, "");
|
|
6133
|
-
const dataPath = `${MODELS_DIR}/${fileName}`;
|
|
6134
|
-
console.log("\u{1F4C2} Reading data from:", dataPath);
|
|
6135
|
-
const rawData = await fileService.read(dataPath);
|
|
6136
|
-
console.log("\u2705 Data read, length:", rawData?.length);
|
|
6137
|
-
if (!rawData) continue;
|
|
6138
|
-
console.log("\u{1F504} Parsing data...");
|
|
6139
|
-
const parsedData = await spawnParseWorker(rawData);
|
|
6140
|
-
console.log("\u2705 Data parsed");
|
|
6141
|
-
const data = Array.isArray(parsedData) ? parsedData : [];
|
|
6142
|
-
if (!includeMeta) {
|
|
6143
|
-
result[modelName] = { data };
|
|
6144
|
-
continue;
|
|
6145
|
-
}
|
|
6146
|
-
const metaPath = `${MODELS_META_DIR}/${encodeURIComponent(
|
|
6147
|
-
modelName
|
|
6148
|
-
)}.meta.json`;
|
|
6149
|
-
console.log("\u{1F4C2} Reading meta from:", metaPath);
|
|
6150
|
-
const rawMeta = await fileService.read(metaPath);
|
|
6151
|
-
let fields = [];
|
|
6152
|
-
let relations = {};
|
|
6153
|
-
if (rawMeta) {
|
|
6154
|
-
console.log("\u{1F504} Parsing meta...");
|
|
6155
|
-
const parsedMeta = await spawnParseWorker(rawMeta);
|
|
6156
|
-
fields = parsedMeta?.fields ?? [];
|
|
6157
|
-
relations = parsedMeta?.relations ?? {};
|
|
6158
|
-
console.log("\u2705 Meta parsed");
|
|
6159
|
-
}
|
|
6160
|
-
result[modelName] = {
|
|
6161
|
-
data,
|
|
6162
|
-
fields,
|
|
6163
|
-
relations
|
|
6438
|
+
// src/services/pos-service/handle-closing-session.ts
|
|
6439
|
+
var import_react32 = require("react");
|
|
6440
|
+
var handleClosingSessionService = (env) => {
|
|
6441
|
+
const handleClosingSession = (0, import_react32.useCallback)(
|
|
6442
|
+
({
|
|
6443
|
+
model,
|
|
6444
|
+
method,
|
|
6445
|
+
ids,
|
|
6446
|
+
kwargs,
|
|
6447
|
+
xNode,
|
|
6448
|
+
service
|
|
6449
|
+
}) => {
|
|
6450
|
+
const jsonData = {
|
|
6451
|
+
model,
|
|
6452
|
+
method,
|
|
6453
|
+
ids,
|
|
6454
|
+
kwargs
|
|
6164
6455
|
};
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
}
|
|
6456
|
+
return env?.requests.post(
|
|
6457
|
+
"/call" /* CALL_PATH */,
|
|
6458
|
+
jsonData,
|
|
6459
|
+
{
|
|
6460
|
+
headers: {
|
|
6461
|
+
"Content-Type": "application/json",
|
|
6462
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
6463
|
+
}
|
|
6464
|
+
},
|
|
6465
|
+
service
|
|
6466
|
+
);
|
|
6467
|
+
},
|
|
6468
|
+
[env]
|
|
6469
|
+
);
|
|
6470
|
+
return {
|
|
6471
|
+
handleClosingSession
|
|
6472
|
+
};
|
|
6473
|
+
};
|
|
6173
6474
|
|
|
6174
6475
|
// src/services/pos-service/load-data-pos-session.ts
|
|
6476
|
+
var import_react33 = require("react");
|
|
6175
6477
|
var loadDataPosSessionService = (env) => {
|
|
6176
6478
|
const isLocalMode = env?.isLocalMode;
|
|
6177
6479
|
const loadDataPosSession = (0, import_react33.useCallback)(
|
|
@@ -6184,10 +6486,8 @@ var loadDataPosSessionService = (env) => {
|
|
|
6184
6486
|
modelsToLoad = [],
|
|
6185
6487
|
searchParams
|
|
6186
6488
|
}) => {
|
|
6187
|
-
console.log("isLocalMode", isLocalMode);
|
|
6188
6489
|
if (isLocalMode) {
|
|
6189
6490
|
const data = await loadData();
|
|
6190
|
-
console.log("\u2705 loadData resolved:", data);
|
|
6191
6491
|
return data;
|
|
6192
6492
|
}
|
|
6193
6493
|
const jsonData = {
|
|
@@ -6441,6 +6741,8 @@ var updateClosedSessionService = (env) => {
|
|
|
6441
6741
|
// src/services/pos-service/update-entity.ts
|
|
6442
6742
|
var import_react40 = require("react");
|
|
6443
6743
|
var updateEntityService = (env) => {
|
|
6744
|
+
const isLocalMode = env?.isLocalMode;
|
|
6745
|
+
const repo = new ModelRepository();
|
|
6444
6746
|
const updateEntity = (0, import_react40.useCallback)(
|
|
6445
6747
|
({
|
|
6446
6748
|
model,
|
|
@@ -6450,6 +6752,15 @@ var updateEntityService = (env) => {
|
|
|
6450
6752
|
xNode,
|
|
6451
6753
|
service
|
|
6452
6754
|
}) => {
|
|
6755
|
+
if (isLocalMode) {
|
|
6756
|
+
const id = extractIdFromDomain(domain);
|
|
6757
|
+
if (!id) return;
|
|
6758
|
+
return repo.updateRecord({
|
|
6759
|
+
update: values,
|
|
6760
|
+
modelName: model,
|
|
6761
|
+
id
|
|
6762
|
+
});
|
|
6763
|
+
}
|
|
6453
6764
|
const jsonData = {
|
|
6454
6765
|
model,
|
|
6455
6766
|
domain,
|
|
@@ -6467,7 +6778,7 @@ var updateEntityService = (env) => {
|
|
|
6467
6778
|
service
|
|
6468
6779
|
);
|
|
6469
6780
|
},
|
|
6470
|
-
[env]
|
|
6781
|
+
[env, isLocalMode]
|
|
6471
6782
|
);
|
|
6472
6783
|
return {
|
|
6473
6784
|
updateEntity
|
|
@@ -6549,101 +6860,6 @@ var usePosService = () => {
|
|
|
6549
6860
|
return service;
|
|
6550
6861
|
};
|
|
6551
6862
|
|
|
6552
|
-
// src/services/filesystem-service/manifest.ts
|
|
6553
|
-
var MANIFEST_PATH = "pos/manifest.json";
|
|
6554
|
-
var MANIFEST_BAK_PATH = "pos/manifest.bak.json";
|
|
6555
|
-
async function writeManifest(manifest) {
|
|
6556
|
-
const oldRaw = await fileService.read(MANIFEST_PATH);
|
|
6557
|
-
if (oldRaw !== null) {
|
|
6558
|
-
await fileService.writeAtomic(MANIFEST_BAK_PATH, oldRaw);
|
|
6559
|
-
}
|
|
6560
|
-
await fileService.writeAtomic(MANIFEST_PATH, JSON.stringify(manifest));
|
|
6561
|
-
try {
|
|
6562
|
-
await fileService.delete(MANIFEST_BAK_PATH);
|
|
6563
|
-
} catch {
|
|
6564
|
-
}
|
|
6565
|
-
}
|
|
6566
|
-
|
|
6567
|
-
// src/services/filesystem-service/import-snapshot.ts
|
|
6568
|
-
var DATA_DIR = "pos";
|
|
6569
|
-
var MODELS_DIR2 = `${DATA_DIR}/models`;
|
|
6570
|
-
var MODELS_META_DIR2 = `${DATA_DIR}/models_meta`;
|
|
6571
|
-
var importSnapshot = async ({ data, onProgress }) => {
|
|
6572
|
-
onProgress?.(1, "Parsing snapshot");
|
|
6573
|
-
const parsed = await spawnParseWorker(data);
|
|
6574
|
-
const modelNames = Object.keys(parsed);
|
|
6575
|
-
const total = modelNames.length;
|
|
6576
|
-
const manifest = { version: (/* @__PURE__ */ new Date()).toISOString(), models: {} };
|
|
6577
|
-
const TMP_PREFIX = `pos/data/tmp_import_${Date.now()}`;
|
|
6578
|
-
await fileService.writeAtomic(`${TMP_PREFIX}/.marker`, "1");
|
|
6579
|
-
let i = 0;
|
|
6580
|
-
for (const model of modelNames) {
|
|
6581
|
-
i++;
|
|
6582
|
-
onProgress?.(
|
|
6583
|
-
Math.round(i / total * 100),
|
|
6584
|
-
`Processing ${model} (${i}/${total})`
|
|
6585
|
-
);
|
|
6586
|
-
const block = parsed[model];
|
|
6587
|
-
const dataPart = block?.data ?? block ?? [];
|
|
6588
|
-
const fields = block?.fields ?? [];
|
|
6589
|
-
const relations = block?.relations ?? {};
|
|
6590
|
-
const serialized = await spawnStringifyWorker(dataPart);
|
|
6591
|
-
const tmpModelPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.json`;
|
|
6592
|
-
await fileService.writeAtomic(tmpModelPath, serialized);
|
|
6593
|
-
const meta = {
|
|
6594
|
-
fields,
|
|
6595
|
-
relations,
|
|
6596
|
-
count: Array.isArray(dataPart) ? dataPart.length : 0,
|
|
6597
|
-
writtenAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
6598
|
-
};
|
|
6599
|
-
const tmpMetaPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`;
|
|
6600
|
-
await fileService.writeAtomic(tmpMetaPath, JSON.stringify(meta));
|
|
6601
|
-
manifest.models[model] = {
|
|
6602
|
-
file: `${MODELS_DIR2}/${encodeURIComponent(model)}.json`,
|
|
6603
|
-
metaFile: `${MODELS_META_DIR2}/${encodeURIComponent(model)}.meta.json`,
|
|
6604
|
-
count: meta.count,
|
|
6605
|
-
updatedAt: meta.writtenAt
|
|
6606
|
-
};
|
|
6607
|
-
}
|
|
6608
|
-
onProgress?.(95, "Committing import (moving files)");
|
|
6609
|
-
for (const model of modelNames) {
|
|
6610
|
-
const tmpModelPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.json`;
|
|
6611
|
-
const finalModelPath = `${MODELS_DIR2}/${encodeURIComponent(model)}.json`;
|
|
6612
|
-
const tmpMetaPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`;
|
|
6613
|
-
const finalMetaPath = `${MODELS_META_DIR2}/${encodeURIComponent(
|
|
6614
|
-
model
|
|
6615
|
-
)}.meta.json`;
|
|
6616
|
-
const tmpRaw = await fileService.read(tmpModelPath);
|
|
6617
|
-
if (tmpRaw !== null) await fileService.writeAtomic(finalModelPath, tmpRaw);
|
|
6618
|
-
const tmpMetaRaw = await fileService.read(tmpMetaPath);
|
|
6619
|
-
if (tmpMetaRaw !== null)
|
|
6620
|
-
await fileService.writeAtomic(finalMetaPath, tmpMetaRaw);
|
|
6621
|
-
onProgress?.(
|
|
6622
|
-
95 + Math.round(
|
|
6623
|
-
(Object.keys(manifest.models).indexOf(model) + 1) / modelNames.length * 5
|
|
6624
|
-
),
|
|
6625
|
-
`Committed ${model}`
|
|
6626
|
-
);
|
|
6627
|
-
}
|
|
6628
|
-
await writeManifest(manifest);
|
|
6629
|
-
try {
|
|
6630
|
-
for (const model of modelNames) {
|
|
6631
|
-
await fileService.delete(
|
|
6632
|
-
`${TMP_PREFIX}/${encodeURIComponent(model)}.json`
|
|
6633
|
-
);
|
|
6634
|
-
await fileService.delete(
|
|
6635
|
-
`${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`
|
|
6636
|
-
);
|
|
6637
|
-
}
|
|
6638
|
-
await fileService.delete(`${TMP_PREFIX}/.marker`);
|
|
6639
|
-
} catch (e) {
|
|
6640
|
-
console.log("Failed to cleanup tmp import files:", e);
|
|
6641
|
-
}
|
|
6642
|
-
onProgress?.(100, "Import complete");
|
|
6643
|
-
return manifest;
|
|
6644
|
-
};
|
|
6645
|
-
var import_snapshot_default = importSnapshot;
|
|
6646
|
-
|
|
6647
6863
|
// src/services/filesystem-service/init-snapshot.ts
|
|
6648
6864
|
var isSnapshotReady = async () => {
|
|
6649
6865
|
try {
|