@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.mjs
CHANGED
|
@@ -2273,9 +2273,9 @@ function applyBinaryOp(ast, context) {
|
|
|
2273
2273
|
var DICT = {
|
|
2274
2274
|
get(...args) {
|
|
2275
2275
|
const { key, defValue } = parseArgs(args, ["key", "defValue"]);
|
|
2276
|
-
const
|
|
2277
|
-
if (key in
|
|
2278
|
-
return
|
|
2276
|
+
const self = this;
|
|
2277
|
+
if (key in self) {
|
|
2278
|
+
return self[key];
|
|
2279
2279
|
} else if (defValue !== void 0) {
|
|
2280
2280
|
return defValue;
|
|
2281
2281
|
}
|
|
@@ -2879,6 +2879,13 @@ function cleanObject(obj) {
|
|
|
2879
2879
|
}
|
|
2880
2880
|
return result;
|
|
2881
2881
|
}
|
|
2882
|
+
var extractIdFromDomain = (domain) => {
|
|
2883
|
+
if (!domain || !Array.isArray(domain)) return null;
|
|
2884
|
+
const idCond = domain.find(
|
|
2885
|
+
([field, operator]) => field === "id" && operator === "="
|
|
2886
|
+
);
|
|
2887
|
+
return idCond ? Number(idCond[2]) : null;
|
|
2888
|
+
};
|
|
2882
2889
|
|
|
2883
2890
|
// src/utils/storage/local-storage.ts
|
|
2884
2891
|
var localStorageUtils = () => {
|
|
@@ -5165,130 +5172,647 @@ var getASessionService = (env) => {
|
|
|
5165
5172
|
|
|
5166
5173
|
// src/services/pos-service/add-entity.ts
|
|
5167
5174
|
import { useCallback as useCallback12 } from "react";
|
|
5168
|
-
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
|
|
5177
|
-
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
|
|
5181
|
-
return
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
|
|
5175
|
+
|
|
5176
|
+
// src/services/filesystem-service/file-service.ts
|
|
5177
|
+
import { Directory, Encoding, Filesystem } from "@capacitor/filesystem";
|
|
5178
|
+
var fileService = {
|
|
5179
|
+
read: async (path) => {
|
|
5180
|
+
try {
|
|
5181
|
+
const res = await Filesystem.readFile({
|
|
5182
|
+
path,
|
|
5183
|
+
directory: Directory.Data,
|
|
5184
|
+
encoding: Encoding.UTF8
|
|
5185
|
+
});
|
|
5186
|
+
if (typeof res.data === "string") return res.data;
|
|
5187
|
+
if (res.data instanceof Blob) return await res.data.text();
|
|
5188
|
+
return null;
|
|
5189
|
+
} catch {
|
|
5190
|
+
return null;
|
|
5191
|
+
}
|
|
5192
|
+
},
|
|
5193
|
+
write: async (path, data) => {
|
|
5194
|
+
await Filesystem.writeFile({
|
|
5195
|
+
path,
|
|
5196
|
+
data,
|
|
5197
|
+
directory: Directory.Data,
|
|
5198
|
+
encoding: Encoding.UTF8,
|
|
5199
|
+
recursive: true
|
|
5200
|
+
});
|
|
5201
|
+
},
|
|
5202
|
+
writeAtomic: async (path, data) => {
|
|
5203
|
+
const tempPath = path + ".tmp";
|
|
5204
|
+
await Filesystem.writeFile({
|
|
5205
|
+
path: tempPath,
|
|
5206
|
+
data,
|
|
5207
|
+
directory: Directory.Data,
|
|
5208
|
+
encoding: Encoding.UTF8,
|
|
5209
|
+
recursive: true
|
|
5210
|
+
});
|
|
5211
|
+
try {
|
|
5212
|
+
await Filesystem.deleteFile({
|
|
5213
|
+
path,
|
|
5214
|
+
directory: Directory.Data
|
|
5215
|
+
});
|
|
5216
|
+
} catch {
|
|
5217
|
+
}
|
|
5218
|
+
await Filesystem.rename({
|
|
5219
|
+
from: tempPath,
|
|
5220
|
+
to: path,
|
|
5221
|
+
directory: Directory.Data
|
|
5222
|
+
});
|
|
5223
|
+
},
|
|
5224
|
+
delete: async (path) => {
|
|
5225
|
+
try {
|
|
5226
|
+
await Filesystem.deleteFile({
|
|
5227
|
+
path,
|
|
5228
|
+
directory: Directory.Data
|
|
5229
|
+
});
|
|
5230
|
+
} catch {
|
|
5231
|
+
}
|
|
5232
|
+
},
|
|
5233
|
+
exists: async (path) => {
|
|
5234
|
+
try {
|
|
5235
|
+
await Filesystem.stat({
|
|
5236
|
+
path,
|
|
5237
|
+
directory: Directory.Data
|
|
5238
|
+
});
|
|
5239
|
+
return true;
|
|
5240
|
+
} catch {
|
|
5241
|
+
return false;
|
|
5242
|
+
}
|
|
5243
|
+
},
|
|
5244
|
+
mkdir: async (path) => {
|
|
5245
|
+
try {
|
|
5246
|
+
await Filesystem.mkdir({
|
|
5247
|
+
path,
|
|
5248
|
+
directory: Directory.Data,
|
|
5249
|
+
recursive: true
|
|
5250
|
+
});
|
|
5251
|
+
} catch (e) {
|
|
5252
|
+
if (!String(e?.message).includes("Exists")) {
|
|
5253
|
+
throw e;
|
|
5254
|
+
}
|
|
5255
|
+
}
|
|
5256
|
+
},
|
|
5257
|
+
list: async (path) => {
|
|
5258
|
+
return Filesystem.readdir({
|
|
5259
|
+
path,
|
|
5260
|
+
directory: Directory.Data
|
|
5261
|
+
});
|
|
5262
|
+
},
|
|
5263
|
+
getUri: async (path) => {
|
|
5264
|
+
return Filesystem.getUri({
|
|
5265
|
+
path,
|
|
5266
|
+
directory: Directory.Data
|
|
5267
|
+
});
|
|
5268
|
+
}
|
|
5198
5269
|
};
|
|
5199
5270
|
|
|
5200
|
-
// src/services/
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
|
|
5211
|
-
|
|
5212
|
-
model: "pos_preparation_display.order" /* POS_PREPARATION_ORDER */,
|
|
5213
|
-
method: "change_order_stage" /* CHANGE_ORDER_STAGE */,
|
|
5214
|
-
ids: orderId,
|
|
5215
|
-
kwargs: {
|
|
5216
|
-
stage_id: stageId,
|
|
5217
|
-
preparation_display_id: preparationDisplayId
|
|
5271
|
+
// src/services/filesystem-service/json-worker.ts
|
|
5272
|
+
function createWorkerBlob() {
|
|
5273
|
+
const workerCode = `
|
|
5274
|
+
self.addEventListener("message", async (ev) => {
|
|
5275
|
+
const { id, cmd, payload } = ev.data;
|
|
5276
|
+
try {
|
|
5277
|
+
if (cmd === "parse") {
|
|
5278
|
+
const parsed = JSON.parse(payload);
|
|
5279
|
+
self.postMessage({ id, ok: true, result: parsed });
|
|
5280
|
+
} else if (cmd === "stringify") {
|
|
5281
|
+
const str = JSON.stringify(payload);
|
|
5282
|
+
self.postMessage({ id, ok: true, result: str });
|
|
5218
5283
|
}
|
|
5219
|
-
}
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
5284
|
+
} catch (err) {
|
|
5285
|
+
self.postMessage({ id, ok: false, error: err?.message || String(err) });
|
|
5286
|
+
}
|
|
5287
|
+
});
|
|
5288
|
+
`;
|
|
5289
|
+
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
5290
|
+
return URL.createObjectURL(blob);
|
|
5291
|
+
}
|
|
5292
|
+
function spawnParseWorker(raw) {
|
|
5293
|
+
return new Promise((resolve, reject) => {
|
|
5294
|
+
const workerUrl = createWorkerBlob();
|
|
5295
|
+
const worker = new Worker(workerUrl);
|
|
5296
|
+
const id = Math.random().toString(36).slice(2);
|
|
5297
|
+
worker.onmessage = (ev) => {
|
|
5298
|
+
const { ok, result, error } = ev.data;
|
|
5299
|
+
if (ok) {
|
|
5300
|
+
resolve(result);
|
|
5301
|
+
} else {
|
|
5302
|
+
reject(new Error(error));
|
|
5303
|
+
}
|
|
5304
|
+
URL.revokeObjectURL(workerUrl);
|
|
5305
|
+
worker.terminate();
|
|
5306
|
+
};
|
|
5307
|
+
worker.onerror = (err) => {
|
|
5308
|
+
reject(err);
|
|
5309
|
+
URL.revokeObjectURL(workerUrl);
|
|
5310
|
+
worker.terminate();
|
|
5311
|
+
};
|
|
5312
|
+
worker.postMessage({ id, cmd: "parse", payload: raw });
|
|
5313
|
+
});
|
|
5314
|
+
}
|
|
5315
|
+
function spawnStringifyWorker(obj) {
|
|
5316
|
+
return new Promise((resolve, reject) => {
|
|
5317
|
+
const workerUrl = createWorkerBlob();
|
|
5318
|
+
const worker = new Worker(workerUrl);
|
|
5319
|
+
worker.onmessage = (ev) => {
|
|
5320
|
+
const { ok, result, error } = ev.data;
|
|
5321
|
+
if (ok) resolve(result);
|
|
5322
|
+
else reject(new Error(error));
|
|
5323
|
+
URL.revokeObjectURL(workerUrl);
|
|
5324
|
+
worker.terminate();
|
|
5325
|
+
};
|
|
5326
|
+
worker.onerror = (err) => {
|
|
5327
|
+
reject(err);
|
|
5328
|
+
URL.revokeObjectURL(workerUrl);
|
|
5329
|
+
worker.terminate();
|
|
5330
|
+
};
|
|
5331
|
+
worker.postMessage({ cmd: "stringify", payload: obj });
|
|
5332
|
+
});
|
|
5333
|
+
}
|
|
5238
5334
|
|
|
5239
|
-
// src/services/
|
|
5240
|
-
|
|
5241
|
-
var
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
|
|
5252
|
-
|
|
5253
|
-
ids,
|
|
5254
|
-
with_context: withContext
|
|
5255
|
-
};
|
|
5256
|
-
return env?.requests.post(
|
|
5257
|
-
"/call" /* CALL_PATH */,
|
|
5258
|
-
jsonData,
|
|
5259
|
-
{
|
|
5260
|
-
headers: {
|
|
5261
|
-
"Content-Type": "application/json",
|
|
5262
|
-
...xNode ? { "X-Node": xNode } : {}
|
|
5263
|
-
}
|
|
5264
|
-
},
|
|
5265
|
-
service
|
|
5266
|
-
);
|
|
5267
|
-
},
|
|
5268
|
-
[env]
|
|
5269
|
-
);
|
|
5270
|
-
return {
|
|
5271
|
-
checkPayment
|
|
5272
|
-
};
|
|
5273
|
-
};
|
|
5335
|
+
// src/services/filesystem-service/manifest.ts
|
|
5336
|
+
var MANIFEST_PATH = "pos/manifest.json";
|
|
5337
|
+
var MANIFEST_BAK_PATH = "pos/manifest.bak.json";
|
|
5338
|
+
async function writeManifest(manifest) {
|
|
5339
|
+
const oldRaw = await fileService.read(MANIFEST_PATH);
|
|
5340
|
+
if (oldRaw !== null) {
|
|
5341
|
+
await fileService.writeAtomic(MANIFEST_BAK_PATH, oldRaw);
|
|
5342
|
+
}
|
|
5343
|
+
await fileService.writeAtomic(MANIFEST_PATH, JSON.stringify(manifest));
|
|
5344
|
+
try {
|
|
5345
|
+
await fileService.delete(MANIFEST_BAK_PATH);
|
|
5346
|
+
} catch {
|
|
5347
|
+
}
|
|
5348
|
+
}
|
|
5274
5349
|
|
|
5275
|
-
// src/services/
|
|
5276
|
-
|
|
5277
|
-
var
|
|
5278
|
-
|
|
5279
|
-
|
|
5280
|
-
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5350
|
+
// src/services/filesystem-service/import-snapshot.ts
|
|
5351
|
+
var DATA_DIR = "pos";
|
|
5352
|
+
var MODELS_DIR = `${DATA_DIR}/models`;
|
|
5353
|
+
var MODELS_META_DIR = `${DATA_DIR}/models_meta`;
|
|
5354
|
+
var importSnapshot = async ({ data, onProgress }) => {
|
|
5355
|
+
onProgress?.(1, "Parsing snapshot");
|
|
5356
|
+
const parsed = await spawnParseWorker(data);
|
|
5357
|
+
const modelNames = Object.keys(parsed);
|
|
5358
|
+
const total = modelNames.length;
|
|
5359
|
+
const manifest = { version: (/* @__PURE__ */ new Date()).toISOString(), models: {} };
|
|
5360
|
+
const TMP_PREFIX = `pos/data/tmp_import_${Date.now()}`;
|
|
5361
|
+
await fileService.writeAtomic(`${TMP_PREFIX}/.marker`, "1");
|
|
5362
|
+
let i = 0;
|
|
5363
|
+
for (const model of modelNames) {
|
|
5364
|
+
i++;
|
|
5365
|
+
onProgress?.(
|
|
5366
|
+
Math.round(i / total * 100),
|
|
5367
|
+
`Processing ${model} (${i}/${total})`
|
|
5368
|
+
);
|
|
5369
|
+
const block = parsed[model];
|
|
5370
|
+
const dataPart = block?.data ?? block ?? [];
|
|
5371
|
+
const fields = block?.fields ?? [];
|
|
5372
|
+
const relations = block?.relations ?? {};
|
|
5373
|
+
const serialized = await spawnStringifyWorker(dataPart);
|
|
5374
|
+
const tmpModelPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.json`;
|
|
5375
|
+
await fileService.writeAtomic(tmpModelPath, serialized);
|
|
5376
|
+
const meta = {
|
|
5377
|
+
fields,
|
|
5378
|
+
relations,
|
|
5379
|
+
count: Array.isArray(dataPart) ? dataPart.length : 0,
|
|
5380
|
+
writtenAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
5381
|
+
};
|
|
5382
|
+
const tmpMetaPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`;
|
|
5383
|
+
await fileService.writeAtomic(tmpMetaPath, JSON.stringify(meta));
|
|
5384
|
+
manifest.models[model] = {
|
|
5385
|
+
file: `${MODELS_DIR}/${encodeURIComponent(model)}.json`,
|
|
5386
|
+
metaFile: `${MODELS_META_DIR}/${encodeURIComponent(model)}.meta.json`,
|
|
5387
|
+
count: meta.count,
|
|
5388
|
+
updatedAt: meta.writtenAt
|
|
5389
|
+
};
|
|
5390
|
+
}
|
|
5391
|
+
onProgress?.(95, "Committing import (moving files)");
|
|
5392
|
+
for (const model of modelNames) {
|
|
5393
|
+
const tmpModelPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.json`;
|
|
5394
|
+
const finalModelPath = `${MODELS_DIR}/${encodeURIComponent(model)}.json`;
|
|
5395
|
+
const tmpMetaPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`;
|
|
5396
|
+
const finalMetaPath = `${MODELS_META_DIR}/${encodeURIComponent(
|
|
5397
|
+
model
|
|
5398
|
+
)}.meta.json`;
|
|
5399
|
+
const tmpRaw = await fileService.read(tmpModelPath);
|
|
5400
|
+
if (tmpRaw !== null) await fileService.writeAtomic(finalModelPath, tmpRaw);
|
|
5401
|
+
const tmpMetaRaw = await fileService.read(tmpMetaPath);
|
|
5402
|
+
if (tmpMetaRaw !== null)
|
|
5403
|
+
await fileService.writeAtomic(finalMetaPath, tmpMetaRaw);
|
|
5404
|
+
onProgress?.(
|
|
5405
|
+
95 + Math.round(
|
|
5406
|
+
(Object.keys(manifest.models).indexOf(model) + 1) / modelNames.length * 5
|
|
5407
|
+
),
|
|
5408
|
+
`Committed ${model}`
|
|
5409
|
+
);
|
|
5410
|
+
}
|
|
5411
|
+
await writeManifest(manifest);
|
|
5412
|
+
try {
|
|
5413
|
+
for (const model of modelNames) {
|
|
5414
|
+
await fileService.delete(
|
|
5415
|
+
`${TMP_PREFIX}/${encodeURIComponent(model)}.json`
|
|
5416
|
+
);
|
|
5417
|
+
await fileService.delete(
|
|
5418
|
+
`${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`
|
|
5419
|
+
);
|
|
5420
|
+
}
|
|
5421
|
+
await fileService.delete(`${TMP_PREFIX}/.marker`);
|
|
5422
|
+
} catch (e) {
|
|
5423
|
+
console.log("Failed to cleanup tmp import files:", e);
|
|
5424
|
+
}
|
|
5425
|
+
onProgress?.(100, "Import complete");
|
|
5426
|
+
return manifest;
|
|
5427
|
+
};
|
|
5428
|
+
var import_snapshot_default = importSnapshot;
|
|
5429
|
+
|
|
5430
|
+
// src/services/filesystem-service/memory-cache.ts
|
|
5431
|
+
var MemoryCache = class {
|
|
5432
|
+
map = /* @__PURE__ */ new Map();
|
|
5433
|
+
get(k) {
|
|
5434
|
+
const e = this.map.get(k);
|
|
5435
|
+
if (!e) return null;
|
|
5436
|
+
if (e.ttl && Date.now() - e.t > e.ttl) {
|
|
5437
|
+
this.map.delete(k);
|
|
5438
|
+
return null;
|
|
5439
|
+
}
|
|
5440
|
+
return e.value;
|
|
5441
|
+
}
|
|
5442
|
+
set(k, v, ttl = 5 * 60 * 1e3) {
|
|
5443
|
+
this.map.set(k, { value: v, t: Date.now(), ttl });
|
|
5444
|
+
}
|
|
5445
|
+
del(k) {
|
|
5446
|
+
this.map.delete(k);
|
|
5447
|
+
}
|
|
5448
|
+
clear() {
|
|
5449
|
+
this.map.clear();
|
|
5450
|
+
}
|
|
5451
|
+
};
|
|
5452
|
+
var memoryCache = new MemoryCache();
|
|
5453
|
+
|
|
5454
|
+
// src/services/filesystem-service/model-loader.ts
|
|
5455
|
+
var MODELS_DIR2 = "pos/models";
|
|
5456
|
+
var MODELS_META_DIR2 = "pos/models_meta";
|
|
5457
|
+
async function loadModelData(modelName, includeMeta = true) {
|
|
5458
|
+
const key = `model:${modelName}:meta:${includeMeta}`;
|
|
5459
|
+
const cached = memoryCache.get(key);
|
|
5460
|
+
if (cached) return cached;
|
|
5461
|
+
const dataPath = `${MODELS_DIR2}/${encodeURIComponent(modelName)}.json`;
|
|
5462
|
+
const metaPath = `${MODELS_META_DIR2}/${encodeURIComponent(
|
|
5463
|
+
modelName
|
|
5464
|
+
)}.meta.json`;
|
|
5465
|
+
const rawData = await fileService.read(dataPath);
|
|
5466
|
+
if (!rawData) return null;
|
|
5467
|
+
const parsedData = await spawnParseWorker(rawData);
|
|
5468
|
+
const data = Array.isArray(parsedData) ? parsedData : [];
|
|
5469
|
+
if (!includeMeta) {
|
|
5470
|
+
const result2 = { data };
|
|
5471
|
+
memoryCache.set(key, result2, 1e3 * 60 * 60);
|
|
5472
|
+
return result2;
|
|
5473
|
+
}
|
|
5474
|
+
const rawMeta = await fileService.read(metaPath);
|
|
5475
|
+
let fields = [];
|
|
5476
|
+
let relations = {};
|
|
5477
|
+
if (rawMeta) {
|
|
5478
|
+
const parsedMeta = await spawnParseWorker(rawMeta);
|
|
5479
|
+
fields = parsedMeta?.fields ?? [];
|
|
5480
|
+
relations = parsedMeta?.relations ?? {};
|
|
5481
|
+
}
|
|
5482
|
+
const result = {
|
|
5483
|
+
data,
|
|
5484
|
+
fields,
|
|
5485
|
+
relations
|
|
5486
|
+
};
|
|
5487
|
+
memoryCache.set(key, result, 1e3 * 60 * 60);
|
|
5488
|
+
return result;
|
|
5489
|
+
}
|
|
5490
|
+
async function loadData(includeMeta = true) {
|
|
5491
|
+
try {
|
|
5492
|
+
const listResult = await fileService.list(MODELS_DIR2);
|
|
5493
|
+
if (!listResult || !Array.isArray(listResult.files)) {
|
|
5494
|
+
console.log("No models found");
|
|
5495
|
+
return {};
|
|
5496
|
+
}
|
|
5497
|
+
const result = {};
|
|
5498
|
+
for (const file of listResult.files) {
|
|
5499
|
+
if (file.type !== "file") continue;
|
|
5500
|
+
if (!file.name.endsWith(".json")) continue;
|
|
5501
|
+
const fileName = file.name;
|
|
5502
|
+
const modelName = fileName.replace(/\.json$/, "");
|
|
5503
|
+
const dataPath = `${MODELS_DIR2}/${fileName}`;
|
|
5504
|
+
const rawData = await fileService.read(dataPath);
|
|
5505
|
+
if (!rawData) continue;
|
|
5506
|
+
const parsedData = await spawnParseWorker(rawData);
|
|
5507
|
+
const data = Array.isArray(parsedData) ? parsedData : [];
|
|
5508
|
+
if (!includeMeta) {
|
|
5509
|
+
result[modelName] = { data };
|
|
5510
|
+
continue;
|
|
5511
|
+
}
|
|
5512
|
+
const metaPath = `${MODELS_META_DIR2}/${encodeURIComponent(
|
|
5513
|
+
modelName
|
|
5514
|
+
)}.meta.json`;
|
|
5515
|
+
const rawMeta = await fileService.read(metaPath);
|
|
5516
|
+
let fields = [];
|
|
5517
|
+
let relations = {};
|
|
5518
|
+
if (rawMeta) {
|
|
5519
|
+
const parsedMeta = await spawnParseWorker(rawMeta);
|
|
5520
|
+
fields = parsedMeta?.fields ?? [];
|
|
5521
|
+
relations = parsedMeta?.relations ?? {};
|
|
5522
|
+
}
|
|
5523
|
+
result[modelName] = {
|
|
5524
|
+
data,
|
|
5525
|
+
fields,
|
|
5526
|
+
relations
|
|
5527
|
+
};
|
|
5528
|
+
}
|
|
5529
|
+
return result;
|
|
5530
|
+
} catch (error) {
|
|
5531
|
+
console.error("Error loading data:", error);
|
|
5532
|
+
throw error;
|
|
5533
|
+
}
|
|
5534
|
+
}
|
|
5535
|
+
|
|
5536
|
+
// src/services/filesystem-service/snapshot-helper.ts
|
|
5537
|
+
var createEmptySnapshot = () => {
|
|
5538
|
+
return {
|
|
5539
|
+
data: []
|
|
5540
|
+
};
|
|
5541
|
+
};
|
|
5542
|
+
var generateNextId = (existingIds, startFrom = 1) => {
|
|
5543
|
+
if (!existingIds || existingIds.length === 0) {
|
|
5544
|
+
return startFrom;
|
|
5545
|
+
}
|
|
5546
|
+
const maxId = Math.max(...existingIds, startFrom - 1);
|
|
5547
|
+
return maxId + 1;
|
|
5548
|
+
};
|
|
5549
|
+
var loadSnapshot = async ({
|
|
5550
|
+
modelName
|
|
5551
|
+
}) => {
|
|
5552
|
+
try {
|
|
5553
|
+
const snapshot = await loadModelData(modelName);
|
|
5554
|
+
if (!snapshot || typeof snapshot !== "object") {
|
|
5555
|
+
console.warn("invalid snapshot, creating new one");
|
|
5556
|
+
return createEmptySnapshot();
|
|
5557
|
+
}
|
|
5558
|
+
return {
|
|
5559
|
+
data: Array.isArray(snapshot.data) ? snapshot.data : []
|
|
5560
|
+
};
|
|
5561
|
+
} catch (error) {
|
|
5562
|
+
console.error("Failed to load snapshot:", error);
|
|
5563
|
+
return createEmptySnapshot();
|
|
5564
|
+
}
|
|
5565
|
+
};
|
|
5566
|
+
var getExistingIds = (snapshot) => {
|
|
5567
|
+
return snapshot.data.map((order) => order.id).filter((id) => typeof id === "number");
|
|
5568
|
+
};
|
|
5569
|
+
var saveSnapshot = async ({
|
|
5570
|
+
snapshot,
|
|
5571
|
+
modelName
|
|
5572
|
+
}) => {
|
|
5573
|
+
try {
|
|
5574
|
+
await import_snapshot_default({
|
|
5575
|
+
data: JSON.stringify({
|
|
5576
|
+
[modelName]: snapshot
|
|
5577
|
+
})
|
|
5578
|
+
});
|
|
5579
|
+
return true;
|
|
5580
|
+
} catch (error) {
|
|
5581
|
+
console.error("failed to save snapshot:", error);
|
|
5582
|
+
return false;
|
|
5583
|
+
}
|
|
5584
|
+
};
|
|
5585
|
+
|
|
5586
|
+
// src/services/filesystem-service/model-repository.ts
|
|
5587
|
+
var ModelRepository = class {
|
|
5588
|
+
getRecord = async ({
|
|
5589
|
+
id,
|
|
5590
|
+
modelName
|
|
5591
|
+
}) => {
|
|
5592
|
+
try {
|
|
5593
|
+
const snapshot = await loadSnapshot({
|
|
5594
|
+
modelName
|
|
5595
|
+
});
|
|
5596
|
+
return snapshot.data.find((record) => record.id === id) || null;
|
|
5597
|
+
} catch (error) {
|
|
5598
|
+
console.error("failed to get record:", error);
|
|
5599
|
+
return null;
|
|
5600
|
+
}
|
|
5601
|
+
};
|
|
5602
|
+
addRecord = async ({
|
|
5603
|
+
newRecord,
|
|
5604
|
+
modelName
|
|
5605
|
+
}) => {
|
|
5606
|
+
try {
|
|
5607
|
+
const snapshot = await loadSnapshot({
|
|
5608
|
+
modelName
|
|
5609
|
+
});
|
|
5610
|
+
const existingIds = getExistingIds(snapshot);
|
|
5611
|
+
const newId = generateNextId(existingIds, snapshot.data.length);
|
|
5612
|
+
snapshot.data.push({
|
|
5613
|
+
...newRecord,
|
|
5614
|
+
id: newId
|
|
5615
|
+
});
|
|
5616
|
+
const saved = await saveSnapshot({
|
|
5617
|
+
snapshot,
|
|
5618
|
+
modelName
|
|
5619
|
+
});
|
|
5620
|
+
if (!saved) {
|
|
5621
|
+
console.error("failed to add new record");
|
|
5622
|
+
return [];
|
|
5623
|
+
}
|
|
5624
|
+
console.log(`\u2705 ${snapshot.data.length} records saved`);
|
|
5625
|
+
return snapshot.data;
|
|
5626
|
+
} catch (error) {
|
|
5627
|
+
console.error("failed to add new record:", error);
|
|
5628
|
+
return [];
|
|
5629
|
+
}
|
|
5630
|
+
};
|
|
5631
|
+
updateRecord = async ({
|
|
5632
|
+
id,
|
|
5633
|
+
update,
|
|
5634
|
+
modelName
|
|
5635
|
+
}) => {
|
|
5636
|
+
try {
|
|
5637
|
+
const snapshot = await loadSnapshot({
|
|
5638
|
+
modelName
|
|
5639
|
+
});
|
|
5640
|
+
const index = snapshot.data.findIndex((record) => record.id === id);
|
|
5641
|
+
if (index === -1) {
|
|
5642
|
+
console.error(`record with id ${id} not found`);
|
|
5643
|
+
return false;
|
|
5644
|
+
}
|
|
5645
|
+
snapshot.data[index] = {
|
|
5646
|
+
...snapshot.data[index],
|
|
5647
|
+
...update
|
|
5648
|
+
};
|
|
5649
|
+
return await saveSnapshot({
|
|
5650
|
+
snapshot,
|
|
5651
|
+
modelName
|
|
5652
|
+
});
|
|
5653
|
+
} catch (error) {
|
|
5654
|
+
console.error("error updating record:", error);
|
|
5655
|
+
return false;
|
|
5656
|
+
}
|
|
5657
|
+
};
|
|
5658
|
+
deleteRecord = async ({
|
|
5659
|
+
id,
|
|
5660
|
+
modelName
|
|
5661
|
+
}) => {
|
|
5662
|
+
try {
|
|
5663
|
+
const snapshot = await loadSnapshot({
|
|
5664
|
+
modelName
|
|
5665
|
+
});
|
|
5666
|
+
const before = snapshot.data.length;
|
|
5667
|
+
snapshot.data = snapshot.data.filter((record) => record.id !== id);
|
|
5668
|
+
if (snapshot.data.length === before) {
|
|
5669
|
+
console.error(`record with id ${id} not found`);
|
|
5670
|
+
return false;
|
|
5671
|
+
}
|
|
5672
|
+
return await saveSnapshot({
|
|
5673
|
+
snapshot,
|
|
5674
|
+
modelName
|
|
5675
|
+
});
|
|
5676
|
+
} catch (error) {
|
|
5677
|
+
console.error("error deleting record:", error);
|
|
5678
|
+
return false;
|
|
5679
|
+
}
|
|
5680
|
+
};
|
|
5681
|
+
};
|
|
5682
|
+
|
|
5683
|
+
// src/services/pos-service/add-entity.ts
|
|
5684
|
+
var addEntityService = (env) => {
|
|
5685
|
+
const isLocalMode = env?.isLocalMode;
|
|
5686
|
+
const repo = new ModelRepository();
|
|
5687
|
+
const addEntity = useCallback12(
|
|
5688
|
+
({
|
|
5689
|
+
model,
|
|
5690
|
+
values,
|
|
5691
|
+
xNode,
|
|
5692
|
+
service,
|
|
5693
|
+
isCreateEndpoint = false
|
|
5694
|
+
}) => {
|
|
5695
|
+
if (isLocalMode) {
|
|
5696
|
+
return repo.addRecord({
|
|
5697
|
+
newRecord: values,
|
|
5698
|
+
modelName: model
|
|
5699
|
+
});
|
|
5700
|
+
}
|
|
5701
|
+
const jsonData = {
|
|
5702
|
+
model,
|
|
5703
|
+
values
|
|
5704
|
+
};
|
|
5705
|
+
return env?.requests.post(
|
|
5706
|
+
isCreateEndpoint ? "/create" /* CREATE_PATH */ : "/call" /* CALL_PATH */,
|
|
5707
|
+
jsonData,
|
|
5708
|
+
{
|
|
5709
|
+
headers: {
|
|
5710
|
+
"Content-Type": "application/json",
|
|
5711
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
5712
|
+
}
|
|
5713
|
+
},
|
|
5714
|
+
service
|
|
5715
|
+
);
|
|
5716
|
+
},
|
|
5717
|
+
[env, isLocalMode]
|
|
5718
|
+
);
|
|
5719
|
+
return {
|
|
5720
|
+
addEntity
|
|
5721
|
+
};
|
|
5722
|
+
};
|
|
5723
|
+
|
|
5724
|
+
// src/services/pos-service/change-order-preparation-state.ts
|
|
5725
|
+
import { useCallback as useCallback13 } from "react";
|
|
5726
|
+
var changOrderPreparationStateService = (env) => {
|
|
5727
|
+
const changeOrderPreparationState = useCallback13(
|
|
5728
|
+
({
|
|
5729
|
+
orderId,
|
|
5730
|
+
stageId,
|
|
5731
|
+
preparationDisplayId,
|
|
5732
|
+
xNode,
|
|
5733
|
+
service
|
|
5734
|
+
}) => {
|
|
5735
|
+
const jsonData = {
|
|
5736
|
+
model: "pos_preparation_display.order" /* POS_PREPARATION_ORDER */,
|
|
5737
|
+
method: "change_order_stage" /* CHANGE_ORDER_STAGE */,
|
|
5738
|
+
ids: orderId,
|
|
5739
|
+
kwargs: {
|
|
5740
|
+
stage_id: stageId,
|
|
5741
|
+
preparation_display_id: preparationDisplayId
|
|
5742
|
+
}
|
|
5743
|
+
};
|
|
5744
|
+
return env?.requests.post(
|
|
5745
|
+
"/call" /* CALL_PATH */,
|
|
5746
|
+
jsonData,
|
|
5747
|
+
{
|
|
5748
|
+
headers: {
|
|
5749
|
+
"Content-Type": "application/json",
|
|
5750
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
5751
|
+
}
|
|
5752
|
+
},
|
|
5753
|
+
service
|
|
5754
|
+
);
|
|
5755
|
+
},
|
|
5756
|
+
[env]
|
|
5757
|
+
);
|
|
5758
|
+
return {
|
|
5759
|
+
changeOrderPreparationState
|
|
5760
|
+
};
|
|
5761
|
+
};
|
|
5762
|
+
|
|
5763
|
+
// src/services/pos-service/check-payment.ts
|
|
5764
|
+
import { useCallback as useCallback14 } from "react";
|
|
5765
|
+
var checkPaymentService = (env) => {
|
|
5766
|
+
const checkPayment = useCallback14(
|
|
5767
|
+
({
|
|
5768
|
+
model,
|
|
5769
|
+
ids,
|
|
5770
|
+
withContext,
|
|
5771
|
+
xNode,
|
|
5772
|
+
service
|
|
5773
|
+
}) => {
|
|
5774
|
+
const jsonData = {
|
|
5775
|
+
model,
|
|
5776
|
+
method: "check" /* CHECK */,
|
|
5777
|
+
ids,
|
|
5778
|
+
with_context: withContext
|
|
5779
|
+
};
|
|
5780
|
+
return env?.requests.post(
|
|
5781
|
+
"/call" /* CALL_PATH */,
|
|
5782
|
+
jsonData,
|
|
5783
|
+
{
|
|
5784
|
+
headers: {
|
|
5785
|
+
"Content-Type": "application/json",
|
|
5786
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
5787
|
+
}
|
|
5788
|
+
},
|
|
5789
|
+
service
|
|
5790
|
+
);
|
|
5791
|
+
},
|
|
5792
|
+
[env]
|
|
5793
|
+
);
|
|
5794
|
+
return {
|
|
5795
|
+
checkPayment
|
|
5796
|
+
};
|
|
5797
|
+
};
|
|
5798
|
+
|
|
5799
|
+
// src/services/pos-service/create-e-invoice.ts
|
|
5800
|
+
import { useCallback as useCallback15 } from "react";
|
|
5801
|
+
var createEInvoiceService = (env) => {
|
|
5802
|
+
const createEInvoice = useCallback15(
|
|
5803
|
+
async ({
|
|
5804
|
+
service,
|
|
5805
|
+
xNode,
|
|
5806
|
+
kwargs,
|
|
5807
|
+
ids,
|
|
5808
|
+
withContext
|
|
5809
|
+
}) => {
|
|
5810
|
+
const body = {
|
|
5811
|
+
model: "pos.order" /* POS_ORDER */,
|
|
5812
|
+
method: "create_e_invoice" /* CREATE_E_INVOICE */,
|
|
5813
|
+
kwargs,
|
|
5814
|
+
ids,
|
|
5815
|
+
with_context: withContext
|
|
5292
5816
|
};
|
|
5293
5817
|
return env?.requests?.post(
|
|
5294
5818
|
`${"/call" /* CALL_PATH */}`,
|
|
@@ -5312,6 +5836,8 @@ var createEInvoiceService = (env) => {
|
|
|
5312
5836
|
// src/services/pos-service/create-entity.ts
|
|
5313
5837
|
import { useCallback as useCallback16 } from "react";
|
|
5314
5838
|
var createEntityService = (env) => {
|
|
5839
|
+
const isLocalMode = env?.isLocalMode;
|
|
5840
|
+
const repo = new ModelRepository();
|
|
5315
5841
|
const createEntity = useCallback16(
|
|
5316
5842
|
({
|
|
5317
5843
|
model,
|
|
@@ -5319,6 +5845,12 @@ var createEntityService = (env) => {
|
|
|
5319
5845
|
xNode,
|
|
5320
5846
|
service
|
|
5321
5847
|
}) => {
|
|
5848
|
+
if (isLocalMode) {
|
|
5849
|
+
return repo.addRecord({
|
|
5850
|
+
newRecord: args,
|
|
5851
|
+
modelName: model
|
|
5852
|
+
});
|
|
5853
|
+
}
|
|
5322
5854
|
const jsonData = {
|
|
5323
5855
|
model,
|
|
5324
5856
|
method: "create" /* CREATE */,
|
|
@@ -5336,7 +5868,7 @@ var createEntityService = (env) => {
|
|
|
5336
5868
|
service
|
|
5337
5869
|
);
|
|
5338
5870
|
},
|
|
5339
|
-
[env]
|
|
5871
|
+
[env, isLocalMode]
|
|
5340
5872
|
);
|
|
5341
5873
|
return {
|
|
5342
5874
|
createEntity
|
|
@@ -5421,6 +5953,8 @@ var createSessionService = (env) => {
|
|
|
5421
5953
|
// src/services/pos-service/delete-entity.ts
|
|
5422
5954
|
import { useCallback as useCallback19 } from "react";
|
|
5423
5955
|
var deleteEntityService = (env) => {
|
|
5956
|
+
const isLocalMode = env?.isLocalMode;
|
|
5957
|
+
const repo = new ModelRepository();
|
|
5424
5958
|
const deleteEntity = useCallback19(
|
|
5425
5959
|
({
|
|
5426
5960
|
model,
|
|
@@ -5429,6 +5963,14 @@ var deleteEntityService = (env) => {
|
|
|
5429
5963
|
service,
|
|
5430
5964
|
method
|
|
5431
5965
|
}) => {
|
|
5966
|
+
if (isLocalMode) {
|
|
5967
|
+
const id = ids[0];
|
|
5968
|
+
if (!id) return;
|
|
5969
|
+
return repo.deleteRecord({
|
|
5970
|
+
modelName: model,
|
|
5971
|
+
id
|
|
5972
|
+
});
|
|
5973
|
+
}
|
|
5432
5974
|
const jsonData = {
|
|
5433
5975
|
model,
|
|
5434
5976
|
ids,
|
|
@@ -5446,7 +5988,7 @@ var deleteEntityService = (env) => {
|
|
|
5446
5988
|
service
|
|
5447
5989
|
);
|
|
5448
5990
|
},
|
|
5449
|
-
[env]
|
|
5991
|
+
[env, isLocalMode]
|
|
5450
5992
|
);
|
|
5451
5993
|
return {
|
|
5452
5994
|
deleteEntity
|
|
@@ -5779,340 +6321,111 @@ var handleCloseSessionService = (env) => {
|
|
|
5779
6321
|
const handleCloseSession = useCallback28(
|
|
5780
6322
|
({
|
|
5781
6323
|
model,
|
|
5782
|
-
ids,
|
|
5783
|
-
xNode,
|
|
5784
|
-
service,
|
|
5785
|
-
method
|
|
5786
|
-
}) => {
|
|
5787
|
-
const jsonData = {
|
|
5788
|
-
model,
|
|
5789
|
-
ids,
|
|
5790
|
-
method
|
|
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
|
-
handleCloseSession
|
|
5808
|
-
};
|
|
5809
|
-
};
|
|
5810
|
-
|
|
5811
|
-
// src/services/pos-service/handle-closing-detail-session.ts
|
|
5812
|
-
import { useCallback as useCallback29 } from "react";
|
|
5813
|
-
var handleClosingDetailSessionService = (env) => {
|
|
5814
|
-
const handleClosingDetailSession = useCallback29(
|
|
5815
|
-
({
|
|
5816
|
-
model,
|
|
5817
|
-
ids,
|
|
5818
|
-
method,
|
|
5819
|
-
xNode,
|
|
5820
|
-
service,
|
|
5821
|
-
kwargs
|
|
5822
|
-
}) => {
|
|
5823
|
-
const jsonData = {
|
|
5824
|
-
model,
|
|
5825
|
-
ids,
|
|
5826
|
-
method,
|
|
5827
|
-
kwargs
|
|
5828
|
-
};
|
|
5829
|
-
return env?.requests.post(
|
|
5830
|
-
"/call" /* CALL_PATH */,
|
|
5831
|
-
jsonData,
|
|
5832
|
-
{
|
|
5833
|
-
headers: {
|
|
5834
|
-
"Content-Type": "application/json",
|
|
5835
|
-
...xNode ? { "X-Node": xNode } : {}
|
|
5836
|
-
}
|
|
5837
|
-
},
|
|
5838
|
-
service
|
|
5839
|
-
);
|
|
5840
|
-
},
|
|
5841
|
-
[env]
|
|
5842
|
-
);
|
|
5843
|
-
return {
|
|
5844
|
-
handleClosingDetailSession
|
|
5845
|
-
};
|
|
5846
|
-
};
|
|
5847
|
-
|
|
5848
|
-
// src/services/pos-service/handle-closing-session.ts
|
|
5849
|
-
import { useCallback as useCallback30 } from "react";
|
|
5850
|
-
var handleClosingSessionService = (env) => {
|
|
5851
|
-
const handleClosingSession = useCallback30(
|
|
5852
|
-
({
|
|
5853
|
-
model,
|
|
5854
|
-
method,
|
|
5855
|
-
ids,
|
|
5856
|
-
kwargs,
|
|
5857
|
-
xNode,
|
|
5858
|
-
service
|
|
5859
|
-
}) => {
|
|
5860
|
-
const jsonData = {
|
|
5861
|
-
model,
|
|
5862
|
-
method,
|
|
5863
|
-
ids,
|
|
5864
|
-
kwargs
|
|
5865
|
-
};
|
|
5866
|
-
return env?.requests.post(
|
|
5867
|
-
"/call" /* CALL_PATH */,
|
|
5868
|
-
jsonData,
|
|
5869
|
-
{
|
|
5870
|
-
headers: {
|
|
5871
|
-
"Content-Type": "application/json",
|
|
5872
|
-
...xNode ? { "X-Node": xNode } : {}
|
|
5873
|
-
}
|
|
5874
|
-
},
|
|
5875
|
-
service
|
|
5876
|
-
);
|
|
5877
|
-
},
|
|
5878
|
-
[env]
|
|
5879
|
-
);
|
|
5880
|
-
return {
|
|
5881
|
-
handleClosingSession
|
|
5882
|
-
};
|
|
5883
|
-
};
|
|
5884
|
-
|
|
5885
|
-
// src/services/pos-service/load-data-pos-session.ts
|
|
5886
|
-
import { useCallback as useCallback31 } from "react";
|
|
5887
|
-
|
|
5888
|
-
// src/services/filesystem-service/file-service.ts
|
|
5889
|
-
import { Directory, Encoding, Filesystem } from "@capacitor/filesystem";
|
|
5890
|
-
var fileService = {
|
|
5891
|
-
async read(path) {
|
|
5892
|
-
try {
|
|
5893
|
-
const res = await Filesystem.readFile({
|
|
5894
|
-
path,
|
|
5895
|
-
directory: Directory.Data,
|
|
5896
|
-
encoding: Encoding.UTF8
|
|
5897
|
-
});
|
|
5898
|
-
if (typeof res.data === "string") return res.data;
|
|
5899
|
-
if (res.data instanceof Blob) return await res.data.text();
|
|
5900
|
-
return null;
|
|
5901
|
-
} catch {
|
|
5902
|
-
return null;
|
|
5903
|
-
}
|
|
5904
|
-
},
|
|
5905
|
-
async write(path, data) {
|
|
5906
|
-
await Filesystem.writeFile({
|
|
5907
|
-
path,
|
|
5908
|
-
data,
|
|
5909
|
-
directory: Directory.Data,
|
|
5910
|
-
encoding: Encoding.UTF8,
|
|
5911
|
-
recursive: true
|
|
5912
|
-
});
|
|
5913
|
-
},
|
|
5914
|
-
async writeAtomic(path, data) {
|
|
5915
|
-
const tempPath = path + ".tmp";
|
|
5916
|
-
await Filesystem.writeFile({
|
|
5917
|
-
path: tempPath,
|
|
5918
|
-
data,
|
|
5919
|
-
directory: Directory.Data,
|
|
5920
|
-
encoding: Encoding.UTF8,
|
|
5921
|
-
recursive: true
|
|
5922
|
-
});
|
|
5923
|
-
try {
|
|
5924
|
-
await Filesystem.deleteFile({
|
|
5925
|
-
path,
|
|
5926
|
-
directory: Directory.Data
|
|
5927
|
-
});
|
|
5928
|
-
} catch {
|
|
5929
|
-
}
|
|
5930
|
-
await Filesystem.rename({
|
|
5931
|
-
from: tempPath,
|
|
5932
|
-
to: path,
|
|
5933
|
-
directory: Directory.Data
|
|
5934
|
-
});
|
|
5935
|
-
},
|
|
5936
|
-
async delete(path) {
|
|
5937
|
-
try {
|
|
5938
|
-
await Filesystem.deleteFile({
|
|
5939
|
-
path,
|
|
5940
|
-
directory: Directory.Data
|
|
5941
|
-
});
|
|
5942
|
-
} catch {
|
|
5943
|
-
}
|
|
5944
|
-
},
|
|
5945
|
-
async exists(path) {
|
|
5946
|
-
try {
|
|
5947
|
-
await Filesystem.stat({
|
|
5948
|
-
path,
|
|
5949
|
-
directory: Directory.Data
|
|
5950
|
-
});
|
|
5951
|
-
return true;
|
|
5952
|
-
} catch {
|
|
5953
|
-
return false;
|
|
5954
|
-
}
|
|
5955
|
-
},
|
|
5956
|
-
async mkdir(path) {
|
|
5957
|
-
try {
|
|
5958
|
-
await Filesystem.mkdir({
|
|
5959
|
-
path,
|
|
5960
|
-
directory: Directory.Data,
|
|
5961
|
-
recursive: true
|
|
5962
|
-
});
|
|
5963
|
-
} catch (e) {
|
|
5964
|
-
if (!String(e?.message).includes("Exists")) {
|
|
5965
|
-
throw e;
|
|
5966
|
-
}
|
|
5967
|
-
}
|
|
5968
|
-
},
|
|
5969
|
-
async list(path) {
|
|
5970
|
-
return Filesystem.readdir({
|
|
5971
|
-
path,
|
|
5972
|
-
directory: Directory.Data
|
|
5973
|
-
});
|
|
5974
|
-
},
|
|
5975
|
-
async getUri(path) {
|
|
5976
|
-
return Filesystem.getUri({
|
|
5977
|
-
path,
|
|
5978
|
-
directory: Directory.Data
|
|
5979
|
-
});
|
|
5980
|
-
}
|
|
5981
|
-
};
|
|
5982
|
-
|
|
5983
|
-
// src/services/filesystem-service/json-worker.ts
|
|
5984
|
-
self.addEventListener("message", async (ev) => {
|
|
5985
|
-
const { id, cmd, payload } = ev.data;
|
|
5986
|
-
try {
|
|
5987
|
-
if (cmd === "parse") {
|
|
5988
|
-
const parsed = JSON.parse(payload);
|
|
5989
|
-
self.postMessage({ id, ok: true, result: parsed });
|
|
5990
|
-
} else if (cmd === "stringify") {
|
|
5991
|
-
const str = JSON.stringify(payload);
|
|
5992
|
-
self.postMessage({ id, ok: true, result: str });
|
|
5993
|
-
}
|
|
5994
|
-
} catch (err) {
|
|
5995
|
-
self.postMessage({ id, ok: false, error: err?.message || String(err) });
|
|
5996
|
-
}
|
|
5997
|
-
});
|
|
5998
|
-
function spawnParseWorker(raw) {
|
|
5999
|
-
return new Promise((resolve, reject) => {
|
|
6000
|
-
const worker = new Worker(new URL("./json-worker.ts", import.meta.url), {
|
|
6001
|
-
type: "module"
|
|
6002
|
-
});
|
|
6003
|
-
const id = Math.random().toString(36).slice(2);
|
|
6004
|
-
worker.onmessage = (ev) => {
|
|
6005
|
-
const { ok, result, error } = ev.data;
|
|
6006
|
-
if (ok) {
|
|
6007
|
-
resolve(result);
|
|
6008
|
-
} else {
|
|
6009
|
-
reject(new Error(error));
|
|
6010
|
-
}
|
|
6011
|
-
worker.terminate();
|
|
6012
|
-
};
|
|
6013
|
-
worker.postMessage({ id, cmd: "parse", payload: raw });
|
|
6014
|
-
});
|
|
6015
|
-
}
|
|
6016
|
-
function spawnStringifyWorker(obj) {
|
|
6017
|
-
return new Promise((resolve, reject) => {
|
|
6018
|
-
const worker = new Worker(new URL("./json-worker.ts", import.meta.url), {
|
|
6019
|
-
type: "module"
|
|
6020
|
-
});
|
|
6021
|
-
worker.onmessage = (ev) => {
|
|
6022
|
-
const { ok, result, error } = ev.data;
|
|
6023
|
-
if (ok) resolve(result);
|
|
6024
|
-
else reject(new Error(error));
|
|
6025
|
-
worker.terminate();
|
|
6026
|
-
};
|
|
6027
|
-
worker.postMessage({ cmd: "stringify", payload: obj });
|
|
6028
|
-
});
|
|
6029
|
-
}
|
|
6324
|
+
ids,
|
|
6325
|
+
xNode,
|
|
6326
|
+
service,
|
|
6327
|
+
method
|
|
6328
|
+
}) => {
|
|
6329
|
+
const jsonData = {
|
|
6330
|
+
model,
|
|
6331
|
+
ids,
|
|
6332
|
+
method
|
|
6333
|
+
};
|
|
6334
|
+
return env?.requests.post(
|
|
6335
|
+
"/call" /* CALL_PATH */,
|
|
6336
|
+
jsonData,
|
|
6337
|
+
{
|
|
6338
|
+
headers: {
|
|
6339
|
+
"Content-Type": "application/json",
|
|
6340
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
6341
|
+
}
|
|
6342
|
+
},
|
|
6343
|
+
service
|
|
6344
|
+
);
|
|
6345
|
+
},
|
|
6346
|
+
[env]
|
|
6347
|
+
);
|
|
6348
|
+
return {
|
|
6349
|
+
handleCloseSession
|
|
6350
|
+
};
|
|
6351
|
+
};
|
|
6030
6352
|
|
|
6031
|
-
// src/services/
|
|
6032
|
-
|
|
6033
|
-
|
|
6034
|
-
|
|
6035
|
-
|
|
6036
|
-
|
|
6037
|
-
|
|
6038
|
-
|
|
6039
|
-
|
|
6040
|
-
|
|
6041
|
-
|
|
6042
|
-
|
|
6043
|
-
|
|
6044
|
-
|
|
6045
|
-
|
|
6046
|
-
|
|
6047
|
-
|
|
6048
|
-
|
|
6049
|
-
|
|
6050
|
-
|
|
6051
|
-
|
|
6353
|
+
// src/services/pos-service/handle-closing-detail-session.ts
|
|
6354
|
+
import { useCallback as useCallback29 } from "react";
|
|
6355
|
+
var handleClosingDetailSessionService = (env) => {
|
|
6356
|
+
const handleClosingDetailSession = useCallback29(
|
|
6357
|
+
({
|
|
6358
|
+
model,
|
|
6359
|
+
ids,
|
|
6360
|
+
method,
|
|
6361
|
+
xNode,
|
|
6362
|
+
service,
|
|
6363
|
+
kwargs
|
|
6364
|
+
}) => {
|
|
6365
|
+
const jsonData = {
|
|
6366
|
+
model,
|
|
6367
|
+
ids,
|
|
6368
|
+
method,
|
|
6369
|
+
kwargs
|
|
6370
|
+
};
|
|
6371
|
+
return env?.requests.post(
|
|
6372
|
+
"/call" /* CALL_PATH */,
|
|
6373
|
+
jsonData,
|
|
6374
|
+
{
|
|
6375
|
+
headers: {
|
|
6376
|
+
"Content-Type": "application/json",
|
|
6377
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
6378
|
+
}
|
|
6379
|
+
},
|
|
6380
|
+
service
|
|
6381
|
+
);
|
|
6382
|
+
},
|
|
6383
|
+
[env]
|
|
6384
|
+
);
|
|
6385
|
+
return {
|
|
6386
|
+
handleClosingDetailSession
|
|
6387
|
+
};
|
|
6052
6388
|
};
|
|
6053
|
-
var memoryCache = new MemoryCache();
|
|
6054
6389
|
|
|
6055
|
-
// src/services/
|
|
6056
|
-
|
|
6057
|
-
var
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
}
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
|
|
6072
|
-
const fileName = file.name;
|
|
6073
|
-
const modelName = fileName.replace(/\.json$/, "");
|
|
6074
|
-
const dataPath = `${MODELS_DIR}/${fileName}`;
|
|
6075
|
-
console.log("\u{1F4C2} Reading data from:", dataPath);
|
|
6076
|
-
const rawData = await fileService.read(dataPath);
|
|
6077
|
-
console.log("\u2705 Data read, length:", rawData?.length);
|
|
6078
|
-
if (!rawData) continue;
|
|
6079
|
-
console.log("\u{1F504} Parsing data...");
|
|
6080
|
-
const parsedData = await spawnParseWorker(rawData);
|
|
6081
|
-
console.log("\u2705 Data parsed");
|
|
6082
|
-
const data = Array.isArray(parsedData) ? parsedData : [];
|
|
6083
|
-
if (!includeMeta) {
|
|
6084
|
-
result[modelName] = { data };
|
|
6085
|
-
continue;
|
|
6086
|
-
}
|
|
6087
|
-
const metaPath = `${MODELS_META_DIR}/${encodeURIComponent(
|
|
6088
|
-
modelName
|
|
6089
|
-
)}.meta.json`;
|
|
6090
|
-
console.log("\u{1F4C2} Reading meta from:", metaPath);
|
|
6091
|
-
const rawMeta = await fileService.read(metaPath);
|
|
6092
|
-
let fields = [];
|
|
6093
|
-
let relations = {};
|
|
6094
|
-
if (rawMeta) {
|
|
6095
|
-
console.log("\u{1F504} Parsing meta...");
|
|
6096
|
-
const parsedMeta = await spawnParseWorker(rawMeta);
|
|
6097
|
-
fields = parsedMeta?.fields ?? [];
|
|
6098
|
-
relations = parsedMeta?.relations ?? {};
|
|
6099
|
-
console.log("\u2705 Meta parsed");
|
|
6100
|
-
}
|
|
6101
|
-
result[modelName] = {
|
|
6102
|
-
data,
|
|
6103
|
-
fields,
|
|
6104
|
-
relations
|
|
6390
|
+
// src/services/pos-service/handle-closing-session.ts
|
|
6391
|
+
import { useCallback as useCallback30 } from "react";
|
|
6392
|
+
var handleClosingSessionService = (env) => {
|
|
6393
|
+
const handleClosingSession = useCallback30(
|
|
6394
|
+
({
|
|
6395
|
+
model,
|
|
6396
|
+
method,
|
|
6397
|
+
ids,
|
|
6398
|
+
kwargs,
|
|
6399
|
+
xNode,
|
|
6400
|
+
service
|
|
6401
|
+
}) => {
|
|
6402
|
+
const jsonData = {
|
|
6403
|
+
model,
|
|
6404
|
+
method,
|
|
6405
|
+
ids,
|
|
6406
|
+
kwargs
|
|
6105
6407
|
};
|
|
6106
|
-
|
|
6107
|
-
|
|
6108
|
-
|
|
6109
|
-
|
|
6110
|
-
|
|
6111
|
-
|
|
6112
|
-
|
|
6113
|
-
}
|
|
6408
|
+
return env?.requests.post(
|
|
6409
|
+
"/call" /* CALL_PATH */,
|
|
6410
|
+
jsonData,
|
|
6411
|
+
{
|
|
6412
|
+
headers: {
|
|
6413
|
+
"Content-Type": "application/json",
|
|
6414
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
6415
|
+
}
|
|
6416
|
+
},
|
|
6417
|
+
service
|
|
6418
|
+
);
|
|
6419
|
+
},
|
|
6420
|
+
[env]
|
|
6421
|
+
);
|
|
6422
|
+
return {
|
|
6423
|
+
handleClosingSession
|
|
6424
|
+
};
|
|
6425
|
+
};
|
|
6114
6426
|
|
|
6115
6427
|
// src/services/pos-service/load-data-pos-session.ts
|
|
6428
|
+
import { useCallback as useCallback31 } from "react";
|
|
6116
6429
|
var loadDataPosSessionService = (env) => {
|
|
6117
6430
|
const isLocalMode = env?.isLocalMode;
|
|
6118
6431
|
const loadDataPosSession = useCallback31(
|
|
@@ -6125,10 +6438,8 @@ var loadDataPosSessionService = (env) => {
|
|
|
6125
6438
|
modelsToLoad = [],
|
|
6126
6439
|
searchParams
|
|
6127
6440
|
}) => {
|
|
6128
|
-
console.log("isLocalMode", isLocalMode);
|
|
6129
6441
|
if (isLocalMode) {
|
|
6130
6442
|
const data = await loadData();
|
|
6131
|
-
console.log("\u2705 loadData resolved:", data);
|
|
6132
6443
|
return data;
|
|
6133
6444
|
}
|
|
6134
6445
|
const jsonData = {
|
|
@@ -6382,6 +6693,8 @@ var updateClosedSessionService = (env) => {
|
|
|
6382
6693
|
// src/services/pos-service/update-entity.ts
|
|
6383
6694
|
import { useCallback as useCallback38 } from "react";
|
|
6384
6695
|
var updateEntityService = (env) => {
|
|
6696
|
+
const isLocalMode = env?.isLocalMode;
|
|
6697
|
+
const repo = new ModelRepository();
|
|
6385
6698
|
const updateEntity = useCallback38(
|
|
6386
6699
|
({
|
|
6387
6700
|
model,
|
|
@@ -6391,6 +6704,15 @@ var updateEntityService = (env) => {
|
|
|
6391
6704
|
xNode,
|
|
6392
6705
|
service
|
|
6393
6706
|
}) => {
|
|
6707
|
+
if (isLocalMode) {
|
|
6708
|
+
const id = extractIdFromDomain(domain);
|
|
6709
|
+
if (!id) return;
|
|
6710
|
+
return repo.updateRecord({
|
|
6711
|
+
update: values,
|
|
6712
|
+
modelName: model,
|
|
6713
|
+
id
|
|
6714
|
+
});
|
|
6715
|
+
}
|
|
6394
6716
|
const jsonData = {
|
|
6395
6717
|
model,
|
|
6396
6718
|
domain,
|
|
@@ -6408,7 +6730,7 @@ var updateEntityService = (env) => {
|
|
|
6408
6730
|
service
|
|
6409
6731
|
);
|
|
6410
6732
|
},
|
|
6411
|
-
[env]
|
|
6733
|
+
[env, isLocalMode]
|
|
6412
6734
|
);
|
|
6413
6735
|
return {
|
|
6414
6736
|
updateEntity
|
|
@@ -6490,101 +6812,6 @@ var usePosService = () => {
|
|
|
6490
6812
|
return service;
|
|
6491
6813
|
};
|
|
6492
6814
|
|
|
6493
|
-
// src/services/filesystem-service/manifest.ts
|
|
6494
|
-
var MANIFEST_PATH = "pos/manifest.json";
|
|
6495
|
-
var MANIFEST_BAK_PATH = "pos/manifest.bak.json";
|
|
6496
|
-
async function writeManifest(manifest) {
|
|
6497
|
-
const oldRaw = await fileService.read(MANIFEST_PATH);
|
|
6498
|
-
if (oldRaw !== null) {
|
|
6499
|
-
await fileService.writeAtomic(MANIFEST_BAK_PATH, oldRaw);
|
|
6500
|
-
}
|
|
6501
|
-
await fileService.writeAtomic(MANIFEST_PATH, JSON.stringify(manifest));
|
|
6502
|
-
try {
|
|
6503
|
-
await fileService.delete(MANIFEST_BAK_PATH);
|
|
6504
|
-
} catch {
|
|
6505
|
-
}
|
|
6506
|
-
}
|
|
6507
|
-
|
|
6508
|
-
// src/services/filesystem-service/import-snapshot.ts
|
|
6509
|
-
var DATA_DIR = "pos";
|
|
6510
|
-
var MODELS_DIR2 = `${DATA_DIR}/models`;
|
|
6511
|
-
var MODELS_META_DIR2 = `${DATA_DIR}/models_meta`;
|
|
6512
|
-
var importSnapshot = async ({ data, onProgress }) => {
|
|
6513
|
-
onProgress?.(1, "Parsing snapshot");
|
|
6514
|
-
const parsed = await spawnParseWorker(data);
|
|
6515
|
-
const modelNames = Object.keys(parsed);
|
|
6516
|
-
const total = modelNames.length;
|
|
6517
|
-
const manifest = { version: (/* @__PURE__ */ new Date()).toISOString(), models: {} };
|
|
6518
|
-
const TMP_PREFIX = `pos/data/tmp_import_${Date.now()}`;
|
|
6519
|
-
await fileService.writeAtomic(`${TMP_PREFIX}/.marker`, "1");
|
|
6520
|
-
let i = 0;
|
|
6521
|
-
for (const model of modelNames) {
|
|
6522
|
-
i++;
|
|
6523
|
-
onProgress?.(
|
|
6524
|
-
Math.round(i / total * 100),
|
|
6525
|
-
`Processing ${model} (${i}/${total})`
|
|
6526
|
-
);
|
|
6527
|
-
const block = parsed[model];
|
|
6528
|
-
const dataPart = block?.data ?? block ?? [];
|
|
6529
|
-
const fields = block?.fields ?? [];
|
|
6530
|
-
const relations = block?.relations ?? {};
|
|
6531
|
-
const serialized = await spawnStringifyWorker(dataPart);
|
|
6532
|
-
const tmpModelPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.json`;
|
|
6533
|
-
await fileService.writeAtomic(tmpModelPath, serialized);
|
|
6534
|
-
const meta = {
|
|
6535
|
-
fields,
|
|
6536
|
-
relations,
|
|
6537
|
-
count: Array.isArray(dataPart) ? dataPart.length : 0,
|
|
6538
|
-
writtenAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
6539
|
-
};
|
|
6540
|
-
const tmpMetaPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`;
|
|
6541
|
-
await fileService.writeAtomic(tmpMetaPath, JSON.stringify(meta));
|
|
6542
|
-
manifest.models[model] = {
|
|
6543
|
-
file: `${MODELS_DIR2}/${encodeURIComponent(model)}.json`,
|
|
6544
|
-
metaFile: `${MODELS_META_DIR2}/${encodeURIComponent(model)}.meta.json`,
|
|
6545
|
-
count: meta.count,
|
|
6546
|
-
updatedAt: meta.writtenAt
|
|
6547
|
-
};
|
|
6548
|
-
}
|
|
6549
|
-
onProgress?.(95, "Committing import (moving files)");
|
|
6550
|
-
for (const model of modelNames) {
|
|
6551
|
-
const tmpModelPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.json`;
|
|
6552
|
-
const finalModelPath = `${MODELS_DIR2}/${encodeURIComponent(model)}.json`;
|
|
6553
|
-
const tmpMetaPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`;
|
|
6554
|
-
const finalMetaPath = `${MODELS_META_DIR2}/${encodeURIComponent(
|
|
6555
|
-
model
|
|
6556
|
-
)}.meta.json`;
|
|
6557
|
-
const tmpRaw = await fileService.read(tmpModelPath);
|
|
6558
|
-
if (tmpRaw !== null) await fileService.writeAtomic(finalModelPath, tmpRaw);
|
|
6559
|
-
const tmpMetaRaw = await fileService.read(tmpMetaPath);
|
|
6560
|
-
if (tmpMetaRaw !== null)
|
|
6561
|
-
await fileService.writeAtomic(finalMetaPath, tmpMetaRaw);
|
|
6562
|
-
onProgress?.(
|
|
6563
|
-
95 + Math.round(
|
|
6564
|
-
(Object.keys(manifest.models).indexOf(model) + 1) / modelNames.length * 5
|
|
6565
|
-
),
|
|
6566
|
-
`Committed ${model}`
|
|
6567
|
-
);
|
|
6568
|
-
}
|
|
6569
|
-
await writeManifest(manifest);
|
|
6570
|
-
try {
|
|
6571
|
-
for (const model of modelNames) {
|
|
6572
|
-
await fileService.delete(
|
|
6573
|
-
`${TMP_PREFIX}/${encodeURIComponent(model)}.json`
|
|
6574
|
-
);
|
|
6575
|
-
await fileService.delete(
|
|
6576
|
-
`${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`
|
|
6577
|
-
);
|
|
6578
|
-
}
|
|
6579
|
-
await fileService.delete(`${TMP_PREFIX}/.marker`);
|
|
6580
|
-
} catch (e) {
|
|
6581
|
-
console.log("Failed to cleanup tmp import files:", e);
|
|
6582
|
-
}
|
|
6583
|
-
onProgress?.(100, "Import complete");
|
|
6584
|
-
return manifest;
|
|
6585
|
-
};
|
|
6586
|
-
var import_snapshot_default = importSnapshot;
|
|
6587
|
-
|
|
6588
6815
|
// src/services/filesystem-service/init-snapshot.ts
|
|
6589
6816
|
var isSnapshotReady = async () => {
|
|
6590
6817
|
try {
|