@fctc/interface-logic 4.3.1 → 4.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks.js +777 -551
- package/dist/hooks.mjs +777 -550
- package/dist/provider.js +777 -551
- package/dist/provider.mjs +777 -550
- package/dist/services.js +777 -551
- package/dist/services.mjs +777 -550
- package/dist/utils.d.mts +2 -1
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +9 -0
- package/dist/utils.mjs +8 -0
- package/package.json +1 -1
package/dist/services.mjs
CHANGED
|
@@ -1606,9 +1606,9 @@ function applyBinaryOp(ast, context) {
|
|
|
1606
1606
|
var DICT = {
|
|
1607
1607
|
get(...args) {
|
|
1608
1608
|
const { key, defValue } = parseArgs(args, ["key", "defValue"]);
|
|
1609
|
-
const
|
|
1610
|
-
if (key in
|
|
1611
|
-
return
|
|
1609
|
+
const self = this;
|
|
1610
|
+
if (key in self) {
|
|
1611
|
+
return self[key];
|
|
1612
1612
|
} else if (defValue !== void 0) {
|
|
1613
1613
|
return defValue;
|
|
1614
1614
|
}
|
|
@@ -2178,6 +2178,13 @@ function cleanObject(obj) {
|
|
|
2178
2178
|
}
|
|
2179
2179
|
return result;
|
|
2180
2180
|
}
|
|
2181
|
+
var extractIdFromDomain = (domain) => {
|
|
2182
|
+
if (!domain || !Array.isArray(domain)) return null;
|
|
2183
|
+
const idCond = domain.find(
|
|
2184
|
+
([field, operator]) => field === "id" && operator === "="
|
|
2185
|
+
);
|
|
2186
|
+
return idCond ? Number(idCond[2]) : null;
|
|
2187
|
+
};
|
|
2181
2188
|
|
|
2182
2189
|
// src/provider/react-query-provider.tsx
|
|
2183
2190
|
import { useState as useState2 } from "react";
|
|
@@ -3141,130 +3148,647 @@ var getASessionService = (env) => {
|
|
|
3141
3148
|
|
|
3142
3149
|
// src/services/pos-service/add-entity.ts
|
|
3143
3150
|
import { useCallback as useCallback4 } from "react";
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
return
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3151
|
+
|
|
3152
|
+
// src/services/filesystem-service/file-service.ts
|
|
3153
|
+
import { Directory, Encoding, Filesystem } from "@capacitor/filesystem";
|
|
3154
|
+
var fileService = {
|
|
3155
|
+
read: async (path) => {
|
|
3156
|
+
try {
|
|
3157
|
+
const res = await Filesystem.readFile({
|
|
3158
|
+
path,
|
|
3159
|
+
directory: Directory.Data,
|
|
3160
|
+
encoding: Encoding.UTF8
|
|
3161
|
+
});
|
|
3162
|
+
if (typeof res.data === "string") return res.data;
|
|
3163
|
+
if (res.data instanceof Blob) return await res.data.text();
|
|
3164
|
+
return null;
|
|
3165
|
+
} catch {
|
|
3166
|
+
return null;
|
|
3167
|
+
}
|
|
3168
|
+
},
|
|
3169
|
+
write: async (path, data) => {
|
|
3170
|
+
await Filesystem.writeFile({
|
|
3171
|
+
path,
|
|
3172
|
+
data,
|
|
3173
|
+
directory: Directory.Data,
|
|
3174
|
+
encoding: Encoding.UTF8,
|
|
3175
|
+
recursive: true
|
|
3176
|
+
});
|
|
3177
|
+
},
|
|
3178
|
+
writeAtomic: async (path, data) => {
|
|
3179
|
+
const tempPath = path + ".tmp";
|
|
3180
|
+
await Filesystem.writeFile({
|
|
3181
|
+
path: tempPath,
|
|
3182
|
+
data,
|
|
3183
|
+
directory: Directory.Data,
|
|
3184
|
+
encoding: Encoding.UTF8,
|
|
3185
|
+
recursive: true
|
|
3186
|
+
});
|
|
3187
|
+
try {
|
|
3188
|
+
await Filesystem.deleteFile({
|
|
3189
|
+
path,
|
|
3190
|
+
directory: Directory.Data
|
|
3191
|
+
});
|
|
3192
|
+
} catch {
|
|
3193
|
+
}
|
|
3194
|
+
await Filesystem.rename({
|
|
3195
|
+
from: tempPath,
|
|
3196
|
+
to: path,
|
|
3197
|
+
directory: Directory.Data
|
|
3198
|
+
});
|
|
3199
|
+
},
|
|
3200
|
+
delete: async (path) => {
|
|
3201
|
+
try {
|
|
3202
|
+
await Filesystem.deleteFile({
|
|
3203
|
+
path,
|
|
3204
|
+
directory: Directory.Data
|
|
3205
|
+
});
|
|
3206
|
+
} catch {
|
|
3207
|
+
}
|
|
3208
|
+
},
|
|
3209
|
+
exists: async (path) => {
|
|
3210
|
+
try {
|
|
3211
|
+
await Filesystem.stat({
|
|
3212
|
+
path,
|
|
3213
|
+
directory: Directory.Data
|
|
3214
|
+
});
|
|
3215
|
+
return true;
|
|
3216
|
+
} catch {
|
|
3217
|
+
return false;
|
|
3218
|
+
}
|
|
3219
|
+
},
|
|
3220
|
+
mkdir: async (path) => {
|
|
3221
|
+
try {
|
|
3222
|
+
await Filesystem.mkdir({
|
|
3223
|
+
path,
|
|
3224
|
+
directory: Directory.Data,
|
|
3225
|
+
recursive: true
|
|
3226
|
+
});
|
|
3227
|
+
} catch (e) {
|
|
3228
|
+
if (!String(e?.message).includes("Exists")) {
|
|
3229
|
+
throw e;
|
|
3230
|
+
}
|
|
3231
|
+
}
|
|
3232
|
+
},
|
|
3233
|
+
list: async (path) => {
|
|
3234
|
+
return Filesystem.readdir({
|
|
3235
|
+
path,
|
|
3236
|
+
directory: Directory.Data
|
|
3237
|
+
});
|
|
3238
|
+
},
|
|
3239
|
+
getUri: async (path) => {
|
|
3240
|
+
return Filesystem.getUri({
|
|
3241
|
+
path,
|
|
3242
|
+
directory: Directory.Data
|
|
3243
|
+
});
|
|
3244
|
+
}
|
|
3174
3245
|
};
|
|
3175
3246
|
|
|
3176
|
-
// src/services/
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
model: "pos_preparation_display.order" /* POS_PREPARATION_ORDER */,
|
|
3189
|
-
method: "change_order_stage" /* CHANGE_ORDER_STAGE */,
|
|
3190
|
-
ids: orderId,
|
|
3191
|
-
kwargs: {
|
|
3192
|
-
stage_id: stageId,
|
|
3193
|
-
preparation_display_id: preparationDisplayId
|
|
3247
|
+
// src/services/filesystem-service/json-worker.ts
|
|
3248
|
+
function createWorkerBlob() {
|
|
3249
|
+
const workerCode = `
|
|
3250
|
+
self.addEventListener("message", async (ev) => {
|
|
3251
|
+
const { id, cmd, payload } = ev.data;
|
|
3252
|
+
try {
|
|
3253
|
+
if (cmd === "parse") {
|
|
3254
|
+
const parsed = JSON.parse(payload);
|
|
3255
|
+
self.postMessage({ id, ok: true, result: parsed });
|
|
3256
|
+
} else if (cmd === "stringify") {
|
|
3257
|
+
const str = JSON.stringify(payload);
|
|
3258
|
+
self.postMessage({ id, ok: true, result: str });
|
|
3194
3259
|
}
|
|
3195
|
-
}
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3260
|
+
} catch (err) {
|
|
3261
|
+
self.postMessage({ id, ok: false, error: err?.message || String(err) });
|
|
3262
|
+
}
|
|
3263
|
+
});
|
|
3264
|
+
`;
|
|
3265
|
+
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
3266
|
+
return URL.createObjectURL(blob);
|
|
3267
|
+
}
|
|
3268
|
+
function spawnParseWorker(raw) {
|
|
3269
|
+
return new Promise((resolve, reject) => {
|
|
3270
|
+
const workerUrl = createWorkerBlob();
|
|
3271
|
+
const worker = new Worker(workerUrl);
|
|
3272
|
+
const id = Math.random().toString(36).slice(2);
|
|
3273
|
+
worker.onmessage = (ev) => {
|
|
3274
|
+
const { ok, result, error } = ev.data;
|
|
3275
|
+
if (ok) {
|
|
3276
|
+
resolve(result);
|
|
3277
|
+
} else {
|
|
3278
|
+
reject(new Error(error));
|
|
3279
|
+
}
|
|
3280
|
+
URL.revokeObjectURL(workerUrl);
|
|
3281
|
+
worker.terminate();
|
|
3282
|
+
};
|
|
3283
|
+
worker.onerror = (err) => {
|
|
3284
|
+
reject(err);
|
|
3285
|
+
URL.revokeObjectURL(workerUrl);
|
|
3286
|
+
worker.terminate();
|
|
3287
|
+
};
|
|
3288
|
+
worker.postMessage({ id, cmd: "parse", payload: raw });
|
|
3289
|
+
});
|
|
3290
|
+
}
|
|
3291
|
+
function spawnStringifyWorker(obj) {
|
|
3292
|
+
return new Promise((resolve, reject) => {
|
|
3293
|
+
const workerUrl = createWorkerBlob();
|
|
3294
|
+
const worker = new Worker(workerUrl);
|
|
3295
|
+
worker.onmessage = (ev) => {
|
|
3296
|
+
const { ok, result, error } = ev.data;
|
|
3297
|
+
if (ok) resolve(result);
|
|
3298
|
+
else reject(new Error(error));
|
|
3299
|
+
URL.revokeObjectURL(workerUrl);
|
|
3300
|
+
worker.terminate();
|
|
3301
|
+
};
|
|
3302
|
+
worker.onerror = (err) => {
|
|
3303
|
+
reject(err);
|
|
3304
|
+
URL.revokeObjectURL(workerUrl);
|
|
3305
|
+
worker.terminate();
|
|
3306
|
+
};
|
|
3307
|
+
worker.postMessage({ cmd: "stringify", payload: obj });
|
|
3308
|
+
});
|
|
3309
|
+
}
|
|
3214
3310
|
|
|
3215
|
-
// src/services/
|
|
3216
|
-
|
|
3217
|
-
var
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
ids,
|
|
3230
|
-
with_context: withContext
|
|
3231
|
-
};
|
|
3232
|
-
return env?.requests.post(
|
|
3233
|
-
"/call" /* CALL_PATH */,
|
|
3234
|
-
jsonData,
|
|
3235
|
-
{
|
|
3236
|
-
headers: {
|
|
3237
|
-
"Content-Type": "application/json",
|
|
3238
|
-
...xNode ? { "X-Node": xNode } : {}
|
|
3239
|
-
}
|
|
3240
|
-
},
|
|
3241
|
-
service
|
|
3242
|
-
);
|
|
3243
|
-
},
|
|
3244
|
-
[env]
|
|
3245
|
-
);
|
|
3246
|
-
return {
|
|
3247
|
-
checkPayment
|
|
3248
|
-
};
|
|
3249
|
-
};
|
|
3311
|
+
// src/services/filesystem-service/manifest.ts
|
|
3312
|
+
var MANIFEST_PATH = "pos/manifest.json";
|
|
3313
|
+
var MANIFEST_BAK_PATH = "pos/manifest.bak.json";
|
|
3314
|
+
async function writeManifest(manifest) {
|
|
3315
|
+
const oldRaw = await fileService.read(MANIFEST_PATH);
|
|
3316
|
+
if (oldRaw !== null) {
|
|
3317
|
+
await fileService.writeAtomic(MANIFEST_BAK_PATH, oldRaw);
|
|
3318
|
+
}
|
|
3319
|
+
await fileService.writeAtomic(MANIFEST_PATH, JSON.stringify(manifest));
|
|
3320
|
+
try {
|
|
3321
|
+
await fileService.delete(MANIFEST_BAK_PATH);
|
|
3322
|
+
} catch {
|
|
3323
|
+
}
|
|
3324
|
+
}
|
|
3250
3325
|
|
|
3251
|
-
// src/services/
|
|
3252
|
-
|
|
3253
|
-
var
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3326
|
+
// src/services/filesystem-service/import-snapshot.ts
|
|
3327
|
+
var DATA_DIR = "pos";
|
|
3328
|
+
var MODELS_DIR = `${DATA_DIR}/models`;
|
|
3329
|
+
var MODELS_META_DIR = `${DATA_DIR}/models_meta`;
|
|
3330
|
+
var importSnapshot = async ({ data, onProgress }) => {
|
|
3331
|
+
onProgress?.(1, "Parsing snapshot");
|
|
3332
|
+
const parsed = await spawnParseWorker(data);
|
|
3333
|
+
const modelNames = Object.keys(parsed);
|
|
3334
|
+
const total = modelNames.length;
|
|
3335
|
+
const manifest = { version: (/* @__PURE__ */ new Date()).toISOString(), models: {} };
|
|
3336
|
+
const TMP_PREFIX = `pos/data/tmp_import_${Date.now()}`;
|
|
3337
|
+
await fileService.writeAtomic(`${TMP_PREFIX}/.marker`, "1");
|
|
3338
|
+
let i = 0;
|
|
3339
|
+
for (const model of modelNames) {
|
|
3340
|
+
i++;
|
|
3341
|
+
onProgress?.(
|
|
3342
|
+
Math.round(i / total * 100),
|
|
3343
|
+
`Processing ${model} (${i}/${total})`
|
|
3344
|
+
);
|
|
3345
|
+
const block = parsed[model];
|
|
3346
|
+
const dataPart = block?.data ?? block ?? [];
|
|
3347
|
+
const fields = block?.fields ?? [];
|
|
3348
|
+
const relations = block?.relations ?? {};
|
|
3349
|
+
const serialized = await spawnStringifyWorker(dataPart);
|
|
3350
|
+
const tmpModelPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.json`;
|
|
3351
|
+
await fileService.writeAtomic(tmpModelPath, serialized);
|
|
3352
|
+
const meta = {
|
|
3353
|
+
fields,
|
|
3354
|
+
relations,
|
|
3355
|
+
count: Array.isArray(dataPart) ? dataPart.length : 0,
|
|
3356
|
+
writtenAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3357
|
+
};
|
|
3358
|
+
const tmpMetaPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`;
|
|
3359
|
+
await fileService.writeAtomic(tmpMetaPath, JSON.stringify(meta));
|
|
3360
|
+
manifest.models[model] = {
|
|
3361
|
+
file: `${MODELS_DIR}/${encodeURIComponent(model)}.json`,
|
|
3362
|
+
metaFile: `${MODELS_META_DIR}/${encodeURIComponent(model)}.meta.json`,
|
|
3363
|
+
count: meta.count,
|
|
3364
|
+
updatedAt: meta.writtenAt
|
|
3365
|
+
};
|
|
3366
|
+
}
|
|
3367
|
+
onProgress?.(95, "Committing import (moving files)");
|
|
3368
|
+
for (const model of modelNames) {
|
|
3369
|
+
const tmpModelPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.json`;
|
|
3370
|
+
const finalModelPath = `${MODELS_DIR}/${encodeURIComponent(model)}.json`;
|
|
3371
|
+
const tmpMetaPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`;
|
|
3372
|
+
const finalMetaPath = `${MODELS_META_DIR}/${encodeURIComponent(
|
|
3373
|
+
model
|
|
3374
|
+
)}.meta.json`;
|
|
3375
|
+
const tmpRaw = await fileService.read(tmpModelPath);
|
|
3376
|
+
if (tmpRaw !== null) await fileService.writeAtomic(finalModelPath, tmpRaw);
|
|
3377
|
+
const tmpMetaRaw = await fileService.read(tmpMetaPath);
|
|
3378
|
+
if (tmpMetaRaw !== null)
|
|
3379
|
+
await fileService.writeAtomic(finalMetaPath, tmpMetaRaw);
|
|
3380
|
+
onProgress?.(
|
|
3381
|
+
95 + Math.round(
|
|
3382
|
+
(Object.keys(manifest.models).indexOf(model) + 1) / modelNames.length * 5
|
|
3383
|
+
),
|
|
3384
|
+
`Committed ${model}`
|
|
3385
|
+
);
|
|
3386
|
+
}
|
|
3387
|
+
await writeManifest(manifest);
|
|
3388
|
+
try {
|
|
3389
|
+
for (const model of modelNames) {
|
|
3390
|
+
await fileService.delete(
|
|
3391
|
+
`${TMP_PREFIX}/${encodeURIComponent(model)}.json`
|
|
3392
|
+
);
|
|
3393
|
+
await fileService.delete(
|
|
3394
|
+
`${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`
|
|
3395
|
+
);
|
|
3396
|
+
}
|
|
3397
|
+
await fileService.delete(`${TMP_PREFIX}/.marker`);
|
|
3398
|
+
} catch (e) {
|
|
3399
|
+
console.log("Failed to cleanup tmp import files:", e);
|
|
3400
|
+
}
|
|
3401
|
+
onProgress?.(100, "Import complete");
|
|
3402
|
+
return manifest;
|
|
3403
|
+
};
|
|
3404
|
+
var import_snapshot_default = importSnapshot;
|
|
3405
|
+
|
|
3406
|
+
// src/services/filesystem-service/memory-cache.ts
|
|
3407
|
+
var MemoryCache = class {
|
|
3408
|
+
map = /* @__PURE__ */ new Map();
|
|
3409
|
+
get(k) {
|
|
3410
|
+
const e = this.map.get(k);
|
|
3411
|
+
if (!e) return null;
|
|
3412
|
+
if (e.ttl && Date.now() - e.t > e.ttl) {
|
|
3413
|
+
this.map.delete(k);
|
|
3414
|
+
return null;
|
|
3415
|
+
}
|
|
3416
|
+
return e.value;
|
|
3417
|
+
}
|
|
3418
|
+
set(k, v, ttl = 5 * 60 * 1e3) {
|
|
3419
|
+
this.map.set(k, { value: v, t: Date.now(), ttl });
|
|
3420
|
+
}
|
|
3421
|
+
del(k) {
|
|
3422
|
+
this.map.delete(k);
|
|
3423
|
+
}
|
|
3424
|
+
clear() {
|
|
3425
|
+
this.map.clear();
|
|
3426
|
+
}
|
|
3427
|
+
};
|
|
3428
|
+
var memoryCache = new MemoryCache();
|
|
3429
|
+
|
|
3430
|
+
// src/services/filesystem-service/model-loader.ts
|
|
3431
|
+
var MODELS_DIR2 = "pos/models";
|
|
3432
|
+
var MODELS_META_DIR2 = "pos/models_meta";
|
|
3433
|
+
async function loadModelData(modelName, includeMeta = true) {
|
|
3434
|
+
const key = `model:${modelName}:meta:${includeMeta}`;
|
|
3435
|
+
const cached = memoryCache.get(key);
|
|
3436
|
+
if (cached) return cached;
|
|
3437
|
+
const dataPath = `${MODELS_DIR2}/${encodeURIComponent(modelName)}.json`;
|
|
3438
|
+
const metaPath = `${MODELS_META_DIR2}/${encodeURIComponent(
|
|
3439
|
+
modelName
|
|
3440
|
+
)}.meta.json`;
|
|
3441
|
+
const rawData = await fileService.read(dataPath);
|
|
3442
|
+
if (!rawData) return null;
|
|
3443
|
+
const parsedData = await spawnParseWorker(rawData);
|
|
3444
|
+
const data = Array.isArray(parsedData) ? parsedData : [];
|
|
3445
|
+
if (!includeMeta) {
|
|
3446
|
+
const result2 = { data };
|
|
3447
|
+
memoryCache.set(key, result2, 1e3 * 60 * 60);
|
|
3448
|
+
return result2;
|
|
3449
|
+
}
|
|
3450
|
+
const rawMeta = await fileService.read(metaPath);
|
|
3451
|
+
let fields = [];
|
|
3452
|
+
let relations = {};
|
|
3453
|
+
if (rawMeta) {
|
|
3454
|
+
const parsedMeta = await spawnParseWorker(rawMeta);
|
|
3455
|
+
fields = parsedMeta?.fields ?? [];
|
|
3456
|
+
relations = parsedMeta?.relations ?? {};
|
|
3457
|
+
}
|
|
3458
|
+
const result = {
|
|
3459
|
+
data,
|
|
3460
|
+
fields,
|
|
3461
|
+
relations
|
|
3462
|
+
};
|
|
3463
|
+
memoryCache.set(key, result, 1e3 * 60 * 60);
|
|
3464
|
+
return result;
|
|
3465
|
+
}
|
|
3466
|
+
async function loadData(includeMeta = true) {
|
|
3467
|
+
try {
|
|
3468
|
+
const listResult = await fileService.list(MODELS_DIR2);
|
|
3469
|
+
if (!listResult || !Array.isArray(listResult.files)) {
|
|
3470
|
+
console.log("No models found");
|
|
3471
|
+
return {};
|
|
3472
|
+
}
|
|
3473
|
+
const result = {};
|
|
3474
|
+
for (const file of listResult.files) {
|
|
3475
|
+
if (file.type !== "file") continue;
|
|
3476
|
+
if (!file.name.endsWith(".json")) continue;
|
|
3477
|
+
const fileName = file.name;
|
|
3478
|
+
const modelName = fileName.replace(/\.json$/, "");
|
|
3479
|
+
const dataPath = `${MODELS_DIR2}/${fileName}`;
|
|
3480
|
+
const rawData = await fileService.read(dataPath);
|
|
3481
|
+
if (!rawData) continue;
|
|
3482
|
+
const parsedData = await spawnParseWorker(rawData);
|
|
3483
|
+
const data = Array.isArray(parsedData) ? parsedData : [];
|
|
3484
|
+
if (!includeMeta) {
|
|
3485
|
+
result[modelName] = { data };
|
|
3486
|
+
continue;
|
|
3487
|
+
}
|
|
3488
|
+
const metaPath = `${MODELS_META_DIR2}/${encodeURIComponent(
|
|
3489
|
+
modelName
|
|
3490
|
+
)}.meta.json`;
|
|
3491
|
+
const rawMeta = await fileService.read(metaPath);
|
|
3492
|
+
let fields = [];
|
|
3493
|
+
let relations = {};
|
|
3494
|
+
if (rawMeta) {
|
|
3495
|
+
const parsedMeta = await spawnParseWorker(rawMeta);
|
|
3496
|
+
fields = parsedMeta?.fields ?? [];
|
|
3497
|
+
relations = parsedMeta?.relations ?? {};
|
|
3498
|
+
}
|
|
3499
|
+
result[modelName] = {
|
|
3500
|
+
data,
|
|
3501
|
+
fields,
|
|
3502
|
+
relations
|
|
3503
|
+
};
|
|
3504
|
+
}
|
|
3505
|
+
return result;
|
|
3506
|
+
} catch (error) {
|
|
3507
|
+
console.error("Error loading data:", error);
|
|
3508
|
+
throw error;
|
|
3509
|
+
}
|
|
3510
|
+
}
|
|
3511
|
+
|
|
3512
|
+
// src/services/filesystem-service/snapshot-helper.ts
|
|
3513
|
+
var createEmptySnapshot = () => {
|
|
3514
|
+
return {
|
|
3515
|
+
data: []
|
|
3516
|
+
};
|
|
3517
|
+
};
|
|
3518
|
+
var generateNextId = (existingIds, startFrom = 1) => {
|
|
3519
|
+
if (!existingIds || existingIds.length === 0) {
|
|
3520
|
+
return startFrom;
|
|
3521
|
+
}
|
|
3522
|
+
const maxId = Math.max(...existingIds, startFrom - 1);
|
|
3523
|
+
return maxId + 1;
|
|
3524
|
+
};
|
|
3525
|
+
var loadSnapshot = async ({
|
|
3526
|
+
modelName
|
|
3527
|
+
}) => {
|
|
3528
|
+
try {
|
|
3529
|
+
const snapshot = await loadModelData(modelName);
|
|
3530
|
+
if (!snapshot || typeof snapshot !== "object") {
|
|
3531
|
+
console.warn("invalid snapshot, creating new one");
|
|
3532
|
+
return createEmptySnapshot();
|
|
3533
|
+
}
|
|
3534
|
+
return {
|
|
3535
|
+
data: Array.isArray(snapshot.data) ? snapshot.data : []
|
|
3536
|
+
};
|
|
3537
|
+
} catch (error) {
|
|
3538
|
+
console.error("Failed to load snapshot:", error);
|
|
3539
|
+
return createEmptySnapshot();
|
|
3540
|
+
}
|
|
3541
|
+
};
|
|
3542
|
+
var getExistingIds = (snapshot) => {
|
|
3543
|
+
return snapshot.data.map((order) => order.id).filter((id) => typeof id === "number");
|
|
3544
|
+
};
|
|
3545
|
+
var saveSnapshot = async ({
|
|
3546
|
+
snapshot,
|
|
3547
|
+
modelName
|
|
3548
|
+
}) => {
|
|
3549
|
+
try {
|
|
3550
|
+
await import_snapshot_default({
|
|
3551
|
+
data: JSON.stringify({
|
|
3552
|
+
[modelName]: snapshot
|
|
3553
|
+
})
|
|
3554
|
+
});
|
|
3555
|
+
return true;
|
|
3556
|
+
} catch (error) {
|
|
3557
|
+
console.error("failed to save snapshot:", error);
|
|
3558
|
+
return false;
|
|
3559
|
+
}
|
|
3560
|
+
};
|
|
3561
|
+
|
|
3562
|
+
// src/services/filesystem-service/model-repository.ts
|
|
3563
|
+
var ModelRepository = class {
|
|
3564
|
+
getRecord = async ({
|
|
3565
|
+
id,
|
|
3566
|
+
modelName
|
|
3567
|
+
}) => {
|
|
3568
|
+
try {
|
|
3569
|
+
const snapshot = await loadSnapshot({
|
|
3570
|
+
modelName
|
|
3571
|
+
});
|
|
3572
|
+
return snapshot.data.find((record) => record.id === id) || null;
|
|
3573
|
+
} catch (error) {
|
|
3574
|
+
console.error("failed to get record:", error);
|
|
3575
|
+
return null;
|
|
3576
|
+
}
|
|
3577
|
+
};
|
|
3578
|
+
addRecord = async ({
|
|
3579
|
+
newRecord,
|
|
3580
|
+
modelName
|
|
3581
|
+
}) => {
|
|
3582
|
+
try {
|
|
3583
|
+
const snapshot = await loadSnapshot({
|
|
3584
|
+
modelName
|
|
3585
|
+
});
|
|
3586
|
+
const existingIds = getExistingIds(snapshot);
|
|
3587
|
+
const newId = generateNextId(existingIds, snapshot.data.length);
|
|
3588
|
+
snapshot.data.push({
|
|
3589
|
+
...newRecord,
|
|
3590
|
+
id: newId
|
|
3591
|
+
});
|
|
3592
|
+
const saved = await saveSnapshot({
|
|
3593
|
+
snapshot,
|
|
3594
|
+
modelName
|
|
3595
|
+
});
|
|
3596
|
+
if (!saved) {
|
|
3597
|
+
console.error("failed to add new record");
|
|
3598
|
+
return [];
|
|
3599
|
+
}
|
|
3600
|
+
console.log(`\u2705 ${snapshot.data.length} records saved`);
|
|
3601
|
+
return snapshot.data;
|
|
3602
|
+
} catch (error) {
|
|
3603
|
+
console.error("failed to add new record:", error);
|
|
3604
|
+
return [];
|
|
3605
|
+
}
|
|
3606
|
+
};
|
|
3607
|
+
updateRecord = async ({
|
|
3608
|
+
id,
|
|
3609
|
+
update,
|
|
3610
|
+
modelName
|
|
3611
|
+
}) => {
|
|
3612
|
+
try {
|
|
3613
|
+
const snapshot = await loadSnapshot({
|
|
3614
|
+
modelName
|
|
3615
|
+
});
|
|
3616
|
+
const index = snapshot.data.findIndex((record) => record.id === id);
|
|
3617
|
+
if (index === -1) {
|
|
3618
|
+
console.error(`record with id ${id} not found`);
|
|
3619
|
+
return false;
|
|
3620
|
+
}
|
|
3621
|
+
snapshot.data[index] = {
|
|
3622
|
+
...snapshot.data[index],
|
|
3623
|
+
...update
|
|
3624
|
+
};
|
|
3625
|
+
return await saveSnapshot({
|
|
3626
|
+
snapshot,
|
|
3627
|
+
modelName
|
|
3628
|
+
});
|
|
3629
|
+
} catch (error) {
|
|
3630
|
+
console.error("error updating record:", error);
|
|
3631
|
+
return false;
|
|
3632
|
+
}
|
|
3633
|
+
};
|
|
3634
|
+
deleteRecord = async ({
|
|
3635
|
+
id,
|
|
3636
|
+
modelName
|
|
3637
|
+
}) => {
|
|
3638
|
+
try {
|
|
3639
|
+
const snapshot = await loadSnapshot({
|
|
3640
|
+
modelName
|
|
3641
|
+
});
|
|
3642
|
+
const before = snapshot.data.length;
|
|
3643
|
+
snapshot.data = snapshot.data.filter((record) => record.id !== id);
|
|
3644
|
+
if (snapshot.data.length === before) {
|
|
3645
|
+
console.error(`record with id ${id} not found`);
|
|
3646
|
+
return false;
|
|
3647
|
+
}
|
|
3648
|
+
return await saveSnapshot({
|
|
3649
|
+
snapshot,
|
|
3650
|
+
modelName
|
|
3651
|
+
});
|
|
3652
|
+
} catch (error) {
|
|
3653
|
+
console.error("error deleting record:", error);
|
|
3654
|
+
return false;
|
|
3655
|
+
}
|
|
3656
|
+
};
|
|
3657
|
+
};
|
|
3658
|
+
|
|
3659
|
+
// src/services/pos-service/add-entity.ts
|
|
3660
|
+
var addEntityService = (env) => {
|
|
3661
|
+
const isLocalMode = env?.isLocalMode;
|
|
3662
|
+
const repo = new ModelRepository();
|
|
3663
|
+
const addEntity = useCallback4(
|
|
3664
|
+
({
|
|
3665
|
+
model,
|
|
3666
|
+
values,
|
|
3667
|
+
xNode,
|
|
3668
|
+
service,
|
|
3669
|
+
isCreateEndpoint = false
|
|
3670
|
+
}) => {
|
|
3671
|
+
if (isLocalMode) {
|
|
3672
|
+
return repo.addRecord({
|
|
3673
|
+
newRecord: values,
|
|
3674
|
+
modelName: model
|
|
3675
|
+
});
|
|
3676
|
+
}
|
|
3677
|
+
const jsonData = {
|
|
3678
|
+
model,
|
|
3679
|
+
values
|
|
3680
|
+
};
|
|
3681
|
+
return env?.requests.post(
|
|
3682
|
+
isCreateEndpoint ? "/create" /* CREATE_PATH */ : "/call" /* CALL_PATH */,
|
|
3683
|
+
jsonData,
|
|
3684
|
+
{
|
|
3685
|
+
headers: {
|
|
3686
|
+
"Content-Type": "application/json",
|
|
3687
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
3688
|
+
}
|
|
3689
|
+
},
|
|
3690
|
+
service
|
|
3691
|
+
);
|
|
3692
|
+
},
|
|
3693
|
+
[env, isLocalMode]
|
|
3694
|
+
);
|
|
3695
|
+
return {
|
|
3696
|
+
addEntity
|
|
3697
|
+
};
|
|
3698
|
+
};
|
|
3699
|
+
|
|
3700
|
+
// src/services/pos-service/change-order-preparation-state.ts
|
|
3701
|
+
import { useCallback as useCallback5 } from "react";
|
|
3702
|
+
var changOrderPreparationStateService = (env) => {
|
|
3703
|
+
const changeOrderPreparationState = useCallback5(
|
|
3704
|
+
({
|
|
3705
|
+
orderId,
|
|
3706
|
+
stageId,
|
|
3707
|
+
preparationDisplayId,
|
|
3708
|
+
xNode,
|
|
3709
|
+
service
|
|
3710
|
+
}) => {
|
|
3711
|
+
const jsonData = {
|
|
3712
|
+
model: "pos_preparation_display.order" /* POS_PREPARATION_ORDER */,
|
|
3713
|
+
method: "change_order_stage" /* CHANGE_ORDER_STAGE */,
|
|
3714
|
+
ids: orderId,
|
|
3715
|
+
kwargs: {
|
|
3716
|
+
stage_id: stageId,
|
|
3717
|
+
preparation_display_id: preparationDisplayId
|
|
3718
|
+
}
|
|
3719
|
+
};
|
|
3720
|
+
return env?.requests.post(
|
|
3721
|
+
"/call" /* CALL_PATH */,
|
|
3722
|
+
jsonData,
|
|
3723
|
+
{
|
|
3724
|
+
headers: {
|
|
3725
|
+
"Content-Type": "application/json",
|
|
3726
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
3727
|
+
}
|
|
3728
|
+
},
|
|
3729
|
+
service
|
|
3730
|
+
);
|
|
3731
|
+
},
|
|
3732
|
+
[env]
|
|
3733
|
+
);
|
|
3734
|
+
return {
|
|
3735
|
+
changeOrderPreparationState
|
|
3736
|
+
};
|
|
3737
|
+
};
|
|
3738
|
+
|
|
3739
|
+
// src/services/pos-service/check-payment.ts
|
|
3740
|
+
import { useCallback as useCallback6 } from "react";
|
|
3741
|
+
var checkPaymentService = (env) => {
|
|
3742
|
+
const checkPayment = useCallback6(
|
|
3743
|
+
({
|
|
3744
|
+
model,
|
|
3745
|
+
ids,
|
|
3746
|
+
withContext,
|
|
3747
|
+
xNode,
|
|
3748
|
+
service
|
|
3749
|
+
}) => {
|
|
3750
|
+
const jsonData = {
|
|
3751
|
+
model,
|
|
3752
|
+
method: "check" /* CHECK */,
|
|
3753
|
+
ids,
|
|
3754
|
+
with_context: withContext
|
|
3755
|
+
};
|
|
3756
|
+
return env?.requests.post(
|
|
3757
|
+
"/call" /* CALL_PATH */,
|
|
3758
|
+
jsonData,
|
|
3759
|
+
{
|
|
3760
|
+
headers: {
|
|
3761
|
+
"Content-Type": "application/json",
|
|
3762
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
3763
|
+
}
|
|
3764
|
+
},
|
|
3765
|
+
service
|
|
3766
|
+
);
|
|
3767
|
+
},
|
|
3768
|
+
[env]
|
|
3769
|
+
);
|
|
3770
|
+
return {
|
|
3771
|
+
checkPayment
|
|
3772
|
+
};
|
|
3773
|
+
};
|
|
3774
|
+
|
|
3775
|
+
// src/services/pos-service/create-e-invoice.ts
|
|
3776
|
+
import { useCallback as useCallback7 } from "react";
|
|
3777
|
+
var createEInvoiceService = (env) => {
|
|
3778
|
+
const createEInvoice = useCallback7(
|
|
3779
|
+
async ({
|
|
3780
|
+
service,
|
|
3781
|
+
xNode,
|
|
3782
|
+
kwargs,
|
|
3783
|
+
ids,
|
|
3784
|
+
withContext
|
|
3785
|
+
}) => {
|
|
3786
|
+
const body = {
|
|
3787
|
+
model: "pos.order" /* POS_ORDER */,
|
|
3788
|
+
method: "create_e_invoice" /* CREATE_E_INVOICE */,
|
|
3789
|
+
kwargs,
|
|
3790
|
+
ids,
|
|
3791
|
+
with_context: withContext
|
|
3268
3792
|
};
|
|
3269
3793
|
return env?.requests?.post(
|
|
3270
3794
|
`${"/call" /* CALL_PATH */}`,
|
|
@@ -3288,6 +3812,8 @@ var createEInvoiceService = (env) => {
|
|
|
3288
3812
|
// src/services/pos-service/create-entity.ts
|
|
3289
3813
|
import { useCallback as useCallback8 } from "react";
|
|
3290
3814
|
var createEntityService = (env) => {
|
|
3815
|
+
const isLocalMode = env?.isLocalMode;
|
|
3816
|
+
const repo = new ModelRepository();
|
|
3291
3817
|
const createEntity = useCallback8(
|
|
3292
3818
|
({
|
|
3293
3819
|
model,
|
|
@@ -3295,6 +3821,12 @@ var createEntityService = (env) => {
|
|
|
3295
3821
|
xNode,
|
|
3296
3822
|
service
|
|
3297
3823
|
}) => {
|
|
3824
|
+
if (isLocalMode) {
|
|
3825
|
+
return repo.addRecord({
|
|
3826
|
+
newRecord: args,
|
|
3827
|
+
modelName: model
|
|
3828
|
+
});
|
|
3829
|
+
}
|
|
3298
3830
|
const jsonData = {
|
|
3299
3831
|
model,
|
|
3300
3832
|
method: "create" /* CREATE */,
|
|
@@ -3312,7 +3844,7 @@ var createEntityService = (env) => {
|
|
|
3312
3844
|
service
|
|
3313
3845
|
);
|
|
3314
3846
|
},
|
|
3315
|
-
[env]
|
|
3847
|
+
[env, isLocalMode]
|
|
3316
3848
|
);
|
|
3317
3849
|
return {
|
|
3318
3850
|
createEntity
|
|
@@ -3397,6 +3929,8 @@ var createSessionService = (env) => {
|
|
|
3397
3929
|
// src/services/pos-service/delete-entity.ts
|
|
3398
3930
|
import { useCallback as useCallback11 } from "react";
|
|
3399
3931
|
var deleteEntityService = (env) => {
|
|
3932
|
+
const isLocalMode = env?.isLocalMode;
|
|
3933
|
+
const repo = new ModelRepository();
|
|
3400
3934
|
const deleteEntity = useCallback11(
|
|
3401
3935
|
({
|
|
3402
3936
|
model,
|
|
@@ -3405,6 +3939,14 @@ var deleteEntityService = (env) => {
|
|
|
3405
3939
|
service,
|
|
3406
3940
|
method
|
|
3407
3941
|
}) => {
|
|
3942
|
+
if (isLocalMode) {
|
|
3943
|
+
const id = ids[0];
|
|
3944
|
+
if (!id) return;
|
|
3945
|
+
return repo.deleteRecord({
|
|
3946
|
+
modelName: model,
|
|
3947
|
+
id
|
|
3948
|
+
});
|
|
3949
|
+
}
|
|
3408
3950
|
const jsonData = {
|
|
3409
3951
|
model,
|
|
3410
3952
|
ids,
|
|
@@ -3422,7 +3964,7 @@ var deleteEntityService = (env) => {
|
|
|
3422
3964
|
service
|
|
3423
3965
|
);
|
|
3424
3966
|
},
|
|
3425
|
-
[env]
|
|
3967
|
+
[env, isLocalMode]
|
|
3426
3968
|
);
|
|
3427
3969
|
return {
|
|
3428
3970
|
deleteEntity
|
|
@@ -3755,340 +4297,111 @@ var handleCloseSessionService = (env) => {
|
|
|
3755
4297
|
const handleCloseSession = useCallback20(
|
|
3756
4298
|
({
|
|
3757
4299
|
model,
|
|
3758
|
-
ids,
|
|
3759
|
-
xNode,
|
|
3760
|
-
service,
|
|
3761
|
-
method
|
|
3762
|
-
}) => {
|
|
3763
|
-
const jsonData = {
|
|
3764
|
-
model,
|
|
3765
|
-
ids,
|
|
3766
|
-
method
|
|
3767
|
-
};
|
|
3768
|
-
return env?.requests.post(
|
|
3769
|
-
"/call" /* CALL_PATH */,
|
|
3770
|
-
jsonData,
|
|
3771
|
-
{
|
|
3772
|
-
headers: {
|
|
3773
|
-
"Content-Type": "application/json",
|
|
3774
|
-
...xNode ? { "X-Node": xNode } : {}
|
|
3775
|
-
}
|
|
3776
|
-
},
|
|
3777
|
-
service
|
|
3778
|
-
);
|
|
3779
|
-
},
|
|
3780
|
-
[env]
|
|
3781
|
-
);
|
|
3782
|
-
return {
|
|
3783
|
-
handleCloseSession
|
|
3784
|
-
};
|
|
3785
|
-
};
|
|
3786
|
-
|
|
3787
|
-
// src/services/pos-service/handle-closing-detail-session.ts
|
|
3788
|
-
import { useCallback as useCallback21 } from "react";
|
|
3789
|
-
var handleClosingDetailSessionService = (env) => {
|
|
3790
|
-
const handleClosingDetailSession = useCallback21(
|
|
3791
|
-
({
|
|
3792
|
-
model,
|
|
3793
|
-
ids,
|
|
3794
|
-
method,
|
|
3795
|
-
xNode,
|
|
3796
|
-
service,
|
|
3797
|
-
kwargs
|
|
3798
|
-
}) => {
|
|
3799
|
-
const jsonData = {
|
|
3800
|
-
model,
|
|
3801
|
-
ids,
|
|
3802
|
-
method,
|
|
3803
|
-
kwargs
|
|
3804
|
-
};
|
|
3805
|
-
return env?.requests.post(
|
|
3806
|
-
"/call" /* CALL_PATH */,
|
|
3807
|
-
jsonData,
|
|
3808
|
-
{
|
|
3809
|
-
headers: {
|
|
3810
|
-
"Content-Type": "application/json",
|
|
3811
|
-
...xNode ? { "X-Node": xNode } : {}
|
|
3812
|
-
}
|
|
3813
|
-
},
|
|
3814
|
-
service
|
|
3815
|
-
);
|
|
3816
|
-
},
|
|
3817
|
-
[env]
|
|
3818
|
-
);
|
|
3819
|
-
return {
|
|
3820
|
-
handleClosingDetailSession
|
|
3821
|
-
};
|
|
3822
|
-
};
|
|
3823
|
-
|
|
3824
|
-
// src/services/pos-service/handle-closing-session.ts
|
|
3825
|
-
import { useCallback as useCallback22 } from "react";
|
|
3826
|
-
var handleClosingSessionService = (env) => {
|
|
3827
|
-
const handleClosingSession = useCallback22(
|
|
3828
|
-
({
|
|
3829
|
-
model,
|
|
3830
|
-
method,
|
|
3831
|
-
ids,
|
|
3832
|
-
kwargs,
|
|
3833
|
-
xNode,
|
|
3834
|
-
service
|
|
3835
|
-
}) => {
|
|
3836
|
-
const jsonData = {
|
|
3837
|
-
model,
|
|
3838
|
-
method,
|
|
3839
|
-
ids,
|
|
3840
|
-
kwargs
|
|
3841
|
-
};
|
|
3842
|
-
return env?.requests.post(
|
|
3843
|
-
"/call" /* CALL_PATH */,
|
|
3844
|
-
jsonData,
|
|
3845
|
-
{
|
|
3846
|
-
headers: {
|
|
3847
|
-
"Content-Type": "application/json",
|
|
3848
|
-
...xNode ? { "X-Node": xNode } : {}
|
|
3849
|
-
}
|
|
3850
|
-
},
|
|
3851
|
-
service
|
|
3852
|
-
);
|
|
3853
|
-
},
|
|
3854
|
-
[env]
|
|
3855
|
-
);
|
|
3856
|
-
return {
|
|
3857
|
-
handleClosingSession
|
|
3858
|
-
};
|
|
3859
|
-
};
|
|
3860
|
-
|
|
3861
|
-
// src/services/pos-service/load-data-pos-session.ts
|
|
3862
|
-
import { useCallback as useCallback23 } from "react";
|
|
3863
|
-
|
|
3864
|
-
// src/services/filesystem-service/file-service.ts
|
|
3865
|
-
import { Directory, Encoding, Filesystem } from "@capacitor/filesystem";
|
|
3866
|
-
var fileService = {
|
|
3867
|
-
async read(path) {
|
|
3868
|
-
try {
|
|
3869
|
-
const res = await Filesystem.readFile({
|
|
3870
|
-
path,
|
|
3871
|
-
directory: Directory.Data,
|
|
3872
|
-
encoding: Encoding.UTF8
|
|
3873
|
-
});
|
|
3874
|
-
if (typeof res.data === "string") return res.data;
|
|
3875
|
-
if (res.data instanceof Blob) return await res.data.text();
|
|
3876
|
-
return null;
|
|
3877
|
-
} catch {
|
|
3878
|
-
return null;
|
|
3879
|
-
}
|
|
3880
|
-
},
|
|
3881
|
-
async write(path, data) {
|
|
3882
|
-
await Filesystem.writeFile({
|
|
3883
|
-
path,
|
|
3884
|
-
data,
|
|
3885
|
-
directory: Directory.Data,
|
|
3886
|
-
encoding: Encoding.UTF8,
|
|
3887
|
-
recursive: true
|
|
3888
|
-
});
|
|
3889
|
-
},
|
|
3890
|
-
async writeAtomic(path, data) {
|
|
3891
|
-
const tempPath = path + ".tmp";
|
|
3892
|
-
await Filesystem.writeFile({
|
|
3893
|
-
path: tempPath,
|
|
3894
|
-
data,
|
|
3895
|
-
directory: Directory.Data,
|
|
3896
|
-
encoding: Encoding.UTF8,
|
|
3897
|
-
recursive: true
|
|
3898
|
-
});
|
|
3899
|
-
try {
|
|
3900
|
-
await Filesystem.deleteFile({
|
|
3901
|
-
path,
|
|
3902
|
-
directory: Directory.Data
|
|
3903
|
-
});
|
|
3904
|
-
} catch {
|
|
3905
|
-
}
|
|
3906
|
-
await Filesystem.rename({
|
|
3907
|
-
from: tempPath,
|
|
3908
|
-
to: path,
|
|
3909
|
-
directory: Directory.Data
|
|
3910
|
-
});
|
|
3911
|
-
},
|
|
3912
|
-
async delete(path) {
|
|
3913
|
-
try {
|
|
3914
|
-
await Filesystem.deleteFile({
|
|
3915
|
-
path,
|
|
3916
|
-
directory: Directory.Data
|
|
3917
|
-
});
|
|
3918
|
-
} catch {
|
|
3919
|
-
}
|
|
3920
|
-
},
|
|
3921
|
-
async exists(path) {
|
|
3922
|
-
try {
|
|
3923
|
-
await Filesystem.stat({
|
|
3924
|
-
path,
|
|
3925
|
-
directory: Directory.Data
|
|
3926
|
-
});
|
|
3927
|
-
return true;
|
|
3928
|
-
} catch {
|
|
3929
|
-
return false;
|
|
3930
|
-
}
|
|
3931
|
-
},
|
|
3932
|
-
async mkdir(path) {
|
|
3933
|
-
try {
|
|
3934
|
-
await Filesystem.mkdir({
|
|
3935
|
-
path,
|
|
3936
|
-
directory: Directory.Data,
|
|
3937
|
-
recursive: true
|
|
3938
|
-
});
|
|
3939
|
-
} catch (e) {
|
|
3940
|
-
if (!String(e?.message).includes("Exists")) {
|
|
3941
|
-
throw e;
|
|
3942
|
-
}
|
|
3943
|
-
}
|
|
3944
|
-
},
|
|
3945
|
-
async list(path) {
|
|
3946
|
-
return Filesystem.readdir({
|
|
3947
|
-
path,
|
|
3948
|
-
directory: Directory.Data
|
|
3949
|
-
});
|
|
3950
|
-
},
|
|
3951
|
-
async getUri(path) {
|
|
3952
|
-
return Filesystem.getUri({
|
|
3953
|
-
path,
|
|
3954
|
-
directory: Directory.Data
|
|
3955
|
-
});
|
|
3956
|
-
}
|
|
3957
|
-
};
|
|
3958
|
-
|
|
3959
|
-
// src/services/filesystem-service/json-worker.ts
|
|
3960
|
-
self.addEventListener("message", async (ev) => {
|
|
3961
|
-
const { id, cmd, payload } = ev.data;
|
|
3962
|
-
try {
|
|
3963
|
-
if (cmd === "parse") {
|
|
3964
|
-
const parsed = JSON.parse(payload);
|
|
3965
|
-
self.postMessage({ id, ok: true, result: parsed });
|
|
3966
|
-
} else if (cmd === "stringify") {
|
|
3967
|
-
const str = JSON.stringify(payload);
|
|
3968
|
-
self.postMessage({ id, ok: true, result: str });
|
|
3969
|
-
}
|
|
3970
|
-
} catch (err) {
|
|
3971
|
-
self.postMessage({ id, ok: false, error: err?.message || String(err) });
|
|
3972
|
-
}
|
|
3973
|
-
});
|
|
3974
|
-
function spawnParseWorker(raw) {
|
|
3975
|
-
return new Promise((resolve, reject) => {
|
|
3976
|
-
const worker = new Worker(new URL("./json-worker.ts", import.meta.url), {
|
|
3977
|
-
type: "module"
|
|
3978
|
-
});
|
|
3979
|
-
const id = Math.random().toString(36).slice(2);
|
|
3980
|
-
worker.onmessage = (ev) => {
|
|
3981
|
-
const { ok, result, error } = ev.data;
|
|
3982
|
-
if (ok) {
|
|
3983
|
-
resolve(result);
|
|
3984
|
-
} else {
|
|
3985
|
-
reject(new Error(error));
|
|
3986
|
-
}
|
|
3987
|
-
worker.terminate();
|
|
3988
|
-
};
|
|
3989
|
-
worker.postMessage({ id, cmd: "parse", payload: raw });
|
|
3990
|
-
});
|
|
3991
|
-
}
|
|
3992
|
-
function spawnStringifyWorker(obj) {
|
|
3993
|
-
return new Promise((resolve, reject) => {
|
|
3994
|
-
const worker = new Worker(new URL("./json-worker.ts", import.meta.url), {
|
|
3995
|
-
type: "module"
|
|
3996
|
-
});
|
|
3997
|
-
worker.onmessage = (ev) => {
|
|
3998
|
-
const { ok, result, error } = ev.data;
|
|
3999
|
-
if (ok) resolve(result);
|
|
4000
|
-
else reject(new Error(error));
|
|
4001
|
-
worker.terminate();
|
|
4002
|
-
};
|
|
4003
|
-
worker.postMessage({ cmd: "stringify", payload: obj });
|
|
4004
|
-
});
|
|
4005
|
-
}
|
|
4300
|
+
ids,
|
|
4301
|
+
xNode,
|
|
4302
|
+
service,
|
|
4303
|
+
method
|
|
4304
|
+
}) => {
|
|
4305
|
+
const jsonData = {
|
|
4306
|
+
model,
|
|
4307
|
+
ids,
|
|
4308
|
+
method
|
|
4309
|
+
};
|
|
4310
|
+
return env?.requests.post(
|
|
4311
|
+
"/call" /* CALL_PATH */,
|
|
4312
|
+
jsonData,
|
|
4313
|
+
{
|
|
4314
|
+
headers: {
|
|
4315
|
+
"Content-Type": "application/json",
|
|
4316
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
4317
|
+
}
|
|
4318
|
+
},
|
|
4319
|
+
service
|
|
4320
|
+
);
|
|
4321
|
+
},
|
|
4322
|
+
[env]
|
|
4323
|
+
);
|
|
4324
|
+
return {
|
|
4325
|
+
handleCloseSession
|
|
4326
|
+
};
|
|
4327
|
+
};
|
|
4006
4328
|
|
|
4007
|
-
// src/services/
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4329
|
+
// src/services/pos-service/handle-closing-detail-session.ts
|
|
4330
|
+
import { useCallback as useCallback21 } from "react";
|
|
4331
|
+
var handleClosingDetailSessionService = (env) => {
|
|
4332
|
+
const handleClosingDetailSession = useCallback21(
|
|
4333
|
+
({
|
|
4334
|
+
model,
|
|
4335
|
+
ids,
|
|
4336
|
+
method,
|
|
4337
|
+
xNode,
|
|
4338
|
+
service,
|
|
4339
|
+
kwargs
|
|
4340
|
+
}) => {
|
|
4341
|
+
const jsonData = {
|
|
4342
|
+
model,
|
|
4343
|
+
ids,
|
|
4344
|
+
method,
|
|
4345
|
+
kwargs
|
|
4346
|
+
};
|
|
4347
|
+
return env?.requests.post(
|
|
4348
|
+
"/call" /* CALL_PATH */,
|
|
4349
|
+
jsonData,
|
|
4350
|
+
{
|
|
4351
|
+
headers: {
|
|
4352
|
+
"Content-Type": "application/json",
|
|
4353
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
4354
|
+
}
|
|
4355
|
+
},
|
|
4356
|
+
service
|
|
4357
|
+
);
|
|
4358
|
+
},
|
|
4359
|
+
[env]
|
|
4360
|
+
);
|
|
4361
|
+
return {
|
|
4362
|
+
handleClosingDetailSession
|
|
4363
|
+
};
|
|
4028
4364
|
};
|
|
4029
|
-
var memoryCache = new MemoryCache();
|
|
4030
4365
|
|
|
4031
|
-
// src/services/
|
|
4032
|
-
|
|
4033
|
-
var
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
}
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
const fileName = file.name;
|
|
4049
|
-
const modelName = fileName.replace(/\.json$/, "");
|
|
4050
|
-
const dataPath = `${MODELS_DIR}/${fileName}`;
|
|
4051
|
-
console.log("\u{1F4C2} Reading data from:", dataPath);
|
|
4052
|
-
const rawData = await fileService.read(dataPath);
|
|
4053
|
-
console.log("\u2705 Data read, length:", rawData?.length);
|
|
4054
|
-
if (!rawData) continue;
|
|
4055
|
-
console.log("\u{1F504} Parsing data...");
|
|
4056
|
-
const parsedData = await spawnParseWorker(rawData);
|
|
4057
|
-
console.log("\u2705 Data parsed");
|
|
4058
|
-
const data = Array.isArray(parsedData) ? parsedData : [];
|
|
4059
|
-
if (!includeMeta) {
|
|
4060
|
-
result[modelName] = { data };
|
|
4061
|
-
continue;
|
|
4062
|
-
}
|
|
4063
|
-
const metaPath = `${MODELS_META_DIR}/${encodeURIComponent(
|
|
4064
|
-
modelName
|
|
4065
|
-
)}.meta.json`;
|
|
4066
|
-
console.log("\u{1F4C2} Reading meta from:", metaPath);
|
|
4067
|
-
const rawMeta = await fileService.read(metaPath);
|
|
4068
|
-
let fields = [];
|
|
4069
|
-
let relations = {};
|
|
4070
|
-
if (rawMeta) {
|
|
4071
|
-
console.log("\u{1F504} Parsing meta...");
|
|
4072
|
-
const parsedMeta = await spawnParseWorker(rawMeta);
|
|
4073
|
-
fields = parsedMeta?.fields ?? [];
|
|
4074
|
-
relations = parsedMeta?.relations ?? {};
|
|
4075
|
-
console.log("\u2705 Meta parsed");
|
|
4076
|
-
}
|
|
4077
|
-
result[modelName] = {
|
|
4078
|
-
data,
|
|
4079
|
-
fields,
|
|
4080
|
-
relations
|
|
4366
|
+
// src/services/pos-service/handle-closing-session.ts
|
|
4367
|
+
import { useCallback as useCallback22 } from "react";
|
|
4368
|
+
var handleClosingSessionService = (env) => {
|
|
4369
|
+
const handleClosingSession = useCallback22(
|
|
4370
|
+
({
|
|
4371
|
+
model,
|
|
4372
|
+
method,
|
|
4373
|
+
ids,
|
|
4374
|
+
kwargs,
|
|
4375
|
+
xNode,
|
|
4376
|
+
service
|
|
4377
|
+
}) => {
|
|
4378
|
+
const jsonData = {
|
|
4379
|
+
model,
|
|
4380
|
+
method,
|
|
4381
|
+
ids,
|
|
4382
|
+
kwargs
|
|
4081
4383
|
};
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
}
|
|
4384
|
+
return env?.requests.post(
|
|
4385
|
+
"/call" /* CALL_PATH */,
|
|
4386
|
+
jsonData,
|
|
4387
|
+
{
|
|
4388
|
+
headers: {
|
|
4389
|
+
"Content-Type": "application/json",
|
|
4390
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
4391
|
+
}
|
|
4392
|
+
},
|
|
4393
|
+
service
|
|
4394
|
+
);
|
|
4395
|
+
},
|
|
4396
|
+
[env]
|
|
4397
|
+
);
|
|
4398
|
+
return {
|
|
4399
|
+
handleClosingSession
|
|
4400
|
+
};
|
|
4401
|
+
};
|
|
4090
4402
|
|
|
4091
4403
|
// src/services/pos-service/load-data-pos-session.ts
|
|
4404
|
+
import { useCallback as useCallback23 } from "react";
|
|
4092
4405
|
var loadDataPosSessionService = (env) => {
|
|
4093
4406
|
const isLocalMode = env?.isLocalMode;
|
|
4094
4407
|
const loadDataPosSession = useCallback23(
|
|
@@ -4101,10 +4414,8 @@ var loadDataPosSessionService = (env) => {
|
|
|
4101
4414
|
modelsToLoad = [],
|
|
4102
4415
|
searchParams
|
|
4103
4416
|
}) => {
|
|
4104
|
-
console.log("isLocalMode", isLocalMode);
|
|
4105
4417
|
if (isLocalMode) {
|
|
4106
4418
|
const data = await loadData();
|
|
4107
|
-
console.log("\u2705 loadData resolved:", data);
|
|
4108
4419
|
return data;
|
|
4109
4420
|
}
|
|
4110
4421
|
const jsonData = {
|
|
@@ -4358,6 +4669,8 @@ var updateClosedSessionService = (env) => {
|
|
|
4358
4669
|
// src/services/pos-service/update-entity.ts
|
|
4359
4670
|
import { useCallback as useCallback30 } from "react";
|
|
4360
4671
|
var updateEntityService = (env) => {
|
|
4672
|
+
const isLocalMode = env?.isLocalMode;
|
|
4673
|
+
const repo = new ModelRepository();
|
|
4361
4674
|
const updateEntity = useCallback30(
|
|
4362
4675
|
({
|
|
4363
4676
|
model,
|
|
@@ -4367,6 +4680,15 @@ var updateEntityService = (env) => {
|
|
|
4367
4680
|
xNode,
|
|
4368
4681
|
service
|
|
4369
4682
|
}) => {
|
|
4683
|
+
if (isLocalMode) {
|
|
4684
|
+
const id = extractIdFromDomain(domain);
|
|
4685
|
+
if (!id) return;
|
|
4686
|
+
return repo.updateRecord({
|
|
4687
|
+
update: values,
|
|
4688
|
+
modelName: model,
|
|
4689
|
+
id
|
|
4690
|
+
});
|
|
4691
|
+
}
|
|
4370
4692
|
const jsonData = {
|
|
4371
4693
|
model,
|
|
4372
4694
|
domain,
|
|
@@ -4384,7 +4706,7 @@ var updateEntityService = (env) => {
|
|
|
4384
4706
|
service
|
|
4385
4707
|
);
|
|
4386
4708
|
},
|
|
4387
|
-
[env]
|
|
4709
|
+
[env, isLocalMode]
|
|
4388
4710
|
);
|
|
4389
4711
|
return {
|
|
4390
4712
|
updateEntity
|
|
@@ -6716,101 +7038,6 @@ function useDashboardService() {
|
|
|
6716
7038
|
return { readGroup, getDataChart };
|
|
6717
7039
|
}
|
|
6718
7040
|
|
|
6719
|
-
// src/services/filesystem-service/manifest.ts
|
|
6720
|
-
var MANIFEST_PATH = "pos/manifest.json";
|
|
6721
|
-
var MANIFEST_BAK_PATH = "pos/manifest.bak.json";
|
|
6722
|
-
async function writeManifest(manifest) {
|
|
6723
|
-
const oldRaw = await fileService.read(MANIFEST_PATH);
|
|
6724
|
-
if (oldRaw !== null) {
|
|
6725
|
-
await fileService.writeAtomic(MANIFEST_BAK_PATH, oldRaw);
|
|
6726
|
-
}
|
|
6727
|
-
await fileService.writeAtomic(MANIFEST_PATH, JSON.stringify(manifest));
|
|
6728
|
-
try {
|
|
6729
|
-
await fileService.delete(MANIFEST_BAK_PATH);
|
|
6730
|
-
} catch {
|
|
6731
|
-
}
|
|
6732
|
-
}
|
|
6733
|
-
|
|
6734
|
-
// src/services/filesystem-service/import-snapshot.ts
|
|
6735
|
-
var DATA_DIR = "pos";
|
|
6736
|
-
var MODELS_DIR2 = `${DATA_DIR}/models`;
|
|
6737
|
-
var MODELS_META_DIR2 = `${DATA_DIR}/models_meta`;
|
|
6738
|
-
var importSnapshot = async ({ data, onProgress }) => {
|
|
6739
|
-
onProgress?.(1, "Parsing snapshot");
|
|
6740
|
-
const parsed = await spawnParseWorker(data);
|
|
6741
|
-
const modelNames = Object.keys(parsed);
|
|
6742
|
-
const total = modelNames.length;
|
|
6743
|
-
const manifest = { version: (/* @__PURE__ */ new Date()).toISOString(), models: {} };
|
|
6744
|
-
const TMP_PREFIX = `pos/data/tmp_import_${Date.now()}`;
|
|
6745
|
-
await fileService.writeAtomic(`${TMP_PREFIX}/.marker`, "1");
|
|
6746
|
-
let i = 0;
|
|
6747
|
-
for (const model of modelNames) {
|
|
6748
|
-
i++;
|
|
6749
|
-
onProgress?.(
|
|
6750
|
-
Math.round(i / total * 100),
|
|
6751
|
-
`Processing ${model} (${i}/${total})`
|
|
6752
|
-
);
|
|
6753
|
-
const block = parsed[model];
|
|
6754
|
-
const dataPart = block?.data ?? block ?? [];
|
|
6755
|
-
const fields = block?.fields ?? [];
|
|
6756
|
-
const relations = block?.relations ?? {};
|
|
6757
|
-
const serialized = await spawnStringifyWorker(dataPart);
|
|
6758
|
-
const tmpModelPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.json`;
|
|
6759
|
-
await fileService.writeAtomic(tmpModelPath, serialized);
|
|
6760
|
-
const meta = {
|
|
6761
|
-
fields,
|
|
6762
|
-
relations,
|
|
6763
|
-
count: Array.isArray(dataPart) ? dataPart.length : 0,
|
|
6764
|
-
writtenAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
6765
|
-
};
|
|
6766
|
-
const tmpMetaPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`;
|
|
6767
|
-
await fileService.writeAtomic(tmpMetaPath, JSON.stringify(meta));
|
|
6768
|
-
manifest.models[model] = {
|
|
6769
|
-
file: `${MODELS_DIR2}/${encodeURIComponent(model)}.json`,
|
|
6770
|
-
metaFile: `${MODELS_META_DIR2}/${encodeURIComponent(model)}.meta.json`,
|
|
6771
|
-
count: meta.count,
|
|
6772
|
-
updatedAt: meta.writtenAt
|
|
6773
|
-
};
|
|
6774
|
-
}
|
|
6775
|
-
onProgress?.(95, "Committing import (moving files)");
|
|
6776
|
-
for (const model of modelNames) {
|
|
6777
|
-
const tmpModelPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.json`;
|
|
6778
|
-
const finalModelPath = `${MODELS_DIR2}/${encodeURIComponent(model)}.json`;
|
|
6779
|
-
const tmpMetaPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`;
|
|
6780
|
-
const finalMetaPath = `${MODELS_META_DIR2}/${encodeURIComponent(
|
|
6781
|
-
model
|
|
6782
|
-
)}.meta.json`;
|
|
6783
|
-
const tmpRaw = await fileService.read(tmpModelPath);
|
|
6784
|
-
if (tmpRaw !== null) await fileService.writeAtomic(finalModelPath, tmpRaw);
|
|
6785
|
-
const tmpMetaRaw = await fileService.read(tmpMetaPath);
|
|
6786
|
-
if (tmpMetaRaw !== null)
|
|
6787
|
-
await fileService.writeAtomic(finalMetaPath, tmpMetaRaw);
|
|
6788
|
-
onProgress?.(
|
|
6789
|
-
95 + Math.round(
|
|
6790
|
-
(Object.keys(manifest.models).indexOf(model) + 1) / modelNames.length * 5
|
|
6791
|
-
),
|
|
6792
|
-
`Committed ${model}`
|
|
6793
|
-
);
|
|
6794
|
-
}
|
|
6795
|
-
await writeManifest(manifest);
|
|
6796
|
-
try {
|
|
6797
|
-
for (const model of modelNames) {
|
|
6798
|
-
await fileService.delete(
|
|
6799
|
-
`${TMP_PREFIX}/${encodeURIComponent(model)}.json`
|
|
6800
|
-
);
|
|
6801
|
-
await fileService.delete(
|
|
6802
|
-
`${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`
|
|
6803
|
-
);
|
|
6804
|
-
}
|
|
6805
|
-
await fileService.delete(`${TMP_PREFIX}/.marker`);
|
|
6806
|
-
} catch (e) {
|
|
6807
|
-
console.log("Failed to cleanup tmp import files:", e);
|
|
6808
|
-
}
|
|
6809
|
-
onProgress?.(100, "Import complete");
|
|
6810
|
-
return manifest;
|
|
6811
|
-
};
|
|
6812
|
-
var import_snapshot_default = importSnapshot;
|
|
6813
|
-
|
|
6814
7041
|
// src/services/filesystem-service/init-snapshot.ts
|
|
6815
7042
|
var isSnapshotReady = async () => {
|
|
6816
7043
|
try {
|