@fctc/interface-logic 4.3.2 → 4.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks.js +766 -550
- package/dist/hooks.mjs +766 -550
- package/dist/provider.js +766 -550
- package/dist/provider.mjs +766 -550
- package/dist/services.js +766 -550
- package/dist/services.mjs +766 -550
- package/dist/utils.d.mts +2 -1
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +9 -0
- package/dist/utils.mjs +8 -0
- package/package.json +1 -1
package/dist/services.mjs
CHANGED
|
@@ -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,116 +3148,638 @@ var getASessionService = (env) => {
|
|
|
3141
3148
|
|
|
3142
3149
|
// src/services/pos-service/add-entity.ts
|
|
3143
3150
|
import { useCallback as useCallback4 } from "react";
|
|
3144
|
-
var addEntityService = (env) => {
|
|
3145
|
-
const addEntity = useCallback4(
|
|
3146
|
-
({
|
|
3147
|
-
model,
|
|
3148
|
-
values,
|
|
3149
|
-
xNode,
|
|
3150
|
-
service,
|
|
3151
|
-
isCreateEndpoint = false
|
|
3152
|
-
}) => {
|
|
3153
|
-
const jsonData = {
|
|
3154
|
-
model,
|
|
3155
|
-
values
|
|
3156
|
-
};
|
|
3157
|
-
return env?.requests.post(
|
|
3158
|
-
isCreateEndpoint ? "/create" /* CREATE_PATH */ : "/call" /* CALL_PATH */,
|
|
3159
|
-
jsonData,
|
|
3160
|
-
{
|
|
3161
|
-
headers: {
|
|
3162
|
-
"Content-Type": "application/json",
|
|
3163
|
-
...xNode ? { "X-Node": xNode } : {}
|
|
3164
|
-
}
|
|
3165
|
-
},
|
|
3166
|
-
service
|
|
3167
|
-
);
|
|
3168
|
-
},
|
|
3169
|
-
[env]
|
|
3170
|
-
);
|
|
3171
|
-
return {
|
|
3172
|
-
addEntity
|
|
3173
|
-
};
|
|
3174
|
-
};
|
|
3175
3151
|
|
|
3176
|
-
// src/services/
|
|
3177
|
-
import {
|
|
3178
|
-
var
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
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
|
+
}
|
|
3213
3245
|
};
|
|
3214
3246
|
|
|
3215
|
-
// src/services/
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
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 });
|
|
3259
|
+
}
|
|
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
|
+
}
|
|
3250
3310
|
|
|
3251
|
-
// src/services/
|
|
3252
|
-
|
|
3253
|
-
var
|
|
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
|
+
}
|
|
3325
|
+
|
|
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
|
+
console.log("modelName", modelName);
|
|
3587
|
+
console.log("snapshot", snapshot);
|
|
3588
|
+
const existingIds = getExistingIds(snapshot);
|
|
3589
|
+
console.log("existingIds", existingIds);
|
|
3590
|
+
const newId = generateNextId(existingIds, snapshot.data.length);
|
|
3591
|
+
console.log("newId", newId);
|
|
3592
|
+
snapshot.data.push({
|
|
3593
|
+
...newRecord,
|
|
3594
|
+
id: newId
|
|
3595
|
+
});
|
|
3596
|
+
const saved = await saveSnapshot({
|
|
3597
|
+
snapshot,
|
|
3598
|
+
modelName
|
|
3599
|
+
});
|
|
3600
|
+
if (!saved) {
|
|
3601
|
+
console.error("failed to add new record");
|
|
3602
|
+
return [];
|
|
3603
|
+
}
|
|
3604
|
+
console.log(`\u2705 ${snapshot.data.length} records saved`);
|
|
3605
|
+
console.log(snapshot.data);
|
|
3606
|
+
return snapshot.data;
|
|
3607
|
+
} catch (error) {
|
|
3608
|
+
console.error("failed to add new record:", error);
|
|
3609
|
+
return [];
|
|
3610
|
+
}
|
|
3611
|
+
};
|
|
3612
|
+
updateRecord = async ({
|
|
3613
|
+
id,
|
|
3614
|
+
update,
|
|
3615
|
+
modelName
|
|
3616
|
+
}) => {
|
|
3617
|
+
try {
|
|
3618
|
+
const snapshot = await loadSnapshot({
|
|
3619
|
+
modelName
|
|
3620
|
+
});
|
|
3621
|
+
const index = snapshot.data.findIndex((record) => record.id === id);
|
|
3622
|
+
if (index === -1) {
|
|
3623
|
+
console.error(`record with id ${id} not found`);
|
|
3624
|
+
return false;
|
|
3625
|
+
}
|
|
3626
|
+
snapshot.data[index] = {
|
|
3627
|
+
...snapshot.data[index],
|
|
3628
|
+
...update
|
|
3629
|
+
};
|
|
3630
|
+
return await saveSnapshot({
|
|
3631
|
+
snapshot,
|
|
3632
|
+
modelName
|
|
3633
|
+
});
|
|
3634
|
+
} catch (error) {
|
|
3635
|
+
console.error("error updating record:", error);
|
|
3636
|
+
return false;
|
|
3637
|
+
}
|
|
3638
|
+
};
|
|
3639
|
+
deleteRecord = async ({
|
|
3640
|
+
id,
|
|
3641
|
+
modelName
|
|
3642
|
+
}) => {
|
|
3643
|
+
try {
|
|
3644
|
+
const snapshot = await loadSnapshot({
|
|
3645
|
+
modelName
|
|
3646
|
+
});
|
|
3647
|
+
const before = snapshot.data.length;
|
|
3648
|
+
snapshot.data = snapshot.data.filter((record) => record.id !== id);
|
|
3649
|
+
if (snapshot.data.length === before) {
|
|
3650
|
+
console.error(`record with id ${id} not found`);
|
|
3651
|
+
return false;
|
|
3652
|
+
}
|
|
3653
|
+
return await saveSnapshot({
|
|
3654
|
+
snapshot,
|
|
3655
|
+
modelName
|
|
3656
|
+
});
|
|
3657
|
+
} catch (error) {
|
|
3658
|
+
console.error("error deleting record:", error);
|
|
3659
|
+
return false;
|
|
3660
|
+
}
|
|
3661
|
+
};
|
|
3662
|
+
};
|
|
3663
|
+
|
|
3664
|
+
// src/services/pos-service/add-entity.ts
|
|
3665
|
+
var addEntityService = (env) => {
|
|
3666
|
+
const isLocalMode = env?.isLocalMode;
|
|
3667
|
+
const repo = new ModelRepository();
|
|
3668
|
+
const addEntity = useCallback4(
|
|
3669
|
+
({
|
|
3670
|
+
model,
|
|
3671
|
+
values,
|
|
3672
|
+
xNode,
|
|
3673
|
+
service,
|
|
3674
|
+
isCreateEndpoint = false
|
|
3675
|
+
}) => {
|
|
3676
|
+
if (isLocalMode) {
|
|
3677
|
+
return repo.addRecord({
|
|
3678
|
+
newRecord: values,
|
|
3679
|
+
modelName: model
|
|
3680
|
+
});
|
|
3681
|
+
}
|
|
3682
|
+
const jsonData = {
|
|
3683
|
+
model,
|
|
3684
|
+
values
|
|
3685
|
+
};
|
|
3686
|
+
return env?.requests.post(
|
|
3687
|
+
isCreateEndpoint ? "/create" /* CREATE_PATH */ : "/call" /* CALL_PATH */,
|
|
3688
|
+
jsonData,
|
|
3689
|
+
{
|
|
3690
|
+
headers: {
|
|
3691
|
+
"Content-Type": "application/json",
|
|
3692
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
3693
|
+
}
|
|
3694
|
+
},
|
|
3695
|
+
service
|
|
3696
|
+
);
|
|
3697
|
+
},
|
|
3698
|
+
[env, isLocalMode]
|
|
3699
|
+
);
|
|
3700
|
+
return {
|
|
3701
|
+
addEntity
|
|
3702
|
+
};
|
|
3703
|
+
};
|
|
3704
|
+
|
|
3705
|
+
// src/services/pos-service/change-order-preparation-state.ts
|
|
3706
|
+
import { useCallback as useCallback5 } from "react";
|
|
3707
|
+
var changOrderPreparationStateService = (env) => {
|
|
3708
|
+
const changeOrderPreparationState = useCallback5(
|
|
3709
|
+
({
|
|
3710
|
+
orderId,
|
|
3711
|
+
stageId,
|
|
3712
|
+
preparationDisplayId,
|
|
3713
|
+
xNode,
|
|
3714
|
+
service
|
|
3715
|
+
}) => {
|
|
3716
|
+
const jsonData = {
|
|
3717
|
+
model: "pos_preparation_display.order" /* POS_PREPARATION_ORDER */,
|
|
3718
|
+
method: "change_order_stage" /* CHANGE_ORDER_STAGE */,
|
|
3719
|
+
ids: orderId,
|
|
3720
|
+
kwargs: {
|
|
3721
|
+
stage_id: stageId,
|
|
3722
|
+
preparation_display_id: preparationDisplayId
|
|
3723
|
+
}
|
|
3724
|
+
};
|
|
3725
|
+
return env?.requests.post(
|
|
3726
|
+
"/call" /* CALL_PATH */,
|
|
3727
|
+
jsonData,
|
|
3728
|
+
{
|
|
3729
|
+
headers: {
|
|
3730
|
+
"Content-Type": "application/json",
|
|
3731
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
3732
|
+
}
|
|
3733
|
+
},
|
|
3734
|
+
service
|
|
3735
|
+
);
|
|
3736
|
+
},
|
|
3737
|
+
[env]
|
|
3738
|
+
);
|
|
3739
|
+
return {
|
|
3740
|
+
changeOrderPreparationState
|
|
3741
|
+
};
|
|
3742
|
+
};
|
|
3743
|
+
|
|
3744
|
+
// src/services/pos-service/check-payment.ts
|
|
3745
|
+
import { useCallback as useCallback6 } from "react";
|
|
3746
|
+
var checkPaymentService = (env) => {
|
|
3747
|
+
const checkPayment = useCallback6(
|
|
3748
|
+
({
|
|
3749
|
+
model,
|
|
3750
|
+
ids,
|
|
3751
|
+
withContext,
|
|
3752
|
+
xNode,
|
|
3753
|
+
service
|
|
3754
|
+
}) => {
|
|
3755
|
+
const jsonData = {
|
|
3756
|
+
model,
|
|
3757
|
+
method: "check" /* CHECK */,
|
|
3758
|
+
ids,
|
|
3759
|
+
with_context: withContext
|
|
3760
|
+
};
|
|
3761
|
+
return env?.requests.post(
|
|
3762
|
+
"/call" /* CALL_PATH */,
|
|
3763
|
+
jsonData,
|
|
3764
|
+
{
|
|
3765
|
+
headers: {
|
|
3766
|
+
"Content-Type": "application/json",
|
|
3767
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
3768
|
+
}
|
|
3769
|
+
},
|
|
3770
|
+
service
|
|
3771
|
+
);
|
|
3772
|
+
},
|
|
3773
|
+
[env]
|
|
3774
|
+
);
|
|
3775
|
+
return {
|
|
3776
|
+
checkPayment
|
|
3777
|
+
};
|
|
3778
|
+
};
|
|
3779
|
+
|
|
3780
|
+
// src/services/pos-service/create-e-invoice.ts
|
|
3781
|
+
import { useCallback as useCallback7 } from "react";
|
|
3782
|
+
var createEInvoiceService = (env) => {
|
|
3254
3783
|
const createEInvoice = useCallback7(
|
|
3255
3784
|
async ({
|
|
3256
3785
|
service,
|
|
@@ -3288,6 +3817,8 @@ var createEInvoiceService = (env) => {
|
|
|
3288
3817
|
// src/services/pos-service/create-entity.ts
|
|
3289
3818
|
import { useCallback as useCallback8 } from "react";
|
|
3290
3819
|
var createEntityService = (env) => {
|
|
3820
|
+
const isLocalMode = env?.isLocalMode;
|
|
3821
|
+
const repo = new ModelRepository();
|
|
3291
3822
|
const createEntity = useCallback8(
|
|
3292
3823
|
({
|
|
3293
3824
|
model,
|
|
@@ -3295,6 +3826,12 @@ var createEntityService = (env) => {
|
|
|
3295
3826
|
xNode,
|
|
3296
3827
|
service
|
|
3297
3828
|
}) => {
|
|
3829
|
+
if (isLocalMode) {
|
|
3830
|
+
return repo.addRecord({
|
|
3831
|
+
newRecord: args,
|
|
3832
|
+
modelName: model
|
|
3833
|
+
});
|
|
3834
|
+
}
|
|
3298
3835
|
const jsonData = {
|
|
3299
3836
|
model,
|
|
3300
3837
|
method: "create" /* CREATE */,
|
|
@@ -3312,7 +3849,7 @@ var createEntityService = (env) => {
|
|
|
3312
3849
|
service
|
|
3313
3850
|
);
|
|
3314
3851
|
},
|
|
3315
|
-
[env]
|
|
3852
|
+
[env, isLocalMode]
|
|
3316
3853
|
);
|
|
3317
3854
|
return {
|
|
3318
3855
|
createEntity
|
|
@@ -3397,6 +3934,8 @@ var createSessionService = (env) => {
|
|
|
3397
3934
|
// src/services/pos-service/delete-entity.ts
|
|
3398
3935
|
import { useCallback as useCallback11 } from "react";
|
|
3399
3936
|
var deleteEntityService = (env) => {
|
|
3937
|
+
const isLocalMode = env?.isLocalMode;
|
|
3938
|
+
const repo = new ModelRepository();
|
|
3400
3939
|
const deleteEntity = useCallback11(
|
|
3401
3940
|
({
|
|
3402
3941
|
model,
|
|
@@ -3405,6 +3944,14 @@ var deleteEntityService = (env) => {
|
|
|
3405
3944
|
service,
|
|
3406
3945
|
method
|
|
3407
3946
|
}) => {
|
|
3947
|
+
if (isLocalMode) {
|
|
3948
|
+
const id = ids[0];
|
|
3949
|
+
if (!id) return;
|
|
3950
|
+
return repo.deleteRecord({
|
|
3951
|
+
modelName: model,
|
|
3952
|
+
id
|
|
3953
|
+
});
|
|
3954
|
+
}
|
|
3408
3955
|
const jsonData = {
|
|
3409
3956
|
model,
|
|
3410
3957
|
ids,
|
|
@@ -3422,7 +3969,7 @@ var deleteEntityService = (env) => {
|
|
|
3422
3969
|
service
|
|
3423
3970
|
);
|
|
3424
3971
|
},
|
|
3425
|
-
[env]
|
|
3972
|
+
[env, isLocalMode]
|
|
3426
3973
|
);
|
|
3427
3974
|
return {
|
|
3428
3975
|
deleteEntity
|
|
@@ -3755,356 +4302,111 @@ var handleCloseSessionService = (env) => {
|
|
|
3755
4302
|
const handleCloseSession = useCallback20(
|
|
3756
4303
|
({
|
|
3757
4304
|
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
|
-
function createWorkerBlob() {
|
|
3961
|
-
const workerCode = `
|
|
3962
|
-
self.addEventListener("message", async (ev) => {
|
|
3963
|
-
const { id, cmd, payload } = ev.data;
|
|
3964
|
-
try {
|
|
3965
|
-
if (cmd === "parse") {
|
|
3966
|
-
const parsed = JSON.parse(payload);
|
|
3967
|
-
self.postMessage({ id, ok: true, result: parsed });
|
|
3968
|
-
} else if (cmd === "stringify") {
|
|
3969
|
-
const str = JSON.stringify(payload);
|
|
3970
|
-
self.postMessage({ id, ok: true, result: str });
|
|
3971
|
-
}
|
|
3972
|
-
} catch (err) {
|
|
3973
|
-
self.postMessage({ id, ok: false, error: err?.message || String(err) });
|
|
3974
|
-
}
|
|
3975
|
-
});
|
|
3976
|
-
`;
|
|
3977
|
-
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
3978
|
-
return URL.createObjectURL(blob);
|
|
3979
|
-
}
|
|
3980
|
-
function spawnParseWorker(raw) {
|
|
3981
|
-
return new Promise((resolve, reject) => {
|
|
3982
|
-
const workerUrl = createWorkerBlob();
|
|
3983
|
-
const worker = new Worker(workerUrl);
|
|
3984
|
-
const id = Math.random().toString(36).slice(2);
|
|
3985
|
-
worker.onmessage = (ev) => {
|
|
3986
|
-
const { ok, result, error } = ev.data;
|
|
3987
|
-
if (ok) {
|
|
3988
|
-
resolve(result);
|
|
3989
|
-
} else {
|
|
3990
|
-
reject(new Error(error));
|
|
3991
|
-
}
|
|
3992
|
-
URL.revokeObjectURL(workerUrl);
|
|
3993
|
-
worker.terminate();
|
|
3994
|
-
};
|
|
3995
|
-
worker.onerror = (err) => {
|
|
3996
|
-
reject(err);
|
|
3997
|
-
URL.revokeObjectURL(workerUrl);
|
|
3998
|
-
worker.terminate();
|
|
3999
|
-
};
|
|
4000
|
-
worker.postMessage({ id, cmd: "parse", payload: raw });
|
|
4001
|
-
});
|
|
4002
|
-
}
|
|
4003
|
-
function spawnStringifyWorker(obj) {
|
|
4004
|
-
return new Promise((resolve, reject) => {
|
|
4005
|
-
const workerUrl = createWorkerBlob();
|
|
4006
|
-
const worker = new Worker(workerUrl);
|
|
4007
|
-
worker.onmessage = (ev) => {
|
|
4008
|
-
const { ok, result, error } = ev.data;
|
|
4009
|
-
if (ok) resolve(result);
|
|
4010
|
-
else reject(new Error(error));
|
|
4011
|
-
URL.revokeObjectURL(workerUrl);
|
|
4012
|
-
worker.terminate();
|
|
4013
|
-
};
|
|
4014
|
-
worker.onerror = (err) => {
|
|
4015
|
-
reject(err);
|
|
4016
|
-
URL.revokeObjectURL(workerUrl);
|
|
4017
|
-
worker.terminate();
|
|
4018
|
-
};
|
|
4019
|
-
worker.postMessage({ cmd: "stringify", payload: obj });
|
|
4020
|
-
});
|
|
4021
|
-
}
|
|
4305
|
+
ids,
|
|
4306
|
+
xNode,
|
|
4307
|
+
service,
|
|
4308
|
+
method
|
|
4309
|
+
}) => {
|
|
4310
|
+
const jsonData = {
|
|
4311
|
+
model,
|
|
4312
|
+
ids,
|
|
4313
|
+
method
|
|
4314
|
+
};
|
|
4315
|
+
return env?.requests.post(
|
|
4316
|
+
"/call" /* CALL_PATH */,
|
|
4317
|
+
jsonData,
|
|
4318
|
+
{
|
|
4319
|
+
headers: {
|
|
4320
|
+
"Content-Type": "application/json",
|
|
4321
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
4322
|
+
}
|
|
4323
|
+
},
|
|
4324
|
+
service
|
|
4325
|
+
);
|
|
4326
|
+
},
|
|
4327
|
+
[env]
|
|
4328
|
+
);
|
|
4329
|
+
return {
|
|
4330
|
+
handleCloseSession
|
|
4331
|
+
};
|
|
4332
|
+
};
|
|
4022
4333
|
|
|
4023
|
-
// src/services/
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4334
|
+
// src/services/pos-service/handle-closing-detail-session.ts
|
|
4335
|
+
import { useCallback as useCallback21 } from "react";
|
|
4336
|
+
var handleClosingDetailSessionService = (env) => {
|
|
4337
|
+
const handleClosingDetailSession = useCallback21(
|
|
4338
|
+
({
|
|
4339
|
+
model,
|
|
4340
|
+
ids,
|
|
4341
|
+
method,
|
|
4342
|
+
xNode,
|
|
4343
|
+
service,
|
|
4344
|
+
kwargs
|
|
4345
|
+
}) => {
|
|
4346
|
+
const jsonData = {
|
|
4347
|
+
model,
|
|
4348
|
+
ids,
|
|
4349
|
+
method,
|
|
4350
|
+
kwargs
|
|
4351
|
+
};
|
|
4352
|
+
return env?.requests.post(
|
|
4353
|
+
"/call" /* CALL_PATH */,
|
|
4354
|
+
jsonData,
|
|
4355
|
+
{
|
|
4356
|
+
headers: {
|
|
4357
|
+
"Content-Type": "application/json",
|
|
4358
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
4359
|
+
}
|
|
4360
|
+
},
|
|
4361
|
+
service
|
|
4362
|
+
);
|
|
4363
|
+
},
|
|
4364
|
+
[env]
|
|
4365
|
+
);
|
|
4366
|
+
return {
|
|
4367
|
+
handleClosingDetailSession
|
|
4368
|
+
};
|
|
4044
4369
|
};
|
|
4045
|
-
var memoryCache = new MemoryCache();
|
|
4046
4370
|
|
|
4047
|
-
// src/services/
|
|
4048
|
-
|
|
4049
|
-
var
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
}
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
const fileName = file.name;
|
|
4065
|
-
const modelName = fileName.replace(/\.json$/, "");
|
|
4066
|
-
const dataPath = `${MODELS_DIR}/${fileName}`;
|
|
4067
|
-
console.log("\u{1F4C2} Reading data from:", dataPath);
|
|
4068
|
-
const rawData = await fileService.read(dataPath);
|
|
4069
|
-
console.log("\u2705 Data read, length:", rawData?.length);
|
|
4070
|
-
if (!rawData) continue;
|
|
4071
|
-
console.log("\u{1F504} Parsing data...");
|
|
4072
|
-
const parsedData = await spawnParseWorker(rawData);
|
|
4073
|
-
console.log("\u2705 Data parsed");
|
|
4074
|
-
const data = Array.isArray(parsedData) ? parsedData : [];
|
|
4075
|
-
if (!includeMeta) {
|
|
4076
|
-
result[modelName] = { data };
|
|
4077
|
-
continue;
|
|
4078
|
-
}
|
|
4079
|
-
const metaPath = `${MODELS_META_DIR}/${encodeURIComponent(
|
|
4080
|
-
modelName
|
|
4081
|
-
)}.meta.json`;
|
|
4082
|
-
console.log("\u{1F4C2} Reading meta from:", metaPath);
|
|
4083
|
-
const rawMeta = await fileService.read(metaPath);
|
|
4084
|
-
let fields = [];
|
|
4085
|
-
let relations = {};
|
|
4086
|
-
if (rawMeta) {
|
|
4087
|
-
console.log("\u{1F504} Parsing meta...");
|
|
4088
|
-
const parsedMeta = await spawnParseWorker(rawMeta);
|
|
4089
|
-
fields = parsedMeta?.fields ?? [];
|
|
4090
|
-
relations = parsedMeta?.relations ?? {};
|
|
4091
|
-
console.log("\u2705 Meta parsed");
|
|
4092
|
-
}
|
|
4093
|
-
result[modelName] = {
|
|
4094
|
-
data,
|
|
4095
|
-
fields,
|
|
4096
|
-
relations
|
|
4371
|
+
// src/services/pos-service/handle-closing-session.ts
|
|
4372
|
+
import { useCallback as useCallback22 } from "react";
|
|
4373
|
+
var handleClosingSessionService = (env) => {
|
|
4374
|
+
const handleClosingSession = useCallback22(
|
|
4375
|
+
({
|
|
4376
|
+
model,
|
|
4377
|
+
method,
|
|
4378
|
+
ids,
|
|
4379
|
+
kwargs,
|
|
4380
|
+
xNode,
|
|
4381
|
+
service
|
|
4382
|
+
}) => {
|
|
4383
|
+
const jsonData = {
|
|
4384
|
+
model,
|
|
4385
|
+
method,
|
|
4386
|
+
ids,
|
|
4387
|
+
kwargs
|
|
4097
4388
|
};
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
}
|
|
4389
|
+
return env?.requests.post(
|
|
4390
|
+
"/call" /* CALL_PATH */,
|
|
4391
|
+
jsonData,
|
|
4392
|
+
{
|
|
4393
|
+
headers: {
|
|
4394
|
+
"Content-Type": "application/json",
|
|
4395
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
4396
|
+
}
|
|
4397
|
+
},
|
|
4398
|
+
service
|
|
4399
|
+
);
|
|
4400
|
+
},
|
|
4401
|
+
[env]
|
|
4402
|
+
);
|
|
4403
|
+
return {
|
|
4404
|
+
handleClosingSession
|
|
4405
|
+
};
|
|
4406
|
+
};
|
|
4106
4407
|
|
|
4107
4408
|
// src/services/pos-service/load-data-pos-session.ts
|
|
4409
|
+
import { useCallback as useCallback23 } from "react";
|
|
4108
4410
|
var loadDataPosSessionService = (env) => {
|
|
4109
4411
|
const isLocalMode = env?.isLocalMode;
|
|
4110
4412
|
const loadDataPosSession = useCallback23(
|
|
@@ -4117,10 +4419,8 @@ var loadDataPosSessionService = (env) => {
|
|
|
4117
4419
|
modelsToLoad = [],
|
|
4118
4420
|
searchParams
|
|
4119
4421
|
}) => {
|
|
4120
|
-
console.log("isLocalMode", isLocalMode);
|
|
4121
4422
|
if (isLocalMode) {
|
|
4122
4423
|
const data = await loadData();
|
|
4123
|
-
console.log("\u2705 loadData resolved:", data);
|
|
4124
4424
|
return data;
|
|
4125
4425
|
}
|
|
4126
4426
|
const jsonData = {
|
|
@@ -4374,6 +4674,8 @@ var updateClosedSessionService = (env) => {
|
|
|
4374
4674
|
// src/services/pos-service/update-entity.ts
|
|
4375
4675
|
import { useCallback as useCallback30 } from "react";
|
|
4376
4676
|
var updateEntityService = (env) => {
|
|
4677
|
+
const isLocalMode = env?.isLocalMode;
|
|
4678
|
+
const repo = new ModelRepository();
|
|
4377
4679
|
const updateEntity = useCallback30(
|
|
4378
4680
|
({
|
|
4379
4681
|
model,
|
|
@@ -4383,6 +4685,15 @@ var updateEntityService = (env) => {
|
|
|
4383
4685
|
xNode,
|
|
4384
4686
|
service
|
|
4385
4687
|
}) => {
|
|
4688
|
+
if (isLocalMode) {
|
|
4689
|
+
const id = extractIdFromDomain(domain);
|
|
4690
|
+
if (!id) return;
|
|
4691
|
+
return repo.updateRecord({
|
|
4692
|
+
update: values,
|
|
4693
|
+
modelName: model,
|
|
4694
|
+
id
|
|
4695
|
+
});
|
|
4696
|
+
}
|
|
4386
4697
|
const jsonData = {
|
|
4387
4698
|
model,
|
|
4388
4699
|
domain,
|
|
@@ -4400,7 +4711,7 @@ var updateEntityService = (env) => {
|
|
|
4400
4711
|
service
|
|
4401
4712
|
);
|
|
4402
4713
|
},
|
|
4403
|
-
[env]
|
|
4714
|
+
[env, isLocalMode]
|
|
4404
4715
|
);
|
|
4405
4716
|
return {
|
|
4406
4717
|
updateEntity
|
|
@@ -6732,101 +7043,6 @@ function useDashboardService() {
|
|
|
6732
7043
|
return { readGroup, getDataChart };
|
|
6733
7044
|
}
|
|
6734
7045
|
|
|
6735
|
-
// src/services/filesystem-service/manifest.ts
|
|
6736
|
-
var MANIFEST_PATH = "pos/manifest.json";
|
|
6737
|
-
var MANIFEST_BAK_PATH = "pos/manifest.bak.json";
|
|
6738
|
-
async function writeManifest(manifest) {
|
|
6739
|
-
const oldRaw = await fileService.read(MANIFEST_PATH);
|
|
6740
|
-
if (oldRaw !== null) {
|
|
6741
|
-
await fileService.writeAtomic(MANIFEST_BAK_PATH, oldRaw);
|
|
6742
|
-
}
|
|
6743
|
-
await fileService.writeAtomic(MANIFEST_PATH, JSON.stringify(manifest));
|
|
6744
|
-
try {
|
|
6745
|
-
await fileService.delete(MANIFEST_BAK_PATH);
|
|
6746
|
-
} catch {
|
|
6747
|
-
}
|
|
6748
|
-
}
|
|
6749
|
-
|
|
6750
|
-
// src/services/filesystem-service/import-snapshot.ts
|
|
6751
|
-
var DATA_DIR = "pos";
|
|
6752
|
-
var MODELS_DIR2 = `${DATA_DIR}/models`;
|
|
6753
|
-
var MODELS_META_DIR2 = `${DATA_DIR}/models_meta`;
|
|
6754
|
-
var importSnapshot = async ({ data, onProgress }) => {
|
|
6755
|
-
onProgress?.(1, "Parsing snapshot");
|
|
6756
|
-
const parsed = await spawnParseWorker(data);
|
|
6757
|
-
const modelNames = Object.keys(parsed);
|
|
6758
|
-
const total = modelNames.length;
|
|
6759
|
-
const manifest = { version: (/* @__PURE__ */ new Date()).toISOString(), models: {} };
|
|
6760
|
-
const TMP_PREFIX = `pos/data/tmp_import_${Date.now()}`;
|
|
6761
|
-
await fileService.writeAtomic(`${TMP_PREFIX}/.marker`, "1");
|
|
6762
|
-
let i = 0;
|
|
6763
|
-
for (const model of modelNames) {
|
|
6764
|
-
i++;
|
|
6765
|
-
onProgress?.(
|
|
6766
|
-
Math.round(i / total * 100),
|
|
6767
|
-
`Processing ${model} (${i}/${total})`
|
|
6768
|
-
);
|
|
6769
|
-
const block = parsed[model];
|
|
6770
|
-
const dataPart = block?.data ?? block ?? [];
|
|
6771
|
-
const fields = block?.fields ?? [];
|
|
6772
|
-
const relations = block?.relations ?? {};
|
|
6773
|
-
const serialized = await spawnStringifyWorker(dataPart);
|
|
6774
|
-
const tmpModelPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.json`;
|
|
6775
|
-
await fileService.writeAtomic(tmpModelPath, serialized);
|
|
6776
|
-
const meta = {
|
|
6777
|
-
fields,
|
|
6778
|
-
relations,
|
|
6779
|
-
count: Array.isArray(dataPart) ? dataPart.length : 0,
|
|
6780
|
-
writtenAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
6781
|
-
};
|
|
6782
|
-
const tmpMetaPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`;
|
|
6783
|
-
await fileService.writeAtomic(tmpMetaPath, JSON.stringify(meta));
|
|
6784
|
-
manifest.models[model] = {
|
|
6785
|
-
file: `${MODELS_DIR2}/${encodeURIComponent(model)}.json`,
|
|
6786
|
-
metaFile: `${MODELS_META_DIR2}/${encodeURIComponent(model)}.meta.json`,
|
|
6787
|
-
count: meta.count,
|
|
6788
|
-
updatedAt: meta.writtenAt
|
|
6789
|
-
};
|
|
6790
|
-
}
|
|
6791
|
-
onProgress?.(95, "Committing import (moving files)");
|
|
6792
|
-
for (const model of modelNames) {
|
|
6793
|
-
const tmpModelPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.json`;
|
|
6794
|
-
const finalModelPath = `${MODELS_DIR2}/${encodeURIComponent(model)}.json`;
|
|
6795
|
-
const tmpMetaPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`;
|
|
6796
|
-
const finalMetaPath = `${MODELS_META_DIR2}/${encodeURIComponent(
|
|
6797
|
-
model
|
|
6798
|
-
)}.meta.json`;
|
|
6799
|
-
const tmpRaw = await fileService.read(tmpModelPath);
|
|
6800
|
-
if (tmpRaw !== null) await fileService.writeAtomic(finalModelPath, tmpRaw);
|
|
6801
|
-
const tmpMetaRaw = await fileService.read(tmpMetaPath);
|
|
6802
|
-
if (tmpMetaRaw !== null)
|
|
6803
|
-
await fileService.writeAtomic(finalMetaPath, tmpMetaRaw);
|
|
6804
|
-
onProgress?.(
|
|
6805
|
-
95 + Math.round(
|
|
6806
|
-
(Object.keys(manifest.models).indexOf(model) + 1) / modelNames.length * 5
|
|
6807
|
-
),
|
|
6808
|
-
`Committed ${model}`
|
|
6809
|
-
);
|
|
6810
|
-
}
|
|
6811
|
-
await writeManifest(manifest);
|
|
6812
|
-
try {
|
|
6813
|
-
for (const model of modelNames) {
|
|
6814
|
-
await fileService.delete(
|
|
6815
|
-
`${TMP_PREFIX}/${encodeURIComponent(model)}.json`
|
|
6816
|
-
);
|
|
6817
|
-
await fileService.delete(
|
|
6818
|
-
`${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`
|
|
6819
|
-
);
|
|
6820
|
-
}
|
|
6821
|
-
await fileService.delete(`${TMP_PREFIX}/.marker`);
|
|
6822
|
-
} catch (e) {
|
|
6823
|
-
console.log("Failed to cleanup tmp import files:", e);
|
|
6824
|
-
}
|
|
6825
|
-
onProgress?.(100, "Import complete");
|
|
6826
|
-
return manifest;
|
|
6827
|
-
};
|
|
6828
|
-
var import_snapshot_default = importSnapshot;
|
|
6829
|
-
|
|
6830
7046
|
// src/services/filesystem-service/init-snapshot.ts
|
|
6831
7047
|
var isSnapshotReady = async () => {
|
|
6832
7048
|
try {
|