@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/services.js
CHANGED
|
@@ -2225,6 +2225,13 @@ function cleanObject(obj) {
|
|
|
2225
2225
|
}
|
|
2226
2226
|
return result;
|
|
2227
2227
|
}
|
|
2228
|
+
var extractIdFromDomain = (domain) => {
|
|
2229
|
+
if (!domain || !Array.isArray(domain)) return null;
|
|
2230
|
+
const idCond = domain.find(
|
|
2231
|
+
([field, operator]) => field === "id" && operator === "="
|
|
2232
|
+
);
|
|
2233
|
+
return idCond ? Number(idCond[2]) : null;
|
|
2234
|
+
};
|
|
2228
2235
|
|
|
2229
2236
|
// src/provider/react-query-provider.tsx
|
|
2230
2237
|
var import_react2 = require("react");
|
|
@@ -3188,116 +3195,638 @@ var getASessionService = (env) => {
|
|
|
3188
3195
|
|
|
3189
3196
|
// src/services/pos-service/add-entity.ts
|
|
3190
3197
|
var import_react7 = require("react");
|
|
3191
|
-
var addEntityService = (env) => {
|
|
3192
|
-
const addEntity = (0, import_react7.useCallback)(
|
|
3193
|
-
({
|
|
3194
|
-
model,
|
|
3195
|
-
values,
|
|
3196
|
-
xNode,
|
|
3197
|
-
service,
|
|
3198
|
-
isCreateEndpoint = false
|
|
3199
|
-
}) => {
|
|
3200
|
-
const jsonData = {
|
|
3201
|
-
model,
|
|
3202
|
-
values
|
|
3203
|
-
};
|
|
3204
|
-
return env?.requests.post(
|
|
3205
|
-
isCreateEndpoint ? "/create" /* CREATE_PATH */ : "/call" /* CALL_PATH */,
|
|
3206
|
-
jsonData,
|
|
3207
|
-
{
|
|
3208
|
-
headers: {
|
|
3209
|
-
"Content-Type": "application/json",
|
|
3210
|
-
...xNode ? { "X-Node": xNode } : {}
|
|
3211
|
-
}
|
|
3212
|
-
},
|
|
3213
|
-
service
|
|
3214
|
-
);
|
|
3215
|
-
},
|
|
3216
|
-
[env]
|
|
3217
|
-
);
|
|
3218
|
-
return {
|
|
3219
|
-
addEntity
|
|
3220
|
-
};
|
|
3221
|
-
};
|
|
3222
3198
|
|
|
3223
|
-
// src/services/
|
|
3224
|
-
var
|
|
3225
|
-
var
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3199
|
+
// src/services/filesystem-service/file-service.ts
|
|
3200
|
+
var import_filesystem = require("@capacitor/filesystem");
|
|
3201
|
+
var fileService = {
|
|
3202
|
+
read: async (path) => {
|
|
3203
|
+
try {
|
|
3204
|
+
const res = await import_filesystem.Filesystem.readFile({
|
|
3205
|
+
path,
|
|
3206
|
+
directory: import_filesystem.Directory.Data,
|
|
3207
|
+
encoding: import_filesystem.Encoding.UTF8
|
|
3208
|
+
});
|
|
3209
|
+
if (typeof res.data === "string") return res.data;
|
|
3210
|
+
if (res.data instanceof Blob) return await res.data.text();
|
|
3211
|
+
return null;
|
|
3212
|
+
} catch {
|
|
3213
|
+
return null;
|
|
3214
|
+
}
|
|
3215
|
+
},
|
|
3216
|
+
write: async (path, data) => {
|
|
3217
|
+
await import_filesystem.Filesystem.writeFile({
|
|
3218
|
+
path,
|
|
3219
|
+
data,
|
|
3220
|
+
directory: import_filesystem.Directory.Data,
|
|
3221
|
+
encoding: import_filesystem.Encoding.UTF8,
|
|
3222
|
+
recursive: true
|
|
3223
|
+
});
|
|
3224
|
+
},
|
|
3225
|
+
writeAtomic: async (path, data) => {
|
|
3226
|
+
const tempPath = path + ".tmp";
|
|
3227
|
+
await import_filesystem.Filesystem.writeFile({
|
|
3228
|
+
path: tempPath,
|
|
3229
|
+
data,
|
|
3230
|
+
directory: import_filesystem.Directory.Data,
|
|
3231
|
+
encoding: import_filesystem.Encoding.UTF8,
|
|
3232
|
+
recursive: true
|
|
3233
|
+
});
|
|
3234
|
+
try {
|
|
3235
|
+
await import_filesystem.Filesystem.deleteFile({
|
|
3236
|
+
path,
|
|
3237
|
+
directory: import_filesystem.Directory.Data
|
|
3238
|
+
});
|
|
3239
|
+
} catch {
|
|
3240
|
+
}
|
|
3241
|
+
await import_filesystem.Filesystem.rename({
|
|
3242
|
+
from: tempPath,
|
|
3243
|
+
to: path,
|
|
3244
|
+
directory: import_filesystem.Directory.Data
|
|
3245
|
+
});
|
|
3246
|
+
},
|
|
3247
|
+
delete: async (path) => {
|
|
3248
|
+
try {
|
|
3249
|
+
await import_filesystem.Filesystem.deleteFile({
|
|
3250
|
+
path,
|
|
3251
|
+
directory: import_filesystem.Directory.Data
|
|
3252
|
+
});
|
|
3253
|
+
} catch {
|
|
3254
|
+
}
|
|
3255
|
+
},
|
|
3256
|
+
exists: async (path) => {
|
|
3257
|
+
try {
|
|
3258
|
+
await import_filesystem.Filesystem.stat({
|
|
3259
|
+
path,
|
|
3260
|
+
directory: import_filesystem.Directory.Data
|
|
3261
|
+
});
|
|
3262
|
+
return true;
|
|
3263
|
+
} catch {
|
|
3264
|
+
return false;
|
|
3265
|
+
}
|
|
3266
|
+
},
|
|
3267
|
+
mkdir: async (path) => {
|
|
3268
|
+
try {
|
|
3269
|
+
await import_filesystem.Filesystem.mkdir({
|
|
3270
|
+
path,
|
|
3271
|
+
directory: import_filesystem.Directory.Data,
|
|
3272
|
+
recursive: true
|
|
3273
|
+
});
|
|
3274
|
+
} catch (e) {
|
|
3275
|
+
if (!String(e?.message).includes("Exists")) {
|
|
3276
|
+
throw e;
|
|
3277
|
+
}
|
|
3278
|
+
}
|
|
3279
|
+
},
|
|
3280
|
+
list: async (path) => {
|
|
3281
|
+
return import_filesystem.Filesystem.readdir({
|
|
3282
|
+
path,
|
|
3283
|
+
directory: import_filesystem.Directory.Data
|
|
3284
|
+
});
|
|
3285
|
+
},
|
|
3286
|
+
getUri: async (path) => {
|
|
3287
|
+
return import_filesystem.Filesystem.getUri({
|
|
3288
|
+
path,
|
|
3289
|
+
directory: import_filesystem.Directory.Data
|
|
3290
|
+
});
|
|
3291
|
+
}
|
|
3260
3292
|
};
|
|
3261
3293
|
|
|
3262
|
-
// src/services/
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3294
|
+
// src/services/filesystem-service/json-worker.ts
|
|
3295
|
+
function createWorkerBlob() {
|
|
3296
|
+
const workerCode = `
|
|
3297
|
+
self.addEventListener("message", async (ev) => {
|
|
3298
|
+
const { id, cmd, payload } = ev.data;
|
|
3299
|
+
try {
|
|
3300
|
+
if (cmd === "parse") {
|
|
3301
|
+
const parsed = JSON.parse(payload);
|
|
3302
|
+
self.postMessage({ id, ok: true, result: parsed });
|
|
3303
|
+
} else if (cmd === "stringify") {
|
|
3304
|
+
const str = JSON.stringify(payload);
|
|
3305
|
+
self.postMessage({ id, ok: true, result: str });
|
|
3306
|
+
}
|
|
3307
|
+
} catch (err) {
|
|
3308
|
+
self.postMessage({ id, ok: false, error: err?.message || String(err) });
|
|
3309
|
+
}
|
|
3310
|
+
});
|
|
3311
|
+
`;
|
|
3312
|
+
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
3313
|
+
return URL.createObjectURL(blob);
|
|
3314
|
+
}
|
|
3315
|
+
function spawnParseWorker(raw) {
|
|
3316
|
+
return new Promise((resolve, reject) => {
|
|
3317
|
+
const workerUrl = createWorkerBlob();
|
|
3318
|
+
const worker = new Worker(workerUrl);
|
|
3319
|
+
const id = Math.random().toString(36).slice(2);
|
|
3320
|
+
worker.onmessage = (ev) => {
|
|
3321
|
+
const { ok, result, error } = ev.data;
|
|
3322
|
+
if (ok) {
|
|
3323
|
+
resolve(result);
|
|
3324
|
+
} else {
|
|
3325
|
+
reject(new Error(error));
|
|
3326
|
+
}
|
|
3327
|
+
URL.revokeObjectURL(workerUrl);
|
|
3328
|
+
worker.terminate();
|
|
3329
|
+
};
|
|
3330
|
+
worker.onerror = (err) => {
|
|
3331
|
+
reject(err);
|
|
3332
|
+
URL.revokeObjectURL(workerUrl);
|
|
3333
|
+
worker.terminate();
|
|
3334
|
+
};
|
|
3335
|
+
worker.postMessage({ id, cmd: "parse", payload: raw });
|
|
3336
|
+
});
|
|
3337
|
+
}
|
|
3338
|
+
function spawnStringifyWorker(obj) {
|
|
3339
|
+
return new Promise((resolve, reject) => {
|
|
3340
|
+
const workerUrl = createWorkerBlob();
|
|
3341
|
+
const worker = new Worker(workerUrl);
|
|
3342
|
+
worker.onmessage = (ev) => {
|
|
3343
|
+
const { ok, result, error } = ev.data;
|
|
3344
|
+
if (ok) resolve(result);
|
|
3345
|
+
else reject(new Error(error));
|
|
3346
|
+
URL.revokeObjectURL(workerUrl);
|
|
3347
|
+
worker.terminate();
|
|
3348
|
+
};
|
|
3349
|
+
worker.onerror = (err) => {
|
|
3350
|
+
reject(err);
|
|
3351
|
+
URL.revokeObjectURL(workerUrl);
|
|
3352
|
+
worker.terminate();
|
|
3353
|
+
};
|
|
3354
|
+
worker.postMessage({ cmd: "stringify", payload: obj });
|
|
3355
|
+
});
|
|
3356
|
+
}
|
|
3297
3357
|
|
|
3298
|
-
// src/services/
|
|
3299
|
-
var
|
|
3300
|
-
var
|
|
3358
|
+
// src/services/filesystem-service/manifest.ts
|
|
3359
|
+
var MANIFEST_PATH = "pos/manifest.json";
|
|
3360
|
+
var MANIFEST_BAK_PATH = "pos/manifest.bak.json";
|
|
3361
|
+
async function writeManifest(manifest) {
|
|
3362
|
+
const oldRaw = await fileService.read(MANIFEST_PATH);
|
|
3363
|
+
if (oldRaw !== null) {
|
|
3364
|
+
await fileService.writeAtomic(MANIFEST_BAK_PATH, oldRaw);
|
|
3365
|
+
}
|
|
3366
|
+
await fileService.writeAtomic(MANIFEST_PATH, JSON.stringify(manifest));
|
|
3367
|
+
try {
|
|
3368
|
+
await fileService.delete(MANIFEST_BAK_PATH);
|
|
3369
|
+
} catch {
|
|
3370
|
+
}
|
|
3371
|
+
}
|
|
3372
|
+
|
|
3373
|
+
// src/services/filesystem-service/import-snapshot.ts
|
|
3374
|
+
var DATA_DIR = "pos";
|
|
3375
|
+
var MODELS_DIR = `${DATA_DIR}/models`;
|
|
3376
|
+
var MODELS_META_DIR = `${DATA_DIR}/models_meta`;
|
|
3377
|
+
var importSnapshot = async ({ data, onProgress }) => {
|
|
3378
|
+
onProgress?.(1, "Parsing snapshot");
|
|
3379
|
+
const parsed = await spawnParseWorker(data);
|
|
3380
|
+
const modelNames = Object.keys(parsed);
|
|
3381
|
+
const total = modelNames.length;
|
|
3382
|
+
const manifest = { version: (/* @__PURE__ */ new Date()).toISOString(), models: {} };
|
|
3383
|
+
const TMP_PREFIX = `pos/data/tmp_import_${Date.now()}`;
|
|
3384
|
+
await fileService.writeAtomic(`${TMP_PREFIX}/.marker`, "1");
|
|
3385
|
+
let i = 0;
|
|
3386
|
+
for (const model of modelNames) {
|
|
3387
|
+
i++;
|
|
3388
|
+
onProgress?.(
|
|
3389
|
+
Math.round(i / total * 100),
|
|
3390
|
+
`Processing ${model} (${i}/${total})`
|
|
3391
|
+
);
|
|
3392
|
+
const block = parsed[model];
|
|
3393
|
+
const dataPart = block?.data ?? block ?? [];
|
|
3394
|
+
const fields = block?.fields ?? [];
|
|
3395
|
+
const relations = block?.relations ?? {};
|
|
3396
|
+
const serialized = await spawnStringifyWorker(dataPart);
|
|
3397
|
+
const tmpModelPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.json`;
|
|
3398
|
+
await fileService.writeAtomic(tmpModelPath, serialized);
|
|
3399
|
+
const meta = {
|
|
3400
|
+
fields,
|
|
3401
|
+
relations,
|
|
3402
|
+
count: Array.isArray(dataPart) ? dataPart.length : 0,
|
|
3403
|
+
writtenAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3404
|
+
};
|
|
3405
|
+
const tmpMetaPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`;
|
|
3406
|
+
await fileService.writeAtomic(tmpMetaPath, JSON.stringify(meta));
|
|
3407
|
+
manifest.models[model] = {
|
|
3408
|
+
file: `${MODELS_DIR}/${encodeURIComponent(model)}.json`,
|
|
3409
|
+
metaFile: `${MODELS_META_DIR}/${encodeURIComponent(model)}.meta.json`,
|
|
3410
|
+
count: meta.count,
|
|
3411
|
+
updatedAt: meta.writtenAt
|
|
3412
|
+
};
|
|
3413
|
+
}
|
|
3414
|
+
onProgress?.(95, "Committing import (moving files)");
|
|
3415
|
+
for (const model of modelNames) {
|
|
3416
|
+
const tmpModelPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.json`;
|
|
3417
|
+
const finalModelPath = `${MODELS_DIR}/${encodeURIComponent(model)}.json`;
|
|
3418
|
+
const tmpMetaPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`;
|
|
3419
|
+
const finalMetaPath = `${MODELS_META_DIR}/${encodeURIComponent(
|
|
3420
|
+
model
|
|
3421
|
+
)}.meta.json`;
|
|
3422
|
+
const tmpRaw = await fileService.read(tmpModelPath);
|
|
3423
|
+
if (tmpRaw !== null) await fileService.writeAtomic(finalModelPath, tmpRaw);
|
|
3424
|
+
const tmpMetaRaw = await fileService.read(tmpMetaPath);
|
|
3425
|
+
if (tmpMetaRaw !== null)
|
|
3426
|
+
await fileService.writeAtomic(finalMetaPath, tmpMetaRaw);
|
|
3427
|
+
onProgress?.(
|
|
3428
|
+
95 + Math.round(
|
|
3429
|
+
(Object.keys(manifest.models).indexOf(model) + 1) / modelNames.length * 5
|
|
3430
|
+
),
|
|
3431
|
+
`Committed ${model}`
|
|
3432
|
+
);
|
|
3433
|
+
}
|
|
3434
|
+
await writeManifest(manifest);
|
|
3435
|
+
try {
|
|
3436
|
+
for (const model of modelNames) {
|
|
3437
|
+
await fileService.delete(
|
|
3438
|
+
`${TMP_PREFIX}/${encodeURIComponent(model)}.json`
|
|
3439
|
+
);
|
|
3440
|
+
await fileService.delete(
|
|
3441
|
+
`${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`
|
|
3442
|
+
);
|
|
3443
|
+
}
|
|
3444
|
+
await fileService.delete(`${TMP_PREFIX}/.marker`);
|
|
3445
|
+
} catch (e) {
|
|
3446
|
+
console.log("Failed to cleanup tmp import files:", e);
|
|
3447
|
+
}
|
|
3448
|
+
onProgress?.(100, "Import complete");
|
|
3449
|
+
return manifest;
|
|
3450
|
+
};
|
|
3451
|
+
var import_snapshot_default = importSnapshot;
|
|
3452
|
+
|
|
3453
|
+
// src/services/filesystem-service/memory-cache.ts
|
|
3454
|
+
var MemoryCache = class {
|
|
3455
|
+
map = /* @__PURE__ */ new Map();
|
|
3456
|
+
get(k) {
|
|
3457
|
+
const e = this.map.get(k);
|
|
3458
|
+
if (!e) return null;
|
|
3459
|
+
if (e.ttl && Date.now() - e.t > e.ttl) {
|
|
3460
|
+
this.map.delete(k);
|
|
3461
|
+
return null;
|
|
3462
|
+
}
|
|
3463
|
+
return e.value;
|
|
3464
|
+
}
|
|
3465
|
+
set(k, v, ttl = 5 * 60 * 1e3) {
|
|
3466
|
+
this.map.set(k, { value: v, t: Date.now(), ttl });
|
|
3467
|
+
}
|
|
3468
|
+
del(k) {
|
|
3469
|
+
this.map.delete(k);
|
|
3470
|
+
}
|
|
3471
|
+
clear() {
|
|
3472
|
+
this.map.clear();
|
|
3473
|
+
}
|
|
3474
|
+
};
|
|
3475
|
+
var memoryCache = new MemoryCache();
|
|
3476
|
+
|
|
3477
|
+
// src/services/filesystem-service/model-loader.ts
|
|
3478
|
+
var MODELS_DIR2 = "pos/models";
|
|
3479
|
+
var MODELS_META_DIR2 = "pos/models_meta";
|
|
3480
|
+
async function loadModelData(modelName, includeMeta = true) {
|
|
3481
|
+
const key = `model:${modelName}:meta:${includeMeta}`;
|
|
3482
|
+
const cached = memoryCache.get(key);
|
|
3483
|
+
if (cached) return cached;
|
|
3484
|
+
const dataPath = `${MODELS_DIR2}/${encodeURIComponent(modelName)}.json`;
|
|
3485
|
+
const metaPath = `${MODELS_META_DIR2}/${encodeURIComponent(
|
|
3486
|
+
modelName
|
|
3487
|
+
)}.meta.json`;
|
|
3488
|
+
const rawData = await fileService.read(dataPath);
|
|
3489
|
+
if (!rawData) return null;
|
|
3490
|
+
const parsedData = await spawnParseWorker(rawData);
|
|
3491
|
+
const data = Array.isArray(parsedData) ? parsedData : [];
|
|
3492
|
+
if (!includeMeta) {
|
|
3493
|
+
const result2 = { data };
|
|
3494
|
+
memoryCache.set(key, result2, 1e3 * 60 * 60);
|
|
3495
|
+
return result2;
|
|
3496
|
+
}
|
|
3497
|
+
const rawMeta = await fileService.read(metaPath);
|
|
3498
|
+
let fields = [];
|
|
3499
|
+
let relations = {};
|
|
3500
|
+
if (rawMeta) {
|
|
3501
|
+
const parsedMeta = await spawnParseWorker(rawMeta);
|
|
3502
|
+
fields = parsedMeta?.fields ?? [];
|
|
3503
|
+
relations = parsedMeta?.relations ?? {};
|
|
3504
|
+
}
|
|
3505
|
+
const result = {
|
|
3506
|
+
data,
|
|
3507
|
+
fields,
|
|
3508
|
+
relations
|
|
3509
|
+
};
|
|
3510
|
+
memoryCache.set(key, result, 1e3 * 60 * 60);
|
|
3511
|
+
return result;
|
|
3512
|
+
}
|
|
3513
|
+
async function loadData(includeMeta = true) {
|
|
3514
|
+
try {
|
|
3515
|
+
const listResult = await fileService.list(MODELS_DIR2);
|
|
3516
|
+
if (!listResult || !Array.isArray(listResult.files)) {
|
|
3517
|
+
console.log("No models found");
|
|
3518
|
+
return {};
|
|
3519
|
+
}
|
|
3520
|
+
const result = {};
|
|
3521
|
+
for (const file of listResult.files) {
|
|
3522
|
+
if (file.type !== "file") continue;
|
|
3523
|
+
if (!file.name.endsWith(".json")) continue;
|
|
3524
|
+
const fileName = file.name;
|
|
3525
|
+
const modelName = fileName.replace(/\.json$/, "");
|
|
3526
|
+
const dataPath = `${MODELS_DIR2}/${fileName}`;
|
|
3527
|
+
const rawData = await fileService.read(dataPath);
|
|
3528
|
+
if (!rawData) continue;
|
|
3529
|
+
const parsedData = await spawnParseWorker(rawData);
|
|
3530
|
+
const data = Array.isArray(parsedData) ? parsedData : [];
|
|
3531
|
+
if (!includeMeta) {
|
|
3532
|
+
result[modelName] = { data };
|
|
3533
|
+
continue;
|
|
3534
|
+
}
|
|
3535
|
+
const metaPath = `${MODELS_META_DIR2}/${encodeURIComponent(
|
|
3536
|
+
modelName
|
|
3537
|
+
)}.meta.json`;
|
|
3538
|
+
const rawMeta = await fileService.read(metaPath);
|
|
3539
|
+
let fields = [];
|
|
3540
|
+
let relations = {};
|
|
3541
|
+
if (rawMeta) {
|
|
3542
|
+
const parsedMeta = await spawnParseWorker(rawMeta);
|
|
3543
|
+
fields = parsedMeta?.fields ?? [];
|
|
3544
|
+
relations = parsedMeta?.relations ?? {};
|
|
3545
|
+
}
|
|
3546
|
+
result[modelName] = {
|
|
3547
|
+
data,
|
|
3548
|
+
fields,
|
|
3549
|
+
relations
|
|
3550
|
+
};
|
|
3551
|
+
}
|
|
3552
|
+
return result;
|
|
3553
|
+
} catch (error) {
|
|
3554
|
+
console.error("Error loading data:", error);
|
|
3555
|
+
throw error;
|
|
3556
|
+
}
|
|
3557
|
+
}
|
|
3558
|
+
|
|
3559
|
+
// src/services/filesystem-service/snapshot-helper.ts
|
|
3560
|
+
var createEmptySnapshot = () => {
|
|
3561
|
+
return {
|
|
3562
|
+
data: []
|
|
3563
|
+
};
|
|
3564
|
+
};
|
|
3565
|
+
var generateNextId = (existingIds, startFrom = 1) => {
|
|
3566
|
+
if (!existingIds || existingIds.length === 0) {
|
|
3567
|
+
return startFrom;
|
|
3568
|
+
}
|
|
3569
|
+
const maxId = Math.max(...existingIds, startFrom - 1);
|
|
3570
|
+
return maxId + 1;
|
|
3571
|
+
};
|
|
3572
|
+
var loadSnapshot = async ({
|
|
3573
|
+
modelName
|
|
3574
|
+
}) => {
|
|
3575
|
+
try {
|
|
3576
|
+
const snapshot = await loadModelData(modelName);
|
|
3577
|
+
if (!snapshot || typeof snapshot !== "object") {
|
|
3578
|
+
console.warn("invalid snapshot, creating new one");
|
|
3579
|
+
return createEmptySnapshot();
|
|
3580
|
+
}
|
|
3581
|
+
return {
|
|
3582
|
+
data: Array.isArray(snapshot.data) ? snapshot.data : []
|
|
3583
|
+
};
|
|
3584
|
+
} catch (error) {
|
|
3585
|
+
console.error("Failed to load snapshot:", error);
|
|
3586
|
+
return createEmptySnapshot();
|
|
3587
|
+
}
|
|
3588
|
+
};
|
|
3589
|
+
var getExistingIds = (snapshot) => {
|
|
3590
|
+
return snapshot.data.map((order) => order.id).filter((id) => typeof id === "number");
|
|
3591
|
+
};
|
|
3592
|
+
var saveSnapshot = async ({
|
|
3593
|
+
snapshot,
|
|
3594
|
+
modelName
|
|
3595
|
+
}) => {
|
|
3596
|
+
try {
|
|
3597
|
+
await import_snapshot_default({
|
|
3598
|
+
data: JSON.stringify({
|
|
3599
|
+
[modelName]: snapshot
|
|
3600
|
+
})
|
|
3601
|
+
});
|
|
3602
|
+
return true;
|
|
3603
|
+
} catch (error) {
|
|
3604
|
+
console.error("failed to save snapshot:", error);
|
|
3605
|
+
return false;
|
|
3606
|
+
}
|
|
3607
|
+
};
|
|
3608
|
+
|
|
3609
|
+
// src/services/filesystem-service/model-repository.ts
|
|
3610
|
+
var ModelRepository = class {
|
|
3611
|
+
getRecord = async ({
|
|
3612
|
+
id,
|
|
3613
|
+
modelName
|
|
3614
|
+
}) => {
|
|
3615
|
+
try {
|
|
3616
|
+
const snapshot = await loadSnapshot({
|
|
3617
|
+
modelName
|
|
3618
|
+
});
|
|
3619
|
+
return snapshot.data.find((record) => record.id === id) || null;
|
|
3620
|
+
} catch (error) {
|
|
3621
|
+
console.error("failed to get record:", error);
|
|
3622
|
+
return null;
|
|
3623
|
+
}
|
|
3624
|
+
};
|
|
3625
|
+
addRecord = async ({
|
|
3626
|
+
newRecord,
|
|
3627
|
+
modelName
|
|
3628
|
+
}) => {
|
|
3629
|
+
try {
|
|
3630
|
+
const snapshot = await loadSnapshot({
|
|
3631
|
+
modelName
|
|
3632
|
+
});
|
|
3633
|
+
console.log("modelName", modelName);
|
|
3634
|
+
console.log("snapshot", snapshot);
|
|
3635
|
+
const existingIds = getExistingIds(snapshot);
|
|
3636
|
+
console.log("existingIds", existingIds);
|
|
3637
|
+
const newId = generateNextId(existingIds, snapshot.data.length);
|
|
3638
|
+
console.log("newId", newId);
|
|
3639
|
+
snapshot.data.push({
|
|
3640
|
+
...newRecord,
|
|
3641
|
+
id: newId
|
|
3642
|
+
});
|
|
3643
|
+
const saved = await saveSnapshot({
|
|
3644
|
+
snapshot,
|
|
3645
|
+
modelName
|
|
3646
|
+
});
|
|
3647
|
+
if (!saved) {
|
|
3648
|
+
console.error("failed to add new record");
|
|
3649
|
+
return [];
|
|
3650
|
+
}
|
|
3651
|
+
console.log(`\u2705 ${snapshot.data.length} records saved`);
|
|
3652
|
+
console.log(snapshot.data);
|
|
3653
|
+
return snapshot.data;
|
|
3654
|
+
} catch (error) {
|
|
3655
|
+
console.error("failed to add new record:", error);
|
|
3656
|
+
return [];
|
|
3657
|
+
}
|
|
3658
|
+
};
|
|
3659
|
+
updateRecord = async ({
|
|
3660
|
+
id,
|
|
3661
|
+
update,
|
|
3662
|
+
modelName
|
|
3663
|
+
}) => {
|
|
3664
|
+
try {
|
|
3665
|
+
const snapshot = await loadSnapshot({
|
|
3666
|
+
modelName
|
|
3667
|
+
});
|
|
3668
|
+
const index = snapshot.data.findIndex((record) => record.id === id);
|
|
3669
|
+
if (index === -1) {
|
|
3670
|
+
console.error(`record with id ${id} not found`);
|
|
3671
|
+
return false;
|
|
3672
|
+
}
|
|
3673
|
+
snapshot.data[index] = {
|
|
3674
|
+
...snapshot.data[index],
|
|
3675
|
+
...update
|
|
3676
|
+
};
|
|
3677
|
+
return await saveSnapshot({
|
|
3678
|
+
snapshot,
|
|
3679
|
+
modelName
|
|
3680
|
+
});
|
|
3681
|
+
} catch (error) {
|
|
3682
|
+
console.error("error updating record:", error);
|
|
3683
|
+
return false;
|
|
3684
|
+
}
|
|
3685
|
+
};
|
|
3686
|
+
deleteRecord = async ({
|
|
3687
|
+
id,
|
|
3688
|
+
modelName
|
|
3689
|
+
}) => {
|
|
3690
|
+
try {
|
|
3691
|
+
const snapshot = await loadSnapshot({
|
|
3692
|
+
modelName
|
|
3693
|
+
});
|
|
3694
|
+
const before = snapshot.data.length;
|
|
3695
|
+
snapshot.data = snapshot.data.filter((record) => record.id !== id);
|
|
3696
|
+
if (snapshot.data.length === before) {
|
|
3697
|
+
console.error(`record with id ${id} not found`);
|
|
3698
|
+
return false;
|
|
3699
|
+
}
|
|
3700
|
+
return await saveSnapshot({
|
|
3701
|
+
snapshot,
|
|
3702
|
+
modelName
|
|
3703
|
+
});
|
|
3704
|
+
} catch (error) {
|
|
3705
|
+
console.error("error deleting record:", error);
|
|
3706
|
+
return false;
|
|
3707
|
+
}
|
|
3708
|
+
};
|
|
3709
|
+
};
|
|
3710
|
+
|
|
3711
|
+
// src/services/pos-service/add-entity.ts
|
|
3712
|
+
var addEntityService = (env) => {
|
|
3713
|
+
const isLocalMode = env?.isLocalMode;
|
|
3714
|
+
const repo = new ModelRepository();
|
|
3715
|
+
const addEntity = (0, import_react7.useCallback)(
|
|
3716
|
+
({
|
|
3717
|
+
model,
|
|
3718
|
+
values,
|
|
3719
|
+
xNode,
|
|
3720
|
+
service,
|
|
3721
|
+
isCreateEndpoint = false
|
|
3722
|
+
}) => {
|
|
3723
|
+
if (isLocalMode) {
|
|
3724
|
+
return repo.addRecord({
|
|
3725
|
+
newRecord: values,
|
|
3726
|
+
modelName: model
|
|
3727
|
+
});
|
|
3728
|
+
}
|
|
3729
|
+
const jsonData = {
|
|
3730
|
+
model,
|
|
3731
|
+
values
|
|
3732
|
+
};
|
|
3733
|
+
return env?.requests.post(
|
|
3734
|
+
isCreateEndpoint ? "/create" /* CREATE_PATH */ : "/call" /* CALL_PATH */,
|
|
3735
|
+
jsonData,
|
|
3736
|
+
{
|
|
3737
|
+
headers: {
|
|
3738
|
+
"Content-Type": "application/json",
|
|
3739
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
3740
|
+
}
|
|
3741
|
+
},
|
|
3742
|
+
service
|
|
3743
|
+
);
|
|
3744
|
+
},
|
|
3745
|
+
[env, isLocalMode]
|
|
3746
|
+
);
|
|
3747
|
+
return {
|
|
3748
|
+
addEntity
|
|
3749
|
+
};
|
|
3750
|
+
};
|
|
3751
|
+
|
|
3752
|
+
// src/services/pos-service/change-order-preparation-state.ts
|
|
3753
|
+
var import_react8 = require("react");
|
|
3754
|
+
var changOrderPreparationStateService = (env) => {
|
|
3755
|
+
const changeOrderPreparationState = (0, import_react8.useCallback)(
|
|
3756
|
+
({
|
|
3757
|
+
orderId,
|
|
3758
|
+
stageId,
|
|
3759
|
+
preparationDisplayId,
|
|
3760
|
+
xNode,
|
|
3761
|
+
service
|
|
3762
|
+
}) => {
|
|
3763
|
+
const jsonData = {
|
|
3764
|
+
model: "pos_preparation_display.order" /* POS_PREPARATION_ORDER */,
|
|
3765
|
+
method: "change_order_stage" /* CHANGE_ORDER_STAGE */,
|
|
3766
|
+
ids: orderId,
|
|
3767
|
+
kwargs: {
|
|
3768
|
+
stage_id: stageId,
|
|
3769
|
+
preparation_display_id: preparationDisplayId
|
|
3770
|
+
}
|
|
3771
|
+
};
|
|
3772
|
+
return env?.requests.post(
|
|
3773
|
+
"/call" /* CALL_PATH */,
|
|
3774
|
+
jsonData,
|
|
3775
|
+
{
|
|
3776
|
+
headers: {
|
|
3777
|
+
"Content-Type": "application/json",
|
|
3778
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
3779
|
+
}
|
|
3780
|
+
},
|
|
3781
|
+
service
|
|
3782
|
+
);
|
|
3783
|
+
},
|
|
3784
|
+
[env]
|
|
3785
|
+
);
|
|
3786
|
+
return {
|
|
3787
|
+
changeOrderPreparationState
|
|
3788
|
+
};
|
|
3789
|
+
};
|
|
3790
|
+
|
|
3791
|
+
// src/services/pos-service/check-payment.ts
|
|
3792
|
+
var import_react9 = require("react");
|
|
3793
|
+
var checkPaymentService = (env) => {
|
|
3794
|
+
const checkPayment = (0, import_react9.useCallback)(
|
|
3795
|
+
({
|
|
3796
|
+
model,
|
|
3797
|
+
ids,
|
|
3798
|
+
withContext,
|
|
3799
|
+
xNode,
|
|
3800
|
+
service
|
|
3801
|
+
}) => {
|
|
3802
|
+
const jsonData = {
|
|
3803
|
+
model,
|
|
3804
|
+
method: "check" /* CHECK */,
|
|
3805
|
+
ids,
|
|
3806
|
+
with_context: withContext
|
|
3807
|
+
};
|
|
3808
|
+
return env?.requests.post(
|
|
3809
|
+
"/call" /* CALL_PATH */,
|
|
3810
|
+
jsonData,
|
|
3811
|
+
{
|
|
3812
|
+
headers: {
|
|
3813
|
+
"Content-Type": "application/json",
|
|
3814
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
3815
|
+
}
|
|
3816
|
+
},
|
|
3817
|
+
service
|
|
3818
|
+
);
|
|
3819
|
+
},
|
|
3820
|
+
[env]
|
|
3821
|
+
);
|
|
3822
|
+
return {
|
|
3823
|
+
checkPayment
|
|
3824
|
+
};
|
|
3825
|
+
};
|
|
3826
|
+
|
|
3827
|
+
// src/services/pos-service/create-e-invoice.ts
|
|
3828
|
+
var import_react10 = require("react");
|
|
3829
|
+
var createEInvoiceService = (env) => {
|
|
3301
3830
|
const createEInvoice = (0, import_react10.useCallback)(
|
|
3302
3831
|
async ({
|
|
3303
3832
|
service,
|
|
@@ -3335,6 +3864,8 @@ var createEInvoiceService = (env) => {
|
|
|
3335
3864
|
// src/services/pos-service/create-entity.ts
|
|
3336
3865
|
var import_react11 = require("react");
|
|
3337
3866
|
var createEntityService = (env) => {
|
|
3867
|
+
const isLocalMode = env?.isLocalMode;
|
|
3868
|
+
const repo = new ModelRepository();
|
|
3338
3869
|
const createEntity = (0, import_react11.useCallback)(
|
|
3339
3870
|
({
|
|
3340
3871
|
model,
|
|
@@ -3342,6 +3873,12 @@ var createEntityService = (env) => {
|
|
|
3342
3873
|
xNode,
|
|
3343
3874
|
service
|
|
3344
3875
|
}) => {
|
|
3876
|
+
if (isLocalMode) {
|
|
3877
|
+
return repo.addRecord({
|
|
3878
|
+
newRecord: args,
|
|
3879
|
+
modelName: model
|
|
3880
|
+
});
|
|
3881
|
+
}
|
|
3345
3882
|
const jsonData = {
|
|
3346
3883
|
model,
|
|
3347
3884
|
method: "create" /* CREATE */,
|
|
@@ -3359,7 +3896,7 @@ var createEntityService = (env) => {
|
|
|
3359
3896
|
service
|
|
3360
3897
|
);
|
|
3361
3898
|
},
|
|
3362
|
-
[env]
|
|
3899
|
+
[env, isLocalMode]
|
|
3363
3900
|
);
|
|
3364
3901
|
return {
|
|
3365
3902
|
createEntity
|
|
@@ -3444,6 +3981,8 @@ var createSessionService = (env) => {
|
|
|
3444
3981
|
// src/services/pos-service/delete-entity.ts
|
|
3445
3982
|
var import_react14 = require("react");
|
|
3446
3983
|
var deleteEntityService = (env) => {
|
|
3984
|
+
const isLocalMode = env?.isLocalMode;
|
|
3985
|
+
const repo = new ModelRepository();
|
|
3447
3986
|
const deleteEntity = (0, import_react14.useCallback)(
|
|
3448
3987
|
({
|
|
3449
3988
|
model,
|
|
@@ -3452,6 +3991,14 @@ var deleteEntityService = (env) => {
|
|
|
3452
3991
|
service,
|
|
3453
3992
|
method
|
|
3454
3993
|
}) => {
|
|
3994
|
+
if (isLocalMode) {
|
|
3995
|
+
const id = ids[0];
|
|
3996
|
+
if (!id) return;
|
|
3997
|
+
return repo.deleteRecord({
|
|
3998
|
+
modelName: model,
|
|
3999
|
+
id
|
|
4000
|
+
});
|
|
4001
|
+
}
|
|
3455
4002
|
const jsonData = {
|
|
3456
4003
|
model,
|
|
3457
4004
|
ids,
|
|
@@ -3469,7 +4016,7 @@ var deleteEntityService = (env) => {
|
|
|
3469
4016
|
service
|
|
3470
4017
|
);
|
|
3471
4018
|
},
|
|
3472
|
-
[env]
|
|
4019
|
+
[env, isLocalMode]
|
|
3473
4020
|
);
|
|
3474
4021
|
return {
|
|
3475
4022
|
deleteEntity
|
|
@@ -3802,356 +4349,111 @@ var handleCloseSessionService = (env) => {
|
|
|
3802
4349
|
const handleCloseSession = (0, import_react23.useCallback)(
|
|
3803
4350
|
({
|
|
3804
4351
|
model,
|
|
3805
|
-
ids,
|
|
3806
|
-
xNode,
|
|
3807
|
-
service,
|
|
3808
|
-
method
|
|
3809
|
-
}) => {
|
|
3810
|
-
const jsonData = {
|
|
3811
|
-
model,
|
|
3812
|
-
ids,
|
|
3813
|
-
method
|
|
3814
|
-
};
|
|
3815
|
-
return env?.requests.post(
|
|
3816
|
-
"/call" /* CALL_PATH */,
|
|
3817
|
-
jsonData,
|
|
3818
|
-
{
|
|
3819
|
-
headers: {
|
|
3820
|
-
"Content-Type": "application/json",
|
|
3821
|
-
...xNode ? { "X-Node": xNode } : {}
|
|
3822
|
-
}
|
|
3823
|
-
},
|
|
3824
|
-
service
|
|
3825
|
-
);
|
|
3826
|
-
},
|
|
3827
|
-
[env]
|
|
3828
|
-
);
|
|
3829
|
-
return {
|
|
3830
|
-
handleCloseSession
|
|
3831
|
-
};
|
|
3832
|
-
};
|
|
3833
|
-
|
|
3834
|
-
// src/services/pos-service/handle-closing-detail-session.ts
|
|
3835
|
-
var import_react24 = require("react");
|
|
3836
|
-
var handleClosingDetailSessionService = (env) => {
|
|
3837
|
-
const handleClosingDetailSession = (0, import_react24.useCallback)(
|
|
3838
|
-
({
|
|
3839
|
-
model,
|
|
3840
|
-
ids,
|
|
3841
|
-
method,
|
|
3842
|
-
xNode,
|
|
3843
|
-
service,
|
|
3844
|
-
kwargs
|
|
3845
|
-
}) => {
|
|
3846
|
-
const jsonData = {
|
|
3847
|
-
model,
|
|
3848
|
-
ids,
|
|
3849
|
-
method,
|
|
3850
|
-
kwargs
|
|
3851
|
-
};
|
|
3852
|
-
return env?.requests.post(
|
|
3853
|
-
"/call" /* CALL_PATH */,
|
|
3854
|
-
jsonData,
|
|
3855
|
-
{
|
|
3856
|
-
headers: {
|
|
3857
|
-
"Content-Type": "application/json",
|
|
3858
|
-
...xNode ? { "X-Node": xNode } : {}
|
|
3859
|
-
}
|
|
3860
|
-
},
|
|
3861
|
-
service
|
|
3862
|
-
);
|
|
3863
|
-
},
|
|
3864
|
-
[env]
|
|
3865
|
-
);
|
|
3866
|
-
return {
|
|
3867
|
-
handleClosingDetailSession
|
|
3868
|
-
};
|
|
3869
|
-
};
|
|
3870
|
-
|
|
3871
|
-
// src/services/pos-service/handle-closing-session.ts
|
|
3872
|
-
var import_react25 = require("react");
|
|
3873
|
-
var handleClosingSessionService = (env) => {
|
|
3874
|
-
const handleClosingSession = (0, import_react25.useCallback)(
|
|
3875
|
-
({
|
|
3876
|
-
model,
|
|
3877
|
-
method,
|
|
3878
|
-
ids,
|
|
3879
|
-
kwargs,
|
|
3880
|
-
xNode,
|
|
3881
|
-
service
|
|
3882
|
-
}) => {
|
|
3883
|
-
const jsonData = {
|
|
3884
|
-
model,
|
|
3885
|
-
method,
|
|
3886
|
-
ids,
|
|
3887
|
-
kwargs
|
|
3888
|
-
};
|
|
3889
|
-
return env?.requests.post(
|
|
3890
|
-
"/call" /* CALL_PATH */,
|
|
3891
|
-
jsonData,
|
|
3892
|
-
{
|
|
3893
|
-
headers: {
|
|
3894
|
-
"Content-Type": "application/json",
|
|
3895
|
-
...xNode ? { "X-Node": xNode } : {}
|
|
3896
|
-
}
|
|
3897
|
-
},
|
|
3898
|
-
service
|
|
3899
|
-
);
|
|
3900
|
-
},
|
|
3901
|
-
[env]
|
|
3902
|
-
);
|
|
3903
|
-
return {
|
|
3904
|
-
handleClosingSession
|
|
3905
|
-
};
|
|
3906
|
-
};
|
|
3907
|
-
|
|
3908
|
-
// src/services/pos-service/load-data-pos-session.ts
|
|
3909
|
-
var import_react26 = require("react");
|
|
3910
|
-
|
|
3911
|
-
// src/services/filesystem-service/file-service.ts
|
|
3912
|
-
var import_filesystem = require("@capacitor/filesystem");
|
|
3913
|
-
var fileService = {
|
|
3914
|
-
async read(path) {
|
|
3915
|
-
try {
|
|
3916
|
-
const res = await import_filesystem.Filesystem.readFile({
|
|
3917
|
-
path,
|
|
3918
|
-
directory: import_filesystem.Directory.Data,
|
|
3919
|
-
encoding: import_filesystem.Encoding.UTF8
|
|
3920
|
-
});
|
|
3921
|
-
if (typeof res.data === "string") return res.data;
|
|
3922
|
-
if (res.data instanceof Blob) return await res.data.text();
|
|
3923
|
-
return null;
|
|
3924
|
-
} catch {
|
|
3925
|
-
return null;
|
|
3926
|
-
}
|
|
3927
|
-
},
|
|
3928
|
-
async write(path, data) {
|
|
3929
|
-
await import_filesystem.Filesystem.writeFile({
|
|
3930
|
-
path,
|
|
3931
|
-
data,
|
|
3932
|
-
directory: import_filesystem.Directory.Data,
|
|
3933
|
-
encoding: import_filesystem.Encoding.UTF8,
|
|
3934
|
-
recursive: true
|
|
3935
|
-
});
|
|
3936
|
-
},
|
|
3937
|
-
async writeAtomic(path, data) {
|
|
3938
|
-
const tempPath = path + ".tmp";
|
|
3939
|
-
await import_filesystem.Filesystem.writeFile({
|
|
3940
|
-
path: tempPath,
|
|
3941
|
-
data,
|
|
3942
|
-
directory: import_filesystem.Directory.Data,
|
|
3943
|
-
encoding: import_filesystem.Encoding.UTF8,
|
|
3944
|
-
recursive: true
|
|
3945
|
-
});
|
|
3946
|
-
try {
|
|
3947
|
-
await import_filesystem.Filesystem.deleteFile({
|
|
3948
|
-
path,
|
|
3949
|
-
directory: import_filesystem.Directory.Data
|
|
3950
|
-
});
|
|
3951
|
-
} catch {
|
|
3952
|
-
}
|
|
3953
|
-
await import_filesystem.Filesystem.rename({
|
|
3954
|
-
from: tempPath,
|
|
3955
|
-
to: path,
|
|
3956
|
-
directory: import_filesystem.Directory.Data
|
|
3957
|
-
});
|
|
3958
|
-
},
|
|
3959
|
-
async delete(path) {
|
|
3960
|
-
try {
|
|
3961
|
-
await import_filesystem.Filesystem.deleteFile({
|
|
3962
|
-
path,
|
|
3963
|
-
directory: import_filesystem.Directory.Data
|
|
3964
|
-
});
|
|
3965
|
-
} catch {
|
|
3966
|
-
}
|
|
3967
|
-
},
|
|
3968
|
-
async exists(path) {
|
|
3969
|
-
try {
|
|
3970
|
-
await import_filesystem.Filesystem.stat({
|
|
3971
|
-
path,
|
|
3972
|
-
directory: import_filesystem.Directory.Data
|
|
3973
|
-
});
|
|
3974
|
-
return true;
|
|
3975
|
-
} catch {
|
|
3976
|
-
return false;
|
|
3977
|
-
}
|
|
3978
|
-
},
|
|
3979
|
-
async mkdir(path) {
|
|
3980
|
-
try {
|
|
3981
|
-
await import_filesystem.Filesystem.mkdir({
|
|
3982
|
-
path,
|
|
3983
|
-
directory: import_filesystem.Directory.Data,
|
|
3984
|
-
recursive: true
|
|
3985
|
-
});
|
|
3986
|
-
} catch (e) {
|
|
3987
|
-
if (!String(e?.message).includes("Exists")) {
|
|
3988
|
-
throw e;
|
|
3989
|
-
}
|
|
3990
|
-
}
|
|
3991
|
-
},
|
|
3992
|
-
async list(path) {
|
|
3993
|
-
return import_filesystem.Filesystem.readdir({
|
|
3994
|
-
path,
|
|
3995
|
-
directory: import_filesystem.Directory.Data
|
|
3996
|
-
});
|
|
3997
|
-
},
|
|
3998
|
-
async getUri(path) {
|
|
3999
|
-
return import_filesystem.Filesystem.getUri({
|
|
4000
|
-
path,
|
|
4001
|
-
directory: import_filesystem.Directory.Data
|
|
4002
|
-
});
|
|
4003
|
-
}
|
|
4004
|
-
};
|
|
4005
|
-
|
|
4006
|
-
// src/services/filesystem-service/json-worker.ts
|
|
4007
|
-
function createWorkerBlob() {
|
|
4008
|
-
const workerCode = `
|
|
4009
|
-
self.addEventListener("message", async (ev) => {
|
|
4010
|
-
const { id, cmd, payload } = ev.data;
|
|
4011
|
-
try {
|
|
4012
|
-
if (cmd === "parse") {
|
|
4013
|
-
const parsed = JSON.parse(payload);
|
|
4014
|
-
self.postMessage({ id, ok: true, result: parsed });
|
|
4015
|
-
} else if (cmd === "stringify") {
|
|
4016
|
-
const str = JSON.stringify(payload);
|
|
4017
|
-
self.postMessage({ id, ok: true, result: str });
|
|
4018
|
-
}
|
|
4019
|
-
} catch (err) {
|
|
4020
|
-
self.postMessage({ id, ok: false, error: err?.message || String(err) });
|
|
4021
|
-
}
|
|
4022
|
-
});
|
|
4023
|
-
`;
|
|
4024
|
-
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
4025
|
-
return URL.createObjectURL(blob);
|
|
4026
|
-
}
|
|
4027
|
-
function spawnParseWorker(raw) {
|
|
4028
|
-
return new Promise((resolve, reject) => {
|
|
4029
|
-
const workerUrl = createWorkerBlob();
|
|
4030
|
-
const worker = new Worker(workerUrl);
|
|
4031
|
-
const id = Math.random().toString(36).slice(2);
|
|
4032
|
-
worker.onmessage = (ev) => {
|
|
4033
|
-
const { ok, result, error } = ev.data;
|
|
4034
|
-
if (ok) {
|
|
4035
|
-
resolve(result);
|
|
4036
|
-
} else {
|
|
4037
|
-
reject(new Error(error));
|
|
4038
|
-
}
|
|
4039
|
-
URL.revokeObjectURL(workerUrl);
|
|
4040
|
-
worker.terminate();
|
|
4041
|
-
};
|
|
4042
|
-
worker.onerror = (err) => {
|
|
4043
|
-
reject(err);
|
|
4044
|
-
URL.revokeObjectURL(workerUrl);
|
|
4045
|
-
worker.terminate();
|
|
4046
|
-
};
|
|
4047
|
-
worker.postMessage({ id, cmd: "parse", payload: raw });
|
|
4048
|
-
});
|
|
4049
|
-
}
|
|
4050
|
-
function spawnStringifyWorker(obj) {
|
|
4051
|
-
return new Promise((resolve, reject) => {
|
|
4052
|
-
const workerUrl = createWorkerBlob();
|
|
4053
|
-
const worker = new Worker(workerUrl);
|
|
4054
|
-
worker.onmessage = (ev) => {
|
|
4055
|
-
const { ok, result, error } = ev.data;
|
|
4056
|
-
if (ok) resolve(result);
|
|
4057
|
-
else reject(new Error(error));
|
|
4058
|
-
URL.revokeObjectURL(workerUrl);
|
|
4059
|
-
worker.terminate();
|
|
4060
|
-
};
|
|
4061
|
-
worker.onerror = (err) => {
|
|
4062
|
-
reject(err);
|
|
4063
|
-
URL.revokeObjectURL(workerUrl);
|
|
4064
|
-
worker.terminate();
|
|
4065
|
-
};
|
|
4066
|
-
worker.postMessage({ cmd: "stringify", payload: obj });
|
|
4067
|
-
});
|
|
4068
|
-
}
|
|
4352
|
+
ids,
|
|
4353
|
+
xNode,
|
|
4354
|
+
service,
|
|
4355
|
+
method
|
|
4356
|
+
}) => {
|
|
4357
|
+
const jsonData = {
|
|
4358
|
+
model,
|
|
4359
|
+
ids,
|
|
4360
|
+
method
|
|
4361
|
+
};
|
|
4362
|
+
return env?.requests.post(
|
|
4363
|
+
"/call" /* CALL_PATH */,
|
|
4364
|
+
jsonData,
|
|
4365
|
+
{
|
|
4366
|
+
headers: {
|
|
4367
|
+
"Content-Type": "application/json",
|
|
4368
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
4369
|
+
}
|
|
4370
|
+
},
|
|
4371
|
+
service
|
|
4372
|
+
);
|
|
4373
|
+
},
|
|
4374
|
+
[env]
|
|
4375
|
+
);
|
|
4376
|
+
return {
|
|
4377
|
+
handleCloseSession
|
|
4378
|
+
};
|
|
4379
|
+
};
|
|
4069
4380
|
|
|
4070
|
-
// src/services/
|
|
4071
|
-
var
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4381
|
+
// src/services/pos-service/handle-closing-detail-session.ts
|
|
4382
|
+
var import_react24 = require("react");
|
|
4383
|
+
var handleClosingDetailSessionService = (env) => {
|
|
4384
|
+
const handleClosingDetailSession = (0, import_react24.useCallback)(
|
|
4385
|
+
({
|
|
4386
|
+
model,
|
|
4387
|
+
ids,
|
|
4388
|
+
method,
|
|
4389
|
+
xNode,
|
|
4390
|
+
service,
|
|
4391
|
+
kwargs
|
|
4392
|
+
}) => {
|
|
4393
|
+
const jsonData = {
|
|
4394
|
+
model,
|
|
4395
|
+
ids,
|
|
4396
|
+
method,
|
|
4397
|
+
kwargs
|
|
4398
|
+
};
|
|
4399
|
+
return env?.requests.post(
|
|
4400
|
+
"/call" /* CALL_PATH */,
|
|
4401
|
+
jsonData,
|
|
4402
|
+
{
|
|
4403
|
+
headers: {
|
|
4404
|
+
"Content-Type": "application/json",
|
|
4405
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
4406
|
+
}
|
|
4407
|
+
},
|
|
4408
|
+
service
|
|
4409
|
+
);
|
|
4410
|
+
},
|
|
4411
|
+
[env]
|
|
4412
|
+
);
|
|
4413
|
+
return {
|
|
4414
|
+
handleClosingDetailSession
|
|
4415
|
+
};
|
|
4091
4416
|
};
|
|
4092
|
-
var memoryCache = new MemoryCache();
|
|
4093
4417
|
|
|
4094
|
-
// src/services/
|
|
4095
|
-
var
|
|
4096
|
-
var
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
}
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
const fileName = file.name;
|
|
4112
|
-
const modelName = fileName.replace(/\.json$/, "");
|
|
4113
|
-
const dataPath = `${MODELS_DIR}/${fileName}`;
|
|
4114
|
-
console.log("\u{1F4C2} Reading data from:", dataPath);
|
|
4115
|
-
const rawData = await fileService.read(dataPath);
|
|
4116
|
-
console.log("\u2705 Data read, length:", rawData?.length);
|
|
4117
|
-
if (!rawData) continue;
|
|
4118
|
-
console.log("\u{1F504} Parsing data...");
|
|
4119
|
-
const parsedData = await spawnParseWorker(rawData);
|
|
4120
|
-
console.log("\u2705 Data parsed");
|
|
4121
|
-
const data = Array.isArray(parsedData) ? parsedData : [];
|
|
4122
|
-
if (!includeMeta) {
|
|
4123
|
-
result[modelName] = { data };
|
|
4124
|
-
continue;
|
|
4125
|
-
}
|
|
4126
|
-
const metaPath = `${MODELS_META_DIR}/${encodeURIComponent(
|
|
4127
|
-
modelName
|
|
4128
|
-
)}.meta.json`;
|
|
4129
|
-
console.log("\u{1F4C2} Reading meta from:", metaPath);
|
|
4130
|
-
const rawMeta = await fileService.read(metaPath);
|
|
4131
|
-
let fields = [];
|
|
4132
|
-
let relations = {};
|
|
4133
|
-
if (rawMeta) {
|
|
4134
|
-
console.log("\u{1F504} Parsing meta...");
|
|
4135
|
-
const parsedMeta = await spawnParseWorker(rawMeta);
|
|
4136
|
-
fields = parsedMeta?.fields ?? [];
|
|
4137
|
-
relations = parsedMeta?.relations ?? {};
|
|
4138
|
-
console.log("\u2705 Meta parsed");
|
|
4139
|
-
}
|
|
4140
|
-
result[modelName] = {
|
|
4141
|
-
data,
|
|
4142
|
-
fields,
|
|
4143
|
-
relations
|
|
4418
|
+
// src/services/pos-service/handle-closing-session.ts
|
|
4419
|
+
var import_react25 = require("react");
|
|
4420
|
+
var handleClosingSessionService = (env) => {
|
|
4421
|
+
const handleClosingSession = (0, import_react25.useCallback)(
|
|
4422
|
+
({
|
|
4423
|
+
model,
|
|
4424
|
+
method,
|
|
4425
|
+
ids,
|
|
4426
|
+
kwargs,
|
|
4427
|
+
xNode,
|
|
4428
|
+
service
|
|
4429
|
+
}) => {
|
|
4430
|
+
const jsonData = {
|
|
4431
|
+
model,
|
|
4432
|
+
method,
|
|
4433
|
+
ids,
|
|
4434
|
+
kwargs
|
|
4144
4435
|
};
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
}
|
|
4436
|
+
return env?.requests.post(
|
|
4437
|
+
"/call" /* CALL_PATH */,
|
|
4438
|
+
jsonData,
|
|
4439
|
+
{
|
|
4440
|
+
headers: {
|
|
4441
|
+
"Content-Type": "application/json",
|
|
4442
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
4443
|
+
}
|
|
4444
|
+
},
|
|
4445
|
+
service
|
|
4446
|
+
);
|
|
4447
|
+
},
|
|
4448
|
+
[env]
|
|
4449
|
+
);
|
|
4450
|
+
return {
|
|
4451
|
+
handleClosingSession
|
|
4452
|
+
};
|
|
4453
|
+
};
|
|
4153
4454
|
|
|
4154
4455
|
// src/services/pos-service/load-data-pos-session.ts
|
|
4456
|
+
var import_react26 = require("react");
|
|
4155
4457
|
var loadDataPosSessionService = (env) => {
|
|
4156
4458
|
const isLocalMode = env?.isLocalMode;
|
|
4157
4459
|
const loadDataPosSession = (0, import_react26.useCallback)(
|
|
@@ -4164,10 +4466,8 @@ var loadDataPosSessionService = (env) => {
|
|
|
4164
4466
|
modelsToLoad = [],
|
|
4165
4467
|
searchParams
|
|
4166
4468
|
}) => {
|
|
4167
|
-
console.log("isLocalMode", isLocalMode);
|
|
4168
4469
|
if (isLocalMode) {
|
|
4169
4470
|
const data = await loadData();
|
|
4170
|
-
console.log("\u2705 loadData resolved:", data);
|
|
4171
4471
|
return data;
|
|
4172
4472
|
}
|
|
4173
4473
|
const jsonData = {
|
|
@@ -4421,6 +4721,8 @@ var updateClosedSessionService = (env) => {
|
|
|
4421
4721
|
// src/services/pos-service/update-entity.ts
|
|
4422
4722
|
var import_react33 = require("react");
|
|
4423
4723
|
var updateEntityService = (env) => {
|
|
4724
|
+
const isLocalMode = env?.isLocalMode;
|
|
4725
|
+
const repo = new ModelRepository();
|
|
4424
4726
|
const updateEntity = (0, import_react33.useCallback)(
|
|
4425
4727
|
({
|
|
4426
4728
|
model,
|
|
@@ -4430,6 +4732,15 @@ var updateEntityService = (env) => {
|
|
|
4430
4732
|
xNode,
|
|
4431
4733
|
service
|
|
4432
4734
|
}) => {
|
|
4735
|
+
if (isLocalMode) {
|
|
4736
|
+
const id = extractIdFromDomain(domain);
|
|
4737
|
+
if (!id) return;
|
|
4738
|
+
return repo.updateRecord({
|
|
4739
|
+
update: values,
|
|
4740
|
+
modelName: model,
|
|
4741
|
+
id
|
|
4742
|
+
});
|
|
4743
|
+
}
|
|
4433
4744
|
const jsonData = {
|
|
4434
4745
|
model,
|
|
4435
4746
|
domain,
|
|
@@ -4447,7 +4758,7 @@ var updateEntityService = (env) => {
|
|
|
4447
4758
|
service
|
|
4448
4759
|
);
|
|
4449
4760
|
},
|
|
4450
|
-
[env]
|
|
4761
|
+
[env, isLocalMode]
|
|
4451
4762
|
);
|
|
4452
4763
|
return {
|
|
4453
4764
|
updateEntity
|
|
@@ -6779,101 +7090,6 @@ function useDashboardService() {
|
|
|
6779
7090
|
return { readGroup, getDataChart };
|
|
6780
7091
|
}
|
|
6781
7092
|
|
|
6782
|
-
// src/services/filesystem-service/manifest.ts
|
|
6783
|
-
var MANIFEST_PATH = "pos/manifest.json";
|
|
6784
|
-
var MANIFEST_BAK_PATH = "pos/manifest.bak.json";
|
|
6785
|
-
async function writeManifest(manifest) {
|
|
6786
|
-
const oldRaw = await fileService.read(MANIFEST_PATH);
|
|
6787
|
-
if (oldRaw !== null) {
|
|
6788
|
-
await fileService.writeAtomic(MANIFEST_BAK_PATH, oldRaw);
|
|
6789
|
-
}
|
|
6790
|
-
await fileService.writeAtomic(MANIFEST_PATH, JSON.stringify(manifest));
|
|
6791
|
-
try {
|
|
6792
|
-
await fileService.delete(MANIFEST_BAK_PATH);
|
|
6793
|
-
} catch {
|
|
6794
|
-
}
|
|
6795
|
-
}
|
|
6796
|
-
|
|
6797
|
-
// src/services/filesystem-service/import-snapshot.ts
|
|
6798
|
-
var DATA_DIR = "pos";
|
|
6799
|
-
var MODELS_DIR2 = `${DATA_DIR}/models`;
|
|
6800
|
-
var MODELS_META_DIR2 = `${DATA_DIR}/models_meta`;
|
|
6801
|
-
var importSnapshot = async ({ data, onProgress }) => {
|
|
6802
|
-
onProgress?.(1, "Parsing snapshot");
|
|
6803
|
-
const parsed = await spawnParseWorker(data);
|
|
6804
|
-
const modelNames = Object.keys(parsed);
|
|
6805
|
-
const total = modelNames.length;
|
|
6806
|
-
const manifest = { version: (/* @__PURE__ */ new Date()).toISOString(), models: {} };
|
|
6807
|
-
const TMP_PREFIX = `pos/data/tmp_import_${Date.now()}`;
|
|
6808
|
-
await fileService.writeAtomic(`${TMP_PREFIX}/.marker`, "1");
|
|
6809
|
-
let i = 0;
|
|
6810
|
-
for (const model of modelNames) {
|
|
6811
|
-
i++;
|
|
6812
|
-
onProgress?.(
|
|
6813
|
-
Math.round(i / total * 100),
|
|
6814
|
-
`Processing ${model} (${i}/${total})`
|
|
6815
|
-
);
|
|
6816
|
-
const block = parsed[model];
|
|
6817
|
-
const dataPart = block?.data ?? block ?? [];
|
|
6818
|
-
const fields = block?.fields ?? [];
|
|
6819
|
-
const relations = block?.relations ?? {};
|
|
6820
|
-
const serialized = await spawnStringifyWorker(dataPart);
|
|
6821
|
-
const tmpModelPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.json`;
|
|
6822
|
-
await fileService.writeAtomic(tmpModelPath, serialized);
|
|
6823
|
-
const meta = {
|
|
6824
|
-
fields,
|
|
6825
|
-
relations,
|
|
6826
|
-
count: Array.isArray(dataPart) ? dataPart.length : 0,
|
|
6827
|
-
writtenAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
6828
|
-
};
|
|
6829
|
-
const tmpMetaPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`;
|
|
6830
|
-
await fileService.writeAtomic(tmpMetaPath, JSON.stringify(meta));
|
|
6831
|
-
manifest.models[model] = {
|
|
6832
|
-
file: `${MODELS_DIR2}/${encodeURIComponent(model)}.json`,
|
|
6833
|
-
metaFile: `${MODELS_META_DIR2}/${encodeURIComponent(model)}.meta.json`,
|
|
6834
|
-
count: meta.count,
|
|
6835
|
-
updatedAt: meta.writtenAt
|
|
6836
|
-
};
|
|
6837
|
-
}
|
|
6838
|
-
onProgress?.(95, "Committing import (moving files)");
|
|
6839
|
-
for (const model of modelNames) {
|
|
6840
|
-
const tmpModelPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.json`;
|
|
6841
|
-
const finalModelPath = `${MODELS_DIR2}/${encodeURIComponent(model)}.json`;
|
|
6842
|
-
const tmpMetaPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`;
|
|
6843
|
-
const finalMetaPath = `${MODELS_META_DIR2}/${encodeURIComponent(
|
|
6844
|
-
model
|
|
6845
|
-
)}.meta.json`;
|
|
6846
|
-
const tmpRaw = await fileService.read(tmpModelPath);
|
|
6847
|
-
if (tmpRaw !== null) await fileService.writeAtomic(finalModelPath, tmpRaw);
|
|
6848
|
-
const tmpMetaRaw = await fileService.read(tmpMetaPath);
|
|
6849
|
-
if (tmpMetaRaw !== null)
|
|
6850
|
-
await fileService.writeAtomic(finalMetaPath, tmpMetaRaw);
|
|
6851
|
-
onProgress?.(
|
|
6852
|
-
95 + Math.round(
|
|
6853
|
-
(Object.keys(manifest.models).indexOf(model) + 1) / modelNames.length * 5
|
|
6854
|
-
),
|
|
6855
|
-
`Committed ${model}`
|
|
6856
|
-
);
|
|
6857
|
-
}
|
|
6858
|
-
await writeManifest(manifest);
|
|
6859
|
-
try {
|
|
6860
|
-
for (const model of modelNames) {
|
|
6861
|
-
await fileService.delete(
|
|
6862
|
-
`${TMP_PREFIX}/${encodeURIComponent(model)}.json`
|
|
6863
|
-
);
|
|
6864
|
-
await fileService.delete(
|
|
6865
|
-
`${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`
|
|
6866
|
-
);
|
|
6867
|
-
}
|
|
6868
|
-
await fileService.delete(`${TMP_PREFIX}/.marker`);
|
|
6869
|
-
} catch (e) {
|
|
6870
|
-
console.log("Failed to cleanup tmp import files:", e);
|
|
6871
|
-
}
|
|
6872
|
-
onProgress?.(100, "Import complete");
|
|
6873
|
-
return manifest;
|
|
6874
|
-
};
|
|
6875
|
-
var import_snapshot_default = importSnapshot;
|
|
6876
|
-
|
|
6877
7093
|
// src/services/filesystem-service/init-snapshot.ts
|
|
6878
7094
|
var isSnapshotReady = async () => {
|
|
6879
7095
|
try {
|