@fctc/interface-logic 4.3.2 → 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 +761 -550
- package/dist/hooks.mjs +761 -550
- package/dist/provider.js +761 -550
- package/dist/provider.mjs +761 -550
- package/dist/services.js +761 -550
- package/dist/services.mjs +761 -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,633 @@ 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
|
+
const existingIds = getExistingIds(snapshot);
|
|
3634
|
+
const newId = generateNextId(existingIds, snapshot.data.length);
|
|
3635
|
+
snapshot.data.push({
|
|
3636
|
+
...newRecord,
|
|
3637
|
+
id: newId
|
|
3638
|
+
});
|
|
3639
|
+
const saved = await saveSnapshot({
|
|
3640
|
+
snapshot,
|
|
3641
|
+
modelName
|
|
3642
|
+
});
|
|
3643
|
+
if (!saved) {
|
|
3644
|
+
console.error("failed to add new record");
|
|
3645
|
+
return [];
|
|
3646
|
+
}
|
|
3647
|
+
console.log(`\u2705 ${snapshot.data.length} records saved`);
|
|
3648
|
+
return snapshot.data;
|
|
3649
|
+
} catch (error) {
|
|
3650
|
+
console.error("failed to add new record:", error);
|
|
3651
|
+
return [];
|
|
3652
|
+
}
|
|
3653
|
+
};
|
|
3654
|
+
updateRecord = async ({
|
|
3655
|
+
id,
|
|
3656
|
+
update,
|
|
3657
|
+
modelName
|
|
3658
|
+
}) => {
|
|
3659
|
+
try {
|
|
3660
|
+
const snapshot = await loadSnapshot({
|
|
3661
|
+
modelName
|
|
3662
|
+
});
|
|
3663
|
+
const index = snapshot.data.findIndex((record) => record.id === id);
|
|
3664
|
+
if (index === -1) {
|
|
3665
|
+
console.error(`record with id ${id} not found`);
|
|
3666
|
+
return false;
|
|
3667
|
+
}
|
|
3668
|
+
snapshot.data[index] = {
|
|
3669
|
+
...snapshot.data[index],
|
|
3670
|
+
...update
|
|
3671
|
+
};
|
|
3672
|
+
return await saveSnapshot({
|
|
3673
|
+
snapshot,
|
|
3674
|
+
modelName
|
|
3675
|
+
});
|
|
3676
|
+
} catch (error) {
|
|
3677
|
+
console.error("error updating record:", error);
|
|
3678
|
+
return false;
|
|
3679
|
+
}
|
|
3680
|
+
};
|
|
3681
|
+
deleteRecord = async ({
|
|
3682
|
+
id,
|
|
3683
|
+
modelName
|
|
3684
|
+
}) => {
|
|
3685
|
+
try {
|
|
3686
|
+
const snapshot = await loadSnapshot({
|
|
3687
|
+
modelName
|
|
3688
|
+
});
|
|
3689
|
+
const before = snapshot.data.length;
|
|
3690
|
+
snapshot.data = snapshot.data.filter((record) => record.id !== id);
|
|
3691
|
+
if (snapshot.data.length === before) {
|
|
3692
|
+
console.error(`record with id ${id} not found`);
|
|
3693
|
+
return false;
|
|
3694
|
+
}
|
|
3695
|
+
return await saveSnapshot({
|
|
3696
|
+
snapshot,
|
|
3697
|
+
modelName
|
|
3698
|
+
});
|
|
3699
|
+
} catch (error) {
|
|
3700
|
+
console.error("error deleting record:", error);
|
|
3701
|
+
return false;
|
|
3702
|
+
}
|
|
3703
|
+
};
|
|
3704
|
+
};
|
|
3705
|
+
|
|
3706
|
+
// src/services/pos-service/add-entity.ts
|
|
3707
|
+
var addEntityService = (env) => {
|
|
3708
|
+
const isLocalMode = env?.isLocalMode;
|
|
3709
|
+
const repo = new ModelRepository();
|
|
3710
|
+
const addEntity = (0, import_react7.useCallback)(
|
|
3711
|
+
({
|
|
3712
|
+
model,
|
|
3713
|
+
values,
|
|
3714
|
+
xNode,
|
|
3715
|
+
service,
|
|
3716
|
+
isCreateEndpoint = false
|
|
3717
|
+
}) => {
|
|
3718
|
+
if (isLocalMode) {
|
|
3719
|
+
return repo.addRecord({
|
|
3720
|
+
newRecord: values,
|
|
3721
|
+
modelName: model
|
|
3722
|
+
});
|
|
3723
|
+
}
|
|
3724
|
+
const jsonData = {
|
|
3725
|
+
model,
|
|
3726
|
+
values
|
|
3727
|
+
};
|
|
3728
|
+
return env?.requests.post(
|
|
3729
|
+
isCreateEndpoint ? "/create" /* CREATE_PATH */ : "/call" /* CALL_PATH */,
|
|
3730
|
+
jsonData,
|
|
3731
|
+
{
|
|
3732
|
+
headers: {
|
|
3733
|
+
"Content-Type": "application/json",
|
|
3734
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
3735
|
+
}
|
|
3736
|
+
},
|
|
3737
|
+
service
|
|
3738
|
+
);
|
|
3739
|
+
},
|
|
3740
|
+
[env, isLocalMode]
|
|
3741
|
+
);
|
|
3742
|
+
return {
|
|
3743
|
+
addEntity
|
|
3744
|
+
};
|
|
3745
|
+
};
|
|
3746
|
+
|
|
3747
|
+
// src/services/pos-service/change-order-preparation-state.ts
|
|
3748
|
+
var import_react8 = require("react");
|
|
3749
|
+
var changOrderPreparationStateService = (env) => {
|
|
3750
|
+
const changeOrderPreparationState = (0, import_react8.useCallback)(
|
|
3751
|
+
({
|
|
3752
|
+
orderId,
|
|
3753
|
+
stageId,
|
|
3754
|
+
preparationDisplayId,
|
|
3755
|
+
xNode,
|
|
3756
|
+
service
|
|
3757
|
+
}) => {
|
|
3758
|
+
const jsonData = {
|
|
3759
|
+
model: "pos_preparation_display.order" /* POS_PREPARATION_ORDER */,
|
|
3760
|
+
method: "change_order_stage" /* CHANGE_ORDER_STAGE */,
|
|
3761
|
+
ids: orderId,
|
|
3762
|
+
kwargs: {
|
|
3763
|
+
stage_id: stageId,
|
|
3764
|
+
preparation_display_id: preparationDisplayId
|
|
3765
|
+
}
|
|
3766
|
+
};
|
|
3767
|
+
return env?.requests.post(
|
|
3768
|
+
"/call" /* CALL_PATH */,
|
|
3769
|
+
jsonData,
|
|
3770
|
+
{
|
|
3771
|
+
headers: {
|
|
3772
|
+
"Content-Type": "application/json",
|
|
3773
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
3774
|
+
}
|
|
3775
|
+
},
|
|
3776
|
+
service
|
|
3777
|
+
);
|
|
3778
|
+
},
|
|
3779
|
+
[env]
|
|
3780
|
+
);
|
|
3781
|
+
return {
|
|
3782
|
+
changeOrderPreparationState
|
|
3783
|
+
};
|
|
3784
|
+
};
|
|
3785
|
+
|
|
3786
|
+
// src/services/pos-service/check-payment.ts
|
|
3787
|
+
var import_react9 = require("react");
|
|
3788
|
+
var checkPaymentService = (env) => {
|
|
3789
|
+
const checkPayment = (0, import_react9.useCallback)(
|
|
3790
|
+
({
|
|
3791
|
+
model,
|
|
3792
|
+
ids,
|
|
3793
|
+
withContext,
|
|
3794
|
+
xNode,
|
|
3795
|
+
service
|
|
3796
|
+
}) => {
|
|
3797
|
+
const jsonData = {
|
|
3798
|
+
model,
|
|
3799
|
+
method: "check" /* CHECK */,
|
|
3800
|
+
ids,
|
|
3801
|
+
with_context: withContext
|
|
3802
|
+
};
|
|
3803
|
+
return env?.requests.post(
|
|
3804
|
+
"/call" /* CALL_PATH */,
|
|
3805
|
+
jsonData,
|
|
3806
|
+
{
|
|
3807
|
+
headers: {
|
|
3808
|
+
"Content-Type": "application/json",
|
|
3809
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
3810
|
+
}
|
|
3811
|
+
},
|
|
3812
|
+
service
|
|
3813
|
+
);
|
|
3814
|
+
},
|
|
3815
|
+
[env]
|
|
3816
|
+
);
|
|
3817
|
+
return {
|
|
3818
|
+
checkPayment
|
|
3819
|
+
};
|
|
3820
|
+
};
|
|
3821
|
+
|
|
3822
|
+
// src/services/pos-service/create-e-invoice.ts
|
|
3823
|
+
var import_react10 = require("react");
|
|
3824
|
+
var createEInvoiceService = (env) => {
|
|
3301
3825
|
const createEInvoice = (0, import_react10.useCallback)(
|
|
3302
3826
|
async ({
|
|
3303
3827
|
service,
|
|
@@ -3335,6 +3859,8 @@ var createEInvoiceService = (env) => {
|
|
|
3335
3859
|
// src/services/pos-service/create-entity.ts
|
|
3336
3860
|
var import_react11 = require("react");
|
|
3337
3861
|
var createEntityService = (env) => {
|
|
3862
|
+
const isLocalMode = env?.isLocalMode;
|
|
3863
|
+
const repo = new ModelRepository();
|
|
3338
3864
|
const createEntity = (0, import_react11.useCallback)(
|
|
3339
3865
|
({
|
|
3340
3866
|
model,
|
|
@@ -3342,6 +3868,12 @@ var createEntityService = (env) => {
|
|
|
3342
3868
|
xNode,
|
|
3343
3869
|
service
|
|
3344
3870
|
}) => {
|
|
3871
|
+
if (isLocalMode) {
|
|
3872
|
+
return repo.addRecord({
|
|
3873
|
+
newRecord: args,
|
|
3874
|
+
modelName: model
|
|
3875
|
+
});
|
|
3876
|
+
}
|
|
3345
3877
|
const jsonData = {
|
|
3346
3878
|
model,
|
|
3347
3879
|
method: "create" /* CREATE */,
|
|
@@ -3359,7 +3891,7 @@ var createEntityService = (env) => {
|
|
|
3359
3891
|
service
|
|
3360
3892
|
);
|
|
3361
3893
|
},
|
|
3362
|
-
[env]
|
|
3894
|
+
[env, isLocalMode]
|
|
3363
3895
|
);
|
|
3364
3896
|
return {
|
|
3365
3897
|
createEntity
|
|
@@ -3444,6 +3976,8 @@ var createSessionService = (env) => {
|
|
|
3444
3976
|
// src/services/pos-service/delete-entity.ts
|
|
3445
3977
|
var import_react14 = require("react");
|
|
3446
3978
|
var deleteEntityService = (env) => {
|
|
3979
|
+
const isLocalMode = env?.isLocalMode;
|
|
3980
|
+
const repo = new ModelRepository();
|
|
3447
3981
|
const deleteEntity = (0, import_react14.useCallback)(
|
|
3448
3982
|
({
|
|
3449
3983
|
model,
|
|
@@ -3452,6 +3986,14 @@ var deleteEntityService = (env) => {
|
|
|
3452
3986
|
service,
|
|
3453
3987
|
method
|
|
3454
3988
|
}) => {
|
|
3989
|
+
if (isLocalMode) {
|
|
3990
|
+
const id = ids[0];
|
|
3991
|
+
if (!id) return;
|
|
3992
|
+
return repo.deleteRecord({
|
|
3993
|
+
modelName: model,
|
|
3994
|
+
id
|
|
3995
|
+
});
|
|
3996
|
+
}
|
|
3455
3997
|
const jsonData = {
|
|
3456
3998
|
model,
|
|
3457
3999
|
ids,
|
|
@@ -3469,7 +4011,7 @@ var deleteEntityService = (env) => {
|
|
|
3469
4011
|
service
|
|
3470
4012
|
);
|
|
3471
4013
|
},
|
|
3472
|
-
[env]
|
|
4014
|
+
[env, isLocalMode]
|
|
3473
4015
|
);
|
|
3474
4016
|
return {
|
|
3475
4017
|
deleteEntity
|
|
@@ -3802,356 +4344,111 @@ var handleCloseSessionService = (env) => {
|
|
|
3802
4344
|
const handleCloseSession = (0, import_react23.useCallback)(
|
|
3803
4345
|
({
|
|
3804
4346
|
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
|
-
}
|
|
4347
|
+
ids,
|
|
4348
|
+
xNode,
|
|
4349
|
+
service,
|
|
4350
|
+
method
|
|
4351
|
+
}) => {
|
|
4352
|
+
const jsonData = {
|
|
4353
|
+
model,
|
|
4354
|
+
ids,
|
|
4355
|
+
method
|
|
4356
|
+
};
|
|
4357
|
+
return env?.requests.post(
|
|
4358
|
+
"/call" /* CALL_PATH */,
|
|
4359
|
+
jsonData,
|
|
4360
|
+
{
|
|
4361
|
+
headers: {
|
|
4362
|
+
"Content-Type": "application/json",
|
|
4363
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
4364
|
+
}
|
|
4365
|
+
},
|
|
4366
|
+
service
|
|
4367
|
+
);
|
|
4368
|
+
},
|
|
4369
|
+
[env]
|
|
4370
|
+
);
|
|
4371
|
+
return {
|
|
4372
|
+
handleCloseSession
|
|
4373
|
+
};
|
|
4374
|
+
};
|
|
4069
4375
|
|
|
4070
|
-
// src/services/
|
|
4071
|
-
var
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4376
|
+
// src/services/pos-service/handle-closing-detail-session.ts
|
|
4377
|
+
var import_react24 = require("react");
|
|
4378
|
+
var handleClosingDetailSessionService = (env) => {
|
|
4379
|
+
const handleClosingDetailSession = (0, import_react24.useCallback)(
|
|
4380
|
+
({
|
|
4381
|
+
model,
|
|
4382
|
+
ids,
|
|
4383
|
+
method,
|
|
4384
|
+
xNode,
|
|
4385
|
+
service,
|
|
4386
|
+
kwargs
|
|
4387
|
+
}) => {
|
|
4388
|
+
const jsonData = {
|
|
4389
|
+
model,
|
|
4390
|
+
ids,
|
|
4391
|
+
method,
|
|
4392
|
+
kwargs
|
|
4393
|
+
};
|
|
4394
|
+
return env?.requests.post(
|
|
4395
|
+
"/call" /* CALL_PATH */,
|
|
4396
|
+
jsonData,
|
|
4397
|
+
{
|
|
4398
|
+
headers: {
|
|
4399
|
+
"Content-Type": "application/json",
|
|
4400
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
4401
|
+
}
|
|
4402
|
+
},
|
|
4403
|
+
service
|
|
4404
|
+
);
|
|
4405
|
+
},
|
|
4406
|
+
[env]
|
|
4407
|
+
);
|
|
4408
|
+
return {
|
|
4409
|
+
handleClosingDetailSession
|
|
4410
|
+
};
|
|
4091
4411
|
};
|
|
4092
|
-
var memoryCache = new MemoryCache();
|
|
4093
4412
|
|
|
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
|
|
4413
|
+
// src/services/pos-service/handle-closing-session.ts
|
|
4414
|
+
var import_react25 = require("react");
|
|
4415
|
+
var handleClosingSessionService = (env) => {
|
|
4416
|
+
const handleClosingSession = (0, import_react25.useCallback)(
|
|
4417
|
+
({
|
|
4418
|
+
model,
|
|
4419
|
+
method,
|
|
4420
|
+
ids,
|
|
4421
|
+
kwargs,
|
|
4422
|
+
xNode,
|
|
4423
|
+
service
|
|
4424
|
+
}) => {
|
|
4425
|
+
const jsonData = {
|
|
4426
|
+
model,
|
|
4427
|
+
method,
|
|
4428
|
+
ids,
|
|
4429
|
+
kwargs
|
|
4144
4430
|
};
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
}
|
|
4431
|
+
return env?.requests.post(
|
|
4432
|
+
"/call" /* CALL_PATH */,
|
|
4433
|
+
jsonData,
|
|
4434
|
+
{
|
|
4435
|
+
headers: {
|
|
4436
|
+
"Content-Type": "application/json",
|
|
4437
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
4438
|
+
}
|
|
4439
|
+
},
|
|
4440
|
+
service
|
|
4441
|
+
);
|
|
4442
|
+
},
|
|
4443
|
+
[env]
|
|
4444
|
+
);
|
|
4445
|
+
return {
|
|
4446
|
+
handleClosingSession
|
|
4447
|
+
};
|
|
4448
|
+
};
|
|
4153
4449
|
|
|
4154
4450
|
// src/services/pos-service/load-data-pos-session.ts
|
|
4451
|
+
var import_react26 = require("react");
|
|
4155
4452
|
var loadDataPosSessionService = (env) => {
|
|
4156
4453
|
const isLocalMode = env?.isLocalMode;
|
|
4157
4454
|
const loadDataPosSession = (0, import_react26.useCallback)(
|
|
@@ -4164,10 +4461,8 @@ var loadDataPosSessionService = (env) => {
|
|
|
4164
4461
|
modelsToLoad = [],
|
|
4165
4462
|
searchParams
|
|
4166
4463
|
}) => {
|
|
4167
|
-
console.log("isLocalMode", isLocalMode);
|
|
4168
4464
|
if (isLocalMode) {
|
|
4169
4465
|
const data = await loadData();
|
|
4170
|
-
console.log("\u2705 loadData resolved:", data);
|
|
4171
4466
|
return data;
|
|
4172
4467
|
}
|
|
4173
4468
|
const jsonData = {
|
|
@@ -4421,6 +4716,8 @@ var updateClosedSessionService = (env) => {
|
|
|
4421
4716
|
// src/services/pos-service/update-entity.ts
|
|
4422
4717
|
var import_react33 = require("react");
|
|
4423
4718
|
var updateEntityService = (env) => {
|
|
4719
|
+
const isLocalMode = env?.isLocalMode;
|
|
4720
|
+
const repo = new ModelRepository();
|
|
4424
4721
|
const updateEntity = (0, import_react33.useCallback)(
|
|
4425
4722
|
({
|
|
4426
4723
|
model,
|
|
@@ -4430,6 +4727,15 @@ var updateEntityService = (env) => {
|
|
|
4430
4727
|
xNode,
|
|
4431
4728
|
service
|
|
4432
4729
|
}) => {
|
|
4730
|
+
if (isLocalMode) {
|
|
4731
|
+
const id = extractIdFromDomain(domain);
|
|
4732
|
+
if (!id) return;
|
|
4733
|
+
return repo.updateRecord({
|
|
4734
|
+
update: values,
|
|
4735
|
+
modelName: model,
|
|
4736
|
+
id
|
|
4737
|
+
});
|
|
4738
|
+
}
|
|
4433
4739
|
const jsonData = {
|
|
4434
4740
|
model,
|
|
4435
4741
|
domain,
|
|
@@ -4447,7 +4753,7 @@ var updateEntityService = (env) => {
|
|
|
4447
4753
|
service
|
|
4448
4754
|
);
|
|
4449
4755
|
},
|
|
4450
|
-
[env]
|
|
4756
|
+
[env, isLocalMode]
|
|
4451
4757
|
);
|
|
4452
4758
|
return {
|
|
4453
4759
|
updateEntity
|
|
@@ -6779,101 +7085,6 @@ function useDashboardService() {
|
|
|
6779
7085
|
return { readGroup, getDataChart };
|
|
6780
7086
|
}
|
|
6781
7087
|
|
|
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
7088
|
// src/services/filesystem-service/init-snapshot.ts
|
|
6878
7089
|
var isSnapshotReady = async () => {
|
|
6879
7090
|
try {
|