@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/hooks.mjs
CHANGED
|
@@ -1616,9 +1616,9 @@ function applyBinaryOp(ast, context) {
|
|
|
1616
1616
|
var DICT = {
|
|
1617
1617
|
get(...args) {
|
|
1618
1618
|
const { key, defValue } = parseArgs(args, ["key", "defValue"]);
|
|
1619
|
-
const
|
|
1620
|
-
if (key in
|
|
1621
|
-
return
|
|
1619
|
+
const self = this;
|
|
1620
|
+
if (key in self) {
|
|
1621
|
+
return self[key];
|
|
1622
1622
|
} else if (defValue !== void 0) {
|
|
1623
1623
|
return defValue;
|
|
1624
1624
|
}
|
|
@@ -2203,6 +2203,13 @@ function cleanObject(obj) {
|
|
|
2203
2203
|
}
|
|
2204
2204
|
return result;
|
|
2205
2205
|
}
|
|
2206
|
+
var extractIdFromDomain = (domain) => {
|
|
2207
|
+
if (!domain || !Array.isArray(domain)) return null;
|
|
2208
|
+
const idCond = domain.find(
|
|
2209
|
+
([field, operator]) => field === "id" && operator === "="
|
|
2210
|
+
);
|
|
2211
|
+
return idCond ? Number(idCond[2]) : null;
|
|
2212
|
+
};
|
|
2206
2213
|
|
|
2207
2214
|
// src/provider/react-query-provider.tsx
|
|
2208
2215
|
import { useState as useState2 } from "react";
|
|
@@ -5078,130 +5085,647 @@ var getASessionService = (env) => {
|
|
|
5078
5085
|
|
|
5079
5086
|
// src/services/pos-service/add-entity.ts
|
|
5080
5087
|
import { useCallback as useCallback13 } from "react";
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
return
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
|
|
5088
|
+
|
|
5089
|
+
// src/services/filesystem-service/file-service.ts
|
|
5090
|
+
import { Directory, Encoding, Filesystem } from "@capacitor/filesystem";
|
|
5091
|
+
var fileService = {
|
|
5092
|
+
read: async (path) => {
|
|
5093
|
+
try {
|
|
5094
|
+
const res = await Filesystem.readFile({
|
|
5095
|
+
path,
|
|
5096
|
+
directory: Directory.Data,
|
|
5097
|
+
encoding: Encoding.UTF8
|
|
5098
|
+
});
|
|
5099
|
+
if (typeof res.data === "string") return res.data;
|
|
5100
|
+
if (res.data instanceof Blob) return await res.data.text();
|
|
5101
|
+
return null;
|
|
5102
|
+
} catch {
|
|
5103
|
+
return null;
|
|
5104
|
+
}
|
|
5105
|
+
},
|
|
5106
|
+
write: async (path, data) => {
|
|
5107
|
+
await Filesystem.writeFile({
|
|
5108
|
+
path,
|
|
5109
|
+
data,
|
|
5110
|
+
directory: Directory.Data,
|
|
5111
|
+
encoding: Encoding.UTF8,
|
|
5112
|
+
recursive: true
|
|
5113
|
+
});
|
|
5114
|
+
},
|
|
5115
|
+
writeAtomic: async (path, data) => {
|
|
5116
|
+
const tempPath = path + ".tmp";
|
|
5117
|
+
await Filesystem.writeFile({
|
|
5118
|
+
path: tempPath,
|
|
5119
|
+
data,
|
|
5120
|
+
directory: Directory.Data,
|
|
5121
|
+
encoding: Encoding.UTF8,
|
|
5122
|
+
recursive: true
|
|
5123
|
+
});
|
|
5124
|
+
try {
|
|
5125
|
+
await Filesystem.deleteFile({
|
|
5126
|
+
path,
|
|
5127
|
+
directory: Directory.Data
|
|
5128
|
+
});
|
|
5129
|
+
} catch {
|
|
5130
|
+
}
|
|
5131
|
+
await Filesystem.rename({
|
|
5132
|
+
from: tempPath,
|
|
5133
|
+
to: path,
|
|
5134
|
+
directory: Directory.Data
|
|
5135
|
+
});
|
|
5136
|
+
},
|
|
5137
|
+
delete: async (path) => {
|
|
5138
|
+
try {
|
|
5139
|
+
await Filesystem.deleteFile({
|
|
5140
|
+
path,
|
|
5141
|
+
directory: Directory.Data
|
|
5142
|
+
});
|
|
5143
|
+
} catch {
|
|
5144
|
+
}
|
|
5145
|
+
},
|
|
5146
|
+
exists: async (path) => {
|
|
5147
|
+
try {
|
|
5148
|
+
await Filesystem.stat({
|
|
5149
|
+
path,
|
|
5150
|
+
directory: Directory.Data
|
|
5151
|
+
});
|
|
5152
|
+
return true;
|
|
5153
|
+
} catch {
|
|
5154
|
+
return false;
|
|
5155
|
+
}
|
|
5156
|
+
},
|
|
5157
|
+
mkdir: async (path) => {
|
|
5158
|
+
try {
|
|
5159
|
+
await Filesystem.mkdir({
|
|
5160
|
+
path,
|
|
5161
|
+
directory: Directory.Data,
|
|
5162
|
+
recursive: true
|
|
5163
|
+
});
|
|
5164
|
+
} catch (e) {
|
|
5165
|
+
if (!String(e?.message).includes("Exists")) {
|
|
5166
|
+
throw e;
|
|
5167
|
+
}
|
|
5168
|
+
}
|
|
5169
|
+
},
|
|
5170
|
+
list: async (path) => {
|
|
5171
|
+
return Filesystem.readdir({
|
|
5172
|
+
path,
|
|
5173
|
+
directory: Directory.Data
|
|
5174
|
+
});
|
|
5175
|
+
},
|
|
5176
|
+
getUri: async (path) => {
|
|
5177
|
+
return Filesystem.getUri({
|
|
5178
|
+
path,
|
|
5179
|
+
directory: Directory.Data
|
|
5180
|
+
});
|
|
5181
|
+
}
|
|
5111
5182
|
};
|
|
5112
5183
|
|
|
5113
|
-
// src/services/
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
model: "pos_preparation_display.order" /* POS_PREPARATION_ORDER */,
|
|
5126
|
-
method: "change_order_stage" /* CHANGE_ORDER_STAGE */,
|
|
5127
|
-
ids: orderId,
|
|
5128
|
-
kwargs: {
|
|
5129
|
-
stage_id: stageId,
|
|
5130
|
-
preparation_display_id: preparationDisplayId
|
|
5184
|
+
// src/services/filesystem-service/json-worker.ts
|
|
5185
|
+
function createWorkerBlob() {
|
|
5186
|
+
const workerCode = `
|
|
5187
|
+
self.addEventListener("message", async (ev) => {
|
|
5188
|
+
const { id, cmd, payload } = ev.data;
|
|
5189
|
+
try {
|
|
5190
|
+
if (cmd === "parse") {
|
|
5191
|
+
const parsed = JSON.parse(payload);
|
|
5192
|
+
self.postMessage({ id, ok: true, result: parsed });
|
|
5193
|
+
} else if (cmd === "stringify") {
|
|
5194
|
+
const str = JSON.stringify(payload);
|
|
5195
|
+
self.postMessage({ id, ok: true, result: str });
|
|
5131
5196
|
}
|
|
5132
|
-
}
|
|
5133
|
-
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5197
|
+
} catch (err) {
|
|
5198
|
+
self.postMessage({ id, ok: false, error: err?.message || String(err) });
|
|
5199
|
+
}
|
|
5200
|
+
});
|
|
5201
|
+
`;
|
|
5202
|
+
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
5203
|
+
return URL.createObjectURL(blob);
|
|
5204
|
+
}
|
|
5205
|
+
function spawnParseWorker(raw) {
|
|
5206
|
+
return new Promise((resolve, reject) => {
|
|
5207
|
+
const workerUrl = createWorkerBlob();
|
|
5208
|
+
const worker = new Worker(workerUrl);
|
|
5209
|
+
const id = Math.random().toString(36).slice(2);
|
|
5210
|
+
worker.onmessage = (ev) => {
|
|
5211
|
+
const { ok, result, error } = ev.data;
|
|
5212
|
+
if (ok) {
|
|
5213
|
+
resolve(result);
|
|
5214
|
+
} else {
|
|
5215
|
+
reject(new Error(error));
|
|
5216
|
+
}
|
|
5217
|
+
URL.revokeObjectURL(workerUrl);
|
|
5218
|
+
worker.terminate();
|
|
5219
|
+
};
|
|
5220
|
+
worker.onerror = (err) => {
|
|
5221
|
+
reject(err);
|
|
5222
|
+
URL.revokeObjectURL(workerUrl);
|
|
5223
|
+
worker.terminate();
|
|
5224
|
+
};
|
|
5225
|
+
worker.postMessage({ id, cmd: "parse", payload: raw });
|
|
5226
|
+
});
|
|
5227
|
+
}
|
|
5228
|
+
function spawnStringifyWorker(obj) {
|
|
5229
|
+
return new Promise((resolve, reject) => {
|
|
5230
|
+
const workerUrl = createWorkerBlob();
|
|
5231
|
+
const worker = new Worker(workerUrl);
|
|
5232
|
+
worker.onmessage = (ev) => {
|
|
5233
|
+
const { ok, result, error } = ev.data;
|
|
5234
|
+
if (ok) resolve(result);
|
|
5235
|
+
else reject(new Error(error));
|
|
5236
|
+
URL.revokeObjectURL(workerUrl);
|
|
5237
|
+
worker.terminate();
|
|
5238
|
+
};
|
|
5239
|
+
worker.onerror = (err) => {
|
|
5240
|
+
reject(err);
|
|
5241
|
+
URL.revokeObjectURL(workerUrl);
|
|
5242
|
+
worker.terminate();
|
|
5243
|
+
};
|
|
5244
|
+
worker.postMessage({ cmd: "stringify", payload: obj });
|
|
5245
|
+
});
|
|
5246
|
+
}
|
|
5151
5247
|
|
|
5152
|
-
// src/services/
|
|
5153
|
-
|
|
5154
|
-
var
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
|
|
5166
|
-
ids,
|
|
5167
|
-
with_context: withContext
|
|
5168
|
-
};
|
|
5169
|
-
return env?.requests.post(
|
|
5170
|
-
"/call" /* CALL_PATH */,
|
|
5171
|
-
jsonData,
|
|
5172
|
-
{
|
|
5173
|
-
headers: {
|
|
5174
|
-
"Content-Type": "application/json",
|
|
5175
|
-
...xNode ? { "X-Node": xNode } : {}
|
|
5176
|
-
}
|
|
5177
|
-
},
|
|
5178
|
-
service
|
|
5179
|
-
);
|
|
5180
|
-
},
|
|
5181
|
-
[env]
|
|
5182
|
-
);
|
|
5183
|
-
return {
|
|
5184
|
-
checkPayment
|
|
5185
|
-
};
|
|
5186
|
-
};
|
|
5248
|
+
// src/services/filesystem-service/manifest.ts
|
|
5249
|
+
var MANIFEST_PATH = "pos/manifest.json";
|
|
5250
|
+
var MANIFEST_BAK_PATH = "pos/manifest.bak.json";
|
|
5251
|
+
async function writeManifest(manifest) {
|
|
5252
|
+
const oldRaw = await fileService.read(MANIFEST_PATH);
|
|
5253
|
+
if (oldRaw !== null) {
|
|
5254
|
+
await fileService.writeAtomic(MANIFEST_BAK_PATH, oldRaw);
|
|
5255
|
+
}
|
|
5256
|
+
await fileService.writeAtomic(MANIFEST_PATH, JSON.stringify(manifest));
|
|
5257
|
+
try {
|
|
5258
|
+
await fileService.delete(MANIFEST_BAK_PATH);
|
|
5259
|
+
} catch {
|
|
5260
|
+
}
|
|
5261
|
+
}
|
|
5187
5262
|
|
|
5188
|
-
// src/services/
|
|
5189
|
-
|
|
5190
|
-
var
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
|
|
5198
|
-
|
|
5199
|
-
|
|
5200
|
-
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5263
|
+
// src/services/filesystem-service/import-snapshot.ts
|
|
5264
|
+
var DATA_DIR = "pos";
|
|
5265
|
+
var MODELS_DIR = `${DATA_DIR}/models`;
|
|
5266
|
+
var MODELS_META_DIR = `${DATA_DIR}/models_meta`;
|
|
5267
|
+
var importSnapshot = async ({ data, onProgress }) => {
|
|
5268
|
+
onProgress?.(1, "Parsing snapshot");
|
|
5269
|
+
const parsed = await spawnParseWorker(data);
|
|
5270
|
+
const modelNames = Object.keys(parsed);
|
|
5271
|
+
const total = modelNames.length;
|
|
5272
|
+
const manifest = { version: (/* @__PURE__ */ new Date()).toISOString(), models: {} };
|
|
5273
|
+
const TMP_PREFIX = `pos/data/tmp_import_${Date.now()}`;
|
|
5274
|
+
await fileService.writeAtomic(`${TMP_PREFIX}/.marker`, "1");
|
|
5275
|
+
let i = 0;
|
|
5276
|
+
for (const model of modelNames) {
|
|
5277
|
+
i++;
|
|
5278
|
+
onProgress?.(
|
|
5279
|
+
Math.round(i / total * 100),
|
|
5280
|
+
`Processing ${model} (${i}/${total})`
|
|
5281
|
+
);
|
|
5282
|
+
const block = parsed[model];
|
|
5283
|
+
const dataPart = block?.data ?? block ?? [];
|
|
5284
|
+
const fields = block?.fields ?? [];
|
|
5285
|
+
const relations = block?.relations ?? {};
|
|
5286
|
+
const serialized = await spawnStringifyWorker(dataPart);
|
|
5287
|
+
const tmpModelPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.json`;
|
|
5288
|
+
await fileService.writeAtomic(tmpModelPath, serialized);
|
|
5289
|
+
const meta = {
|
|
5290
|
+
fields,
|
|
5291
|
+
relations,
|
|
5292
|
+
count: Array.isArray(dataPart) ? dataPart.length : 0,
|
|
5293
|
+
writtenAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
5294
|
+
};
|
|
5295
|
+
const tmpMetaPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`;
|
|
5296
|
+
await fileService.writeAtomic(tmpMetaPath, JSON.stringify(meta));
|
|
5297
|
+
manifest.models[model] = {
|
|
5298
|
+
file: `${MODELS_DIR}/${encodeURIComponent(model)}.json`,
|
|
5299
|
+
metaFile: `${MODELS_META_DIR}/${encodeURIComponent(model)}.meta.json`,
|
|
5300
|
+
count: meta.count,
|
|
5301
|
+
updatedAt: meta.writtenAt
|
|
5302
|
+
};
|
|
5303
|
+
}
|
|
5304
|
+
onProgress?.(95, "Committing import (moving files)");
|
|
5305
|
+
for (const model of modelNames) {
|
|
5306
|
+
const tmpModelPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.json`;
|
|
5307
|
+
const finalModelPath = `${MODELS_DIR}/${encodeURIComponent(model)}.json`;
|
|
5308
|
+
const tmpMetaPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`;
|
|
5309
|
+
const finalMetaPath = `${MODELS_META_DIR}/${encodeURIComponent(
|
|
5310
|
+
model
|
|
5311
|
+
)}.meta.json`;
|
|
5312
|
+
const tmpRaw = await fileService.read(tmpModelPath);
|
|
5313
|
+
if (tmpRaw !== null) await fileService.writeAtomic(finalModelPath, tmpRaw);
|
|
5314
|
+
const tmpMetaRaw = await fileService.read(tmpMetaPath);
|
|
5315
|
+
if (tmpMetaRaw !== null)
|
|
5316
|
+
await fileService.writeAtomic(finalMetaPath, tmpMetaRaw);
|
|
5317
|
+
onProgress?.(
|
|
5318
|
+
95 + Math.round(
|
|
5319
|
+
(Object.keys(manifest.models).indexOf(model) + 1) / modelNames.length * 5
|
|
5320
|
+
),
|
|
5321
|
+
`Committed ${model}`
|
|
5322
|
+
);
|
|
5323
|
+
}
|
|
5324
|
+
await writeManifest(manifest);
|
|
5325
|
+
try {
|
|
5326
|
+
for (const model of modelNames) {
|
|
5327
|
+
await fileService.delete(
|
|
5328
|
+
`${TMP_PREFIX}/${encodeURIComponent(model)}.json`
|
|
5329
|
+
);
|
|
5330
|
+
await fileService.delete(
|
|
5331
|
+
`${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`
|
|
5332
|
+
);
|
|
5333
|
+
}
|
|
5334
|
+
await fileService.delete(`${TMP_PREFIX}/.marker`);
|
|
5335
|
+
} catch (e) {
|
|
5336
|
+
console.log("Failed to cleanup tmp import files:", e);
|
|
5337
|
+
}
|
|
5338
|
+
onProgress?.(100, "Import complete");
|
|
5339
|
+
return manifest;
|
|
5340
|
+
};
|
|
5341
|
+
var import_snapshot_default = importSnapshot;
|
|
5342
|
+
|
|
5343
|
+
// src/services/filesystem-service/memory-cache.ts
|
|
5344
|
+
var MemoryCache = class {
|
|
5345
|
+
map = /* @__PURE__ */ new Map();
|
|
5346
|
+
get(k) {
|
|
5347
|
+
const e = this.map.get(k);
|
|
5348
|
+
if (!e) return null;
|
|
5349
|
+
if (e.ttl && Date.now() - e.t > e.ttl) {
|
|
5350
|
+
this.map.delete(k);
|
|
5351
|
+
return null;
|
|
5352
|
+
}
|
|
5353
|
+
return e.value;
|
|
5354
|
+
}
|
|
5355
|
+
set(k, v, ttl = 5 * 60 * 1e3) {
|
|
5356
|
+
this.map.set(k, { value: v, t: Date.now(), ttl });
|
|
5357
|
+
}
|
|
5358
|
+
del(k) {
|
|
5359
|
+
this.map.delete(k);
|
|
5360
|
+
}
|
|
5361
|
+
clear() {
|
|
5362
|
+
this.map.clear();
|
|
5363
|
+
}
|
|
5364
|
+
};
|
|
5365
|
+
var memoryCache = new MemoryCache();
|
|
5366
|
+
|
|
5367
|
+
// src/services/filesystem-service/model-loader.ts
|
|
5368
|
+
var MODELS_DIR2 = "pos/models";
|
|
5369
|
+
var MODELS_META_DIR2 = "pos/models_meta";
|
|
5370
|
+
async function loadModelData(modelName, includeMeta = true) {
|
|
5371
|
+
const key = `model:${modelName}:meta:${includeMeta}`;
|
|
5372
|
+
const cached = memoryCache.get(key);
|
|
5373
|
+
if (cached) return cached;
|
|
5374
|
+
const dataPath = `${MODELS_DIR2}/${encodeURIComponent(modelName)}.json`;
|
|
5375
|
+
const metaPath = `${MODELS_META_DIR2}/${encodeURIComponent(
|
|
5376
|
+
modelName
|
|
5377
|
+
)}.meta.json`;
|
|
5378
|
+
const rawData = await fileService.read(dataPath);
|
|
5379
|
+
if (!rawData) return null;
|
|
5380
|
+
const parsedData = await spawnParseWorker(rawData);
|
|
5381
|
+
const data = Array.isArray(parsedData) ? parsedData : [];
|
|
5382
|
+
if (!includeMeta) {
|
|
5383
|
+
const result2 = { data };
|
|
5384
|
+
memoryCache.set(key, result2, 1e3 * 60 * 60);
|
|
5385
|
+
return result2;
|
|
5386
|
+
}
|
|
5387
|
+
const rawMeta = await fileService.read(metaPath);
|
|
5388
|
+
let fields = [];
|
|
5389
|
+
let relations = {};
|
|
5390
|
+
if (rawMeta) {
|
|
5391
|
+
const parsedMeta = await spawnParseWorker(rawMeta);
|
|
5392
|
+
fields = parsedMeta?.fields ?? [];
|
|
5393
|
+
relations = parsedMeta?.relations ?? {};
|
|
5394
|
+
}
|
|
5395
|
+
const result = {
|
|
5396
|
+
data,
|
|
5397
|
+
fields,
|
|
5398
|
+
relations
|
|
5399
|
+
};
|
|
5400
|
+
memoryCache.set(key, result, 1e3 * 60 * 60);
|
|
5401
|
+
return result;
|
|
5402
|
+
}
|
|
5403
|
+
async function loadData(includeMeta = true) {
|
|
5404
|
+
try {
|
|
5405
|
+
const listResult = await fileService.list(MODELS_DIR2);
|
|
5406
|
+
if (!listResult || !Array.isArray(listResult.files)) {
|
|
5407
|
+
console.log("No models found");
|
|
5408
|
+
return {};
|
|
5409
|
+
}
|
|
5410
|
+
const result = {};
|
|
5411
|
+
for (const file of listResult.files) {
|
|
5412
|
+
if (file.type !== "file") continue;
|
|
5413
|
+
if (!file.name.endsWith(".json")) continue;
|
|
5414
|
+
const fileName = file.name;
|
|
5415
|
+
const modelName = fileName.replace(/\.json$/, "");
|
|
5416
|
+
const dataPath = `${MODELS_DIR2}/${fileName}`;
|
|
5417
|
+
const rawData = await fileService.read(dataPath);
|
|
5418
|
+
if (!rawData) continue;
|
|
5419
|
+
const parsedData = await spawnParseWorker(rawData);
|
|
5420
|
+
const data = Array.isArray(parsedData) ? parsedData : [];
|
|
5421
|
+
if (!includeMeta) {
|
|
5422
|
+
result[modelName] = { data };
|
|
5423
|
+
continue;
|
|
5424
|
+
}
|
|
5425
|
+
const metaPath = `${MODELS_META_DIR2}/${encodeURIComponent(
|
|
5426
|
+
modelName
|
|
5427
|
+
)}.meta.json`;
|
|
5428
|
+
const rawMeta = await fileService.read(metaPath);
|
|
5429
|
+
let fields = [];
|
|
5430
|
+
let relations = {};
|
|
5431
|
+
if (rawMeta) {
|
|
5432
|
+
const parsedMeta = await spawnParseWorker(rawMeta);
|
|
5433
|
+
fields = parsedMeta?.fields ?? [];
|
|
5434
|
+
relations = parsedMeta?.relations ?? {};
|
|
5435
|
+
}
|
|
5436
|
+
result[modelName] = {
|
|
5437
|
+
data,
|
|
5438
|
+
fields,
|
|
5439
|
+
relations
|
|
5440
|
+
};
|
|
5441
|
+
}
|
|
5442
|
+
return result;
|
|
5443
|
+
} catch (error) {
|
|
5444
|
+
console.error("Error loading data:", error);
|
|
5445
|
+
throw error;
|
|
5446
|
+
}
|
|
5447
|
+
}
|
|
5448
|
+
|
|
5449
|
+
// src/services/filesystem-service/snapshot-helper.ts
|
|
5450
|
+
var createEmptySnapshot = () => {
|
|
5451
|
+
return {
|
|
5452
|
+
data: []
|
|
5453
|
+
};
|
|
5454
|
+
};
|
|
5455
|
+
var generateNextId = (existingIds, startFrom = 1) => {
|
|
5456
|
+
if (!existingIds || existingIds.length === 0) {
|
|
5457
|
+
return startFrom;
|
|
5458
|
+
}
|
|
5459
|
+
const maxId = Math.max(...existingIds, startFrom - 1);
|
|
5460
|
+
return maxId + 1;
|
|
5461
|
+
};
|
|
5462
|
+
var loadSnapshot = async ({
|
|
5463
|
+
modelName
|
|
5464
|
+
}) => {
|
|
5465
|
+
try {
|
|
5466
|
+
const snapshot = await loadModelData(modelName);
|
|
5467
|
+
if (!snapshot || typeof snapshot !== "object") {
|
|
5468
|
+
console.warn("invalid snapshot, creating new one");
|
|
5469
|
+
return createEmptySnapshot();
|
|
5470
|
+
}
|
|
5471
|
+
return {
|
|
5472
|
+
data: Array.isArray(snapshot.data) ? snapshot.data : []
|
|
5473
|
+
};
|
|
5474
|
+
} catch (error) {
|
|
5475
|
+
console.error("Failed to load snapshot:", error);
|
|
5476
|
+
return createEmptySnapshot();
|
|
5477
|
+
}
|
|
5478
|
+
};
|
|
5479
|
+
var getExistingIds = (snapshot) => {
|
|
5480
|
+
return snapshot.data.map((order) => order.id).filter((id) => typeof id === "number");
|
|
5481
|
+
};
|
|
5482
|
+
var saveSnapshot = async ({
|
|
5483
|
+
snapshot,
|
|
5484
|
+
modelName
|
|
5485
|
+
}) => {
|
|
5486
|
+
try {
|
|
5487
|
+
await import_snapshot_default({
|
|
5488
|
+
data: JSON.stringify({
|
|
5489
|
+
[modelName]: snapshot
|
|
5490
|
+
})
|
|
5491
|
+
});
|
|
5492
|
+
return true;
|
|
5493
|
+
} catch (error) {
|
|
5494
|
+
console.error("failed to save snapshot:", error);
|
|
5495
|
+
return false;
|
|
5496
|
+
}
|
|
5497
|
+
};
|
|
5498
|
+
|
|
5499
|
+
// src/services/filesystem-service/model-repository.ts
|
|
5500
|
+
var ModelRepository = class {
|
|
5501
|
+
getRecord = async ({
|
|
5502
|
+
id,
|
|
5503
|
+
modelName
|
|
5504
|
+
}) => {
|
|
5505
|
+
try {
|
|
5506
|
+
const snapshot = await loadSnapshot({
|
|
5507
|
+
modelName
|
|
5508
|
+
});
|
|
5509
|
+
return snapshot.data.find((record) => record.id === id) || null;
|
|
5510
|
+
} catch (error) {
|
|
5511
|
+
console.error("failed to get record:", error);
|
|
5512
|
+
return null;
|
|
5513
|
+
}
|
|
5514
|
+
};
|
|
5515
|
+
addRecord = async ({
|
|
5516
|
+
newRecord,
|
|
5517
|
+
modelName
|
|
5518
|
+
}) => {
|
|
5519
|
+
try {
|
|
5520
|
+
const snapshot = await loadSnapshot({
|
|
5521
|
+
modelName
|
|
5522
|
+
});
|
|
5523
|
+
const existingIds = getExistingIds(snapshot);
|
|
5524
|
+
const newId = generateNextId(existingIds, snapshot.data.length);
|
|
5525
|
+
snapshot.data.push({
|
|
5526
|
+
...newRecord,
|
|
5527
|
+
id: newId
|
|
5528
|
+
});
|
|
5529
|
+
const saved = await saveSnapshot({
|
|
5530
|
+
snapshot,
|
|
5531
|
+
modelName
|
|
5532
|
+
});
|
|
5533
|
+
if (!saved) {
|
|
5534
|
+
console.error("failed to add new record");
|
|
5535
|
+
return [];
|
|
5536
|
+
}
|
|
5537
|
+
console.log(`\u2705 ${snapshot.data.length} records saved`);
|
|
5538
|
+
return snapshot.data;
|
|
5539
|
+
} catch (error) {
|
|
5540
|
+
console.error("failed to add new record:", error);
|
|
5541
|
+
return [];
|
|
5542
|
+
}
|
|
5543
|
+
};
|
|
5544
|
+
updateRecord = async ({
|
|
5545
|
+
id,
|
|
5546
|
+
update,
|
|
5547
|
+
modelName
|
|
5548
|
+
}) => {
|
|
5549
|
+
try {
|
|
5550
|
+
const snapshot = await loadSnapshot({
|
|
5551
|
+
modelName
|
|
5552
|
+
});
|
|
5553
|
+
const index = snapshot.data.findIndex((record) => record.id === id);
|
|
5554
|
+
if (index === -1) {
|
|
5555
|
+
console.error(`record with id ${id} not found`);
|
|
5556
|
+
return false;
|
|
5557
|
+
}
|
|
5558
|
+
snapshot.data[index] = {
|
|
5559
|
+
...snapshot.data[index],
|
|
5560
|
+
...update
|
|
5561
|
+
};
|
|
5562
|
+
return await saveSnapshot({
|
|
5563
|
+
snapshot,
|
|
5564
|
+
modelName
|
|
5565
|
+
});
|
|
5566
|
+
} catch (error) {
|
|
5567
|
+
console.error("error updating record:", error);
|
|
5568
|
+
return false;
|
|
5569
|
+
}
|
|
5570
|
+
};
|
|
5571
|
+
deleteRecord = async ({
|
|
5572
|
+
id,
|
|
5573
|
+
modelName
|
|
5574
|
+
}) => {
|
|
5575
|
+
try {
|
|
5576
|
+
const snapshot = await loadSnapshot({
|
|
5577
|
+
modelName
|
|
5578
|
+
});
|
|
5579
|
+
const before = snapshot.data.length;
|
|
5580
|
+
snapshot.data = snapshot.data.filter((record) => record.id !== id);
|
|
5581
|
+
if (snapshot.data.length === before) {
|
|
5582
|
+
console.error(`record with id ${id} not found`);
|
|
5583
|
+
return false;
|
|
5584
|
+
}
|
|
5585
|
+
return await saveSnapshot({
|
|
5586
|
+
snapshot,
|
|
5587
|
+
modelName
|
|
5588
|
+
});
|
|
5589
|
+
} catch (error) {
|
|
5590
|
+
console.error("error deleting record:", error);
|
|
5591
|
+
return false;
|
|
5592
|
+
}
|
|
5593
|
+
};
|
|
5594
|
+
};
|
|
5595
|
+
|
|
5596
|
+
// src/services/pos-service/add-entity.ts
|
|
5597
|
+
var addEntityService = (env) => {
|
|
5598
|
+
const isLocalMode = env?.isLocalMode;
|
|
5599
|
+
const repo = new ModelRepository();
|
|
5600
|
+
const addEntity = useCallback13(
|
|
5601
|
+
({
|
|
5602
|
+
model,
|
|
5603
|
+
values,
|
|
5604
|
+
xNode,
|
|
5605
|
+
service,
|
|
5606
|
+
isCreateEndpoint = false
|
|
5607
|
+
}) => {
|
|
5608
|
+
if (isLocalMode) {
|
|
5609
|
+
return repo.addRecord({
|
|
5610
|
+
newRecord: values,
|
|
5611
|
+
modelName: model
|
|
5612
|
+
});
|
|
5613
|
+
}
|
|
5614
|
+
const jsonData = {
|
|
5615
|
+
model,
|
|
5616
|
+
values
|
|
5617
|
+
};
|
|
5618
|
+
return env?.requests.post(
|
|
5619
|
+
isCreateEndpoint ? "/create" /* CREATE_PATH */ : "/call" /* CALL_PATH */,
|
|
5620
|
+
jsonData,
|
|
5621
|
+
{
|
|
5622
|
+
headers: {
|
|
5623
|
+
"Content-Type": "application/json",
|
|
5624
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
5625
|
+
}
|
|
5626
|
+
},
|
|
5627
|
+
service
|
|
5628
|
+
);
|
|
5629
|
+
},
|
|
5630
|
+
[env, isLocalMode]
|
|
5631
|
+
);
|
|
5632
|
+
return {
|
|
5633
|
+
addEntity
|
|
5634
|
+
};
|
|
5635
|
+
};
|
|
5636
|
+
|
|
5637
|
+
// src/services/pos-service/change-order-preparation-state.ts
|
|
5638
|
+
import { useCallback as useCallback14 } from "react";
|
|
5639
|
+
var changOrderPreparationStateService = (env) => {
|
|
5640
|
+
const changeOrderPreparationState = useCallback14(
|
|
5641
|
+
({
|
|
5642
|
+
orderId,
|
|
5643
|
+
stageId,
|
|
5644
|
+
preparationDisplayId,
|
|
5645
|
+
xNode,
|
|
5646
|
+
service
|
|
5647
|
+
}) => {
|
|
5648
|
+
const jsonData = {
|
|
5649
|
+
model: "pos_preparation_display.order" /* POS_PREPARATION_ORDER */,
|
|
5650
|
+
method: "change_order_stage" /* CHANGE_ORDER_STAGE */,
|
|
5651
|
+
ids: orderId,
|
|
5652
|
+
kwargs: {
|
|
5653
|
+
stage_id: stageId,
|
|
5654
|
+
preparation_display_id: preparationDisplayId
|
|
5655
|
+
}
|
|
5656
|
+
};
|
|
5657
|
+
return env?.requests.post(
|
|
5658
|
+
"/call" /* CALL_PATH */,
|
|
5659
|
+
jsonData,
|
|
5660
|
+
{
|
|
5661
|
+
headers: {
|
|
5662
|
+
"Content-Type": "application/json",
|
|
5663
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
5664
|
+
}
|
|
5665
|
+
},
|
|
5666
|
+
service
|
|
5667
|
+
);
|
|
5668
|
+
},
|
|
5669
|
+
[env]
|
|
5670
|
+
);
|
|
5671
|
+
return {
|
|
5672
|
+
changeOrderPreparationState
|
|
5673
|
+
};
|
|
5674
|
+
};
|
|
5675
|
+
|
|
5676
|
+
// src/services/pos-service/check-payment.ts
|
|
5677
|
+
import { useCallback as useCallback15 } from "react";
|
|
5678
|
+
var checkPaymentService = (env) => {
|
|
5679
|
+
const checkPayment = useCallback15(
|
|
5680
|
+
({
|
|
5681
|
+
model,
|
|
5682
|
+
ids,
|
|
5683
|
+
withContext,
|
|
5684
|
+
xNode,
|
|
5685
|
+
service
|
|
5686
|
+
}) => {
|
|
5687
|
+
const jsonData = {
|
|
5688
|
+
model,
|
|
5689
|
+
method: "check" /* CHECK */,
|
|
5690
|
+
ids,
|
|
5691
|
+
with_context: withContext
|
|
5692
|
+
};
|
|
5693
|
+
return env?.requests.post(
|
|
5694
|
+
"/call" /* CALL_PATH */,
|
|
5695
|
+
jsonData,
|
|
5696
|
+
{
|
|
5697
|
+
headers: {
|
|
5698
|
+
"Content-Type": "application/json",
|
|
5699
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
5700
|
+
}
|
|
5701
|
+
},
|
|
5702
|
+
service
|
|
5703
|
+
);
|
|
5704
|
+
},
|
|
5705
|
+
[env]
|
|
5706
|
+
);
|
|
5707
|
+
return {
|
|
5708
|
+
checkPayment
|
|
5709
|
+
};
|
|
5710
|
+
};
|
|
5711
|
+
|
|
5712
|
+
// src/services/pos-service/create-e-invoice.ts
|
|
5713
|
+
import { useCallback as useCallback16 } from "react";
|
|
5714
|
+
var createEInvoiceService = (env) => {
|
|
5715
|
+
const createEInvoice = useCallback16(
|
|
5716
|
+
async ({
|
|
5717
|
+
service,
|
|
5718
|
+
xNode,
|
|
5719
|
+
kwargs,
|
|
5720
|
+
ids,
|
|
5721
|
+
withContext
|
|
5722
|
+
}) => {
|
|
5723
|
+
const body = {
|
|
5724
|
+
model: "pos.order" /* POS_ORDER */,
|
|
5725
|
+
method: "create_e_invoice" /* CREATE_E_INVOICE */,
|
|
5726
|
+
kwargs,
|
|
5727
|
+
ids,
|
|
5728
|
+
with_context: withContext
|
|
5205
5729
|
};
|
|
5206
5730
|
return env?.requests?.post(
|
|
5207
5731
|
`${"/call" /* CALL_PATH */}`,
|
|
@@ -5225,6 +5749,8 @@ var createEInvoiceService = (env) => {
|
|
|
5225
5749
|
// src/services/pos-service/create-entity.ts
|
|
5226
5750
|
import { useCallback as useCallback17 } from "react";
|
|
5227
5751
|
var createEntityService = (env) => {
|
|
5752
|
+
const isLocalMode = env?.isLocalMode;
|
|
5753
|
+
const repo = new ModelRepository();
|
|
5228
5754
|
const createEntity = useCallback17(
|
|
5229
5755
|
({
|
|
5230
5756
|
model,
|
|
@@ -5232,6 +5758,12 @@ var createEntityService = (env) => {
|
|
|
5232
5758
|
xNode,
|
|
5233
5759
|
service
|
|
5234
5760
|
}) => {
|
|
5761
|
+
if (isLocalMode) {
|
|
5762
|
+
return repo.addRecord({
|
|
5763
|
+
newRecord: args,
|
|
5764
|
+
modelName: model
|
|
5765
|
+
});
|
|
5766
|
+
}
|
|
5235
5767
|
const jsonData = {
|
|
5236
5768
|
model,
|
|
5237
5769
|
method: "create" /* CREATE */,
|
|
@@ -5249,7 +5781,7 @@ var createEntityService = (env) => {
|
|
|
5249
5781
|
service
|
|
5250
5782
|
);
|
|
5251
5783
|
},
|
|
5252
|
-
[env]
|
|
5784
|
+
[env, isLocalMode]
|
|
5253
5785
|
);
|
|
5254
5786
|
return {
|
|
5255
5787
|
createEntity
|
|
@@ -5334,6 +5866,8 @@ var createSessionService = (env) => {
|
|
|
5334
5866
|
// src/services/pos-service/delete-entity.ts
|
|
5335
5867
|
import { useCallback as useCallback20 } from "react";
|
|
5336
5868
|
var deleteEntityService = (env) => {
|
|
5869
|
+
const isLocalMode = env?.isLocalMode;
|
|
5870
|
+
const repo = new ModelRepository();
|
|
5337
5871
|
const deleteEntity = useCallback20(
|
|
5338
5872
|
({
|
|
5339
5873
|
model,
|
|
@@ -5342,6 +5876,14 @@ var deleteEntityService = (env) => {
|
|
|
5342
5876
|
service,
|
|
5343
5877
|
method
|
|
5344
5878
|
}) => {
|
|
5879
|
+
if (isLocalMode) {
|
|
5880
|
+
const id = ids[0];
|
|
5881
|
+
if (!id) return;
|
|
5882
|
+
return repo.deleteRecord({
|
|
5883
|
+
modelName: model,
|
|
5884
|
+
id
|
|
5885
|
+
});
|
|
5886
|
+
}
|
|
5345
5887
|
const jsonData = {
|
|
5346
5888
|
model,
|
|
5347
5889
|
ids,
|
|
@@ -5359,7 +5901,7 @@ var deleteEntityService = (env) => {
|
|
|
5359
5901
|
service
|
|
5360
5902
|
);
|
|
5361
5903
|
},
|
|
5362
|
-
[env]
|
|
5904
|
+
[env, isLocalMode]
|
|
5363
5905
|
);
|
|
5364
5906
|
return {
|
|
5365
5907
|
deleteEntity
|
|
@@ -5692,340 +6234,111 @@ var handleCloseSessionService = (env) => {
|
|
|
5692
6234
|
const handleCloseSession = useCallback29(
|
|
5693
6235
|
({
|
|
5694
6236
|
model,
|
|
5695
|
-
ids,
|
|
5696
|
-
xNode,
|
|
5697
|
-
service,
|
|
5698
|
-
method
|
|
5699
|
-
}) => {
|
|
5700
|
-
const jsonData = {
|
|
5701
|
-
model,
|
|
5702
|
-
ids,
|
|
5703
|
-
method
|
|
5704
|
-
};
|
|
5705
|
-
return env?.requests.post(
|
|
5706
|
-
"/call" /* CALL_PATH */,
|
|
5707
|
-
jsonData,
|
|
5708
|
-
{
|
|
5709
|
-
headers: {
|
|
5710
|
-
"Content-Type": "application/json",
|
|
5711
|
-
...xNode ? { "X-Node": xNode } : {}
|
|
5712
|
-
}
|
|
5713
|
-
},
|
|
5714
|
-
service
|
|
5715
|
-
);
|
|
5716
|
-
},
|
|
5717
|
-
[env]
|
|
5718
|
-
);
|
|
5719
|
-
return {
|
|
5720
|
-
handleCloseSession
|
|
5721
|
-
};
|
|
5722
|
-
};
|
|
5723
|
-
|
|
5724
|
-
// src/services/pos-service/handle-closing-detail-session.ts
|
|
5725
|
-
import { useCallback as useCallback30 } from "react";
|
|
5726
|
-
var handleClosingDetailSessionService = (env) => {
|
|
5727
|
-
const handleClosingDetailSession = useCallback30(
|
|
5728
|
-
({
|
|
5729
|
-
model,
|
|
5730
|
-
ids,
|
|
5731
|
-
method,
|
|
5732
|
-
xNode,
|
|
5733
|
-
service,
|
|
5734
|
-
kwargs
|
|
5735
|
-
}) => {
|
|
5736
|
-
const jsonData = {
|
|
5737
|
-
model,
|
|
5738
|
-
ids,
|
|
5739
|
-
method,
|
|
5740
|
-
kwargs
|
|
5741
|
-
};
|
|
5742
|
-
return env?.requests.post(
|
|
5743
|
-
"/call" /* CALL_PATH */,
|
|
5744
|
-
jsonData,
|
|
5745
|
-
{
|
|
5746
|
-
headers: {
|
|
5747
|
-
"Content-Type": "application/json",
|
|
5748
|
-
...xNode ? { "X-Node": xNode } : {}
|
|
5749
|
-
}
|
|
5750
|
-
},
|
|
5751
|
-
service
|
|
5752
|
-
);
|
|
5753
|
-
},
|
|
5754
|
-
[env]
|
|
5755
|
-
);
|
|
5756
|
-
return {
|
|
5757
|
-
handleClosingDetailSession
|
|
5758
|
-
};
|
|
5759
|
-
};
|
|
5760
|
-
|
|
5761
|
-
// src/services/pos-service/handle-closing-session.ts
|
|
5762
|
-
import { useCallback as useCallback31 } from "react";
|
|
5763
|
-
var handleClosingSessionService = (env) => {
|
|
5764
|
-
const handleClosingSession = useCallback31(
|
|
5765
|
-
({
|
|
5766
|
-
model,
|
|
5767
|
-
method,
|
|
5768
|
-
ids,
|
|
5769
|
-
kwargs,
|
|
5770
|
-
xNode,
|
|
5771
|
-
service
|
|
5772
|
-
}) => {
|
|
5773
|
-
const jsonData = {
|
|
5774
|
-
model,
|
|
5775
|
-
method,
|
|
5776
|
-
ids,
|
|
5777
|
-
kwargs
|
|
5778
|
-
};
|
|
5779
|
-
return env?.requests.post(
|
|
5780
|
-
"/call" /* CALL_PATH */,
|
|
5781
|
-
jsonData,
|
|
5782
|
-
{
|
|
5783
|
-
headers: {
|
|
5784
|
-
"Content-Type": "application/json",
|
|
5785
|
-
...xNode ? { "X-Node": xNode } : {}
|
|
5786
|
-
}
|
|
5787
|
-
},
|
|
5788
|
-
service
|
|
5789
|
-
);
|
|
5790
|
-
},
|
|
5791
|
-
[env]
|
|
5792
|
-
);
|
|
5793
|
-
return {
|
|
5794
|
-
handleClosingSession
|
|
5795
|
-
};
|
|
5796
|
-
};
|
|
5797
|
-
|
|
5798
|
-
// src/services/pos-service/load-data-pos-session.ts
|
|
5799
|
-
import { useCallback as useCallback32 } from "react";
|
|
5800
|
-
|
|
5801
|
-
// src/services/filesystem-service/file-service.ts
|
|
5802
|
-
import { Directory, Encoding, Filesystem } from "@capacitor/filesystem";
|
|
5803
|
-
var fileService = {
|
|
5804
|
-
async read(path) {
|
|
5805
|
-
try {
|
|
5806
|
-
const res = await Filesystem.readFile({
|
|
5807
|
-
path,
|
|
5808
|
-
directory: Directory.Data,
|
|
5809
|
-
encoding: Encoding.UTF8
|
|
5810
|
-
});
|
|
5811
|
-
if (typeof res.data === "string") return res.data;
|
|
5812
|
-
if (res.data instanceof Blob) return await res.data.text();
|
|
5813
|
-
return null;
|
|
5814
|
-
} catch {
|
|
5815
|
-
return null;
|
|
5816
|
-
}
|
|
5817
|
-
},
|
|
5818
|
-
async write(path, data) {
|
|
5819
|
-
await Filesystem.writeFile({
|
|
5820
|
-
path,
|
|
5821
|
-
data,
|
|
5822
|
-
directory: Directory.Data,
|
|
5823
|
-
encoding: Encoding.UTF8,
|
|
5824
|
-
recursive: true
|
|
5825
|
-
});
|
|
5826
|
-
},
|
|
5827
|
-
async writeAtomic(path, data) {
|
|
5828
|
-
const tempPath = path + ".tmp";
|
|
5829
|
-
await Filesystem.writeFile({
|
|
5830
|
-
path: tempPath,
|
|
5831
|
-
data,
|
|
5832
|
-
directory: Directory.Data,
|
|
5833
|
-
encoding: Encoding.UTF8,
|
|
5834
|
-
recursive: true
|
|
5835
|
-
});
|
|
5836
|
-
try {
|
|
5837
|
-
await Filesystem.deleteFile({
|
|
5838
|
-
path,
|
|
5839
|
-
directory: Directory.Data
|
|
5840
|
-
});
|
|
5841
|
-
} catch {
|
|
5842
|
-
}
|
|
5843
|
-
await Filesystem.rename({
|
|
5844
|
-
from: tempPath,
|
|
5845
|
-
to: path,
|
|
5846
|
-
directory: Directory.Data
|
|
5847
|
-
});
|
|
5848
|
-
},
|
|
5849
|
-
async delete(path) {
|
|
5850
|
-
try {
|
|
5851
|
-
await Filesystem.deleteFile({
|
|
5852
|
-
path,
|
|
5853
|
-
directory: Directory.Data
|
|
5854
|
-
});
|
|
5855
|
-
} catch {
|
|
5856
|
-
}
|
|
5857
|
-
},
|
|
5858
|
-
async exists(path) {
|
|
5859
|
-
try {
|
|
5860
|
-
await Filesystem.stat({
|
|
5861
|
-
path,
|
|
5862
|
-
directory: Directory.Data
|
|
5863
|
-
});
|
|
5864
|
-
return true;
|
|
5865
|
-
} catch {
|
|
5866
|
-
return false;
|
|
5867
|
-
}
|
|
5868
|
-
},
|
|
5869
|
-
async mkdir(path) {
|
|
5870
|
-
try {
|
|
5871
|
-
await Filesystem.mkdir({
|
|
5872
|
-
path,
|
|
5873
|
-
directory: Directory.Data,
|
|
5874
|
-
recursive: true
|
|
5875
|
-
});
|
|
5876
|
-
} catch (e) {
|
|
5877
|
-
if (!String(e?.message).includes("Exists")) {
|
|
5878
|
-
throw e;
|
|
5879
|
-
}
|
|
5880
|
-
}
|
|
5881
|
-
},
|
|
5882
|
-
async list(path) {
|
|
5883
|
-
return Filesystem.readdir({
|
|
5884
|
-
path,
|
|
5885
|
-
directory: Directory.Data
|
|
5886
|
-
});
|
|
5887
|
-
},
|
|
5888
|
-
async getUri(path) {
|
|
5889
|
-
return Filesystem.getUri({
|
|
5890
|
-
path,
|
|
5891
|
-
directory: Directory.Data
|
|
5892
|
-
});
|
|
5893
|
-
}
|
|
5894
|
-
};
|
|
5895
|
-
|
|
5896
|
-
// src/services/filesystem-service/json-worker.ts
|
|
5897
|
-
self.addEventListener("message", async (ev) => {
|
|
5898
|
-
const { id, cmd, payload } = ev.data;
|
|
5899
|
-
try {
|
|
5900
|
-
if (cmd === "parse") {
|
|
5901
|
-
const parsed = JSON.parse(payload);
|
|
5902
|
-
self.postMessage({ id, ok: true, result: parsed });
|
|
5903
|
-
} else if (cmd === "stringify") {
|
|
5904
|
-
const str = JSON.stringify(payload);
|
|
5905
|
-
self.postMessage({ id, ok: true, result: str });
|
|
5906
|
-
}
|
|
5907
|
-
} catch (err) {
|
|
5908
|
-
self.postMessage({ id, ok: false, error: err?.message || String(err) });
|
|
5909
|
-
}
|
|
5910
|
-
});
|
|
5911
|
-
function spawnParseWorker(raw) {
|
|
5912
|
-
return new Promise((resolve, reject) => {
|
|
5913
|
-
const worker = new Worker(new URL("./json-worker.ts", import.meta.url), {
|
|
5914
|
-
type: "module"
|
|
5915
|
-
});
|
|
5916
|
-
const id = Math.random().toString(36).slice(2);
|
|
5917
|
-
worker.onmessage = (ev) => {
|
|
5918
|
-
const { ok, result, error } = ev.data;
|
|
5919
|
-
if (ok) {
|
|
5920
|
-
resolve(result);
|
|
5921
|
-
} else {
|
|
5922
|
-
reject(new Error(error));
|
|
5923
|
-
}
|
|
5924
|
-
worker.terminate();
|
|
5925
|
-
};
|
|
5926
|
-
worker.postMessage({ id, cmd: "parse", payload: raw });
|
|
5927
|
-
});
|
|
5928
|
-
}
|
|
5929
|
-
function spawnStringifyWorker(obj) {
|
|
5930
|
-
return new Promise((resolve, reject) => {
|
|
5931
|
-
const worker = new Worker(new URL("./json-worker.ts", import.meta.url), {
|
|
5932
|
-
type: "module"
|
|
5933
|
-
});
|
|
5934
|
-
worker.onmessage = (ev) => {
|
|
5935
|
-
const { ok, result, error } = ev.data;
|
|
5936
|
-
if (ok) resolve(result);
|
|
5937
|
-
else reject(new Error(error));
|
|
5938
|
-
worker.terminate();
|
|
5939
|
-
};
|
|
5940
|
-
worker.postMessage({ cmd: "stringify", payload: obj });
|
|
5941
|
-
});
|
|
5942
|
-
}
|
|
6237
|
+
ids,
|
|
6238
|
+
xNode,
|
|
6239
|
+
service,
|
|
6240
|
+
method
|
|
6241
|
+
}) => {
|
|
6242
|
+
const jsonData = {
|
|
6243
|
+
model,
|
|
6244
|
+
ids,
|
|
6245
|
+
method
|
|
6246
|
+
};
|
|
6247
|
+
return env?.requests.post(
|
|
6248
|
+
"/call" /* CALL_PATH */,
|
|
6249
|
+
jsonData,
|
|
6250
|
+
{
|
|
6251
|
+
headers: {
|
|
6252
|
+
"Content-Type": "application/json",
|
|
6253
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
6254
|
+
}
|
|
6255
|
+
},
|
|
6256
|
+
service
|
|
6257
|
+
);
|
|
6258
|
+
},
|
|
6259
|
+
[env]
|
|
6260
|
+
);
|
|
6261
|
+
return {
|
|
6262
|
+
handleCloseSession
|
|
6263
|
+
};
|
|
6264
|
+
};
|
|
5943
6265
|
|
|
5944
|
-
// src/services/
|
|
5945
|
-
|
|
5946
|
-
|
|
5947
|
-
|
|
5948
|
-
|
|
5949
|
-
|
|
5950
|
-
|
|
5951
|
-
|
|
5952
|
-
|
|
5953
|
-
|
|
5954
|
-
|
|
5955
|
-
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
5959
|
-
|
|
5960
|
-
|
|
5961
|
-
|
|
5962
|
-
|
|
5963
|
-
|
|
5964
|
-
|
|
6266
|
+
// src/services/pos-service/handle-closing-detail-session.ts
|
|
6267
|
+
import { useCallback as useCallback30 } from "react";
|
|
6268
|
+
var handleClosingDetailSessionService = (env) => {
|
|
6269
|
+
const handleClosingDetailSession = useCallback30(
|
|
6270
|
+
({
|
|
6271
|
+
model,
|
|
6272
|
+
ids,
|
|
6273
|
+
method,
|
|
6274
|
+
xNode,
|
|
6275
|
+
service,
|
|
6276
|
+
kwargs
|
|
6277
|
+
}) => {
|
|
6278
|
+
const jsonData = {
|
|
6279
|
+
model,
|
|
6280
|
+
ids,
|
|
6281
|
+
method,
|
|
6282
|
+
kwargs
|
|
6283
|
+
};
|
|
6284
|
+
return env?.requests.post(
|
|
6285
|
+
"/call" /* CALL_PATH */,
|
|
6286
|
+
jsonData,
|
|
6287
|
+
{
|
|
6288
|
+
headers: {
|
|
6289
|
+
"Content-Type": "application/json",
|
|
6290
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
6291
|
+
}
|
|
6292
|
+
},
|
|
6293
|
+
service
|
|
6294
|
+
);
|
|
6295
|
+
},
|
|
6296
|
+
[env]
|
|
6297
|
+
);
|
|
6298
|
+
return {
|
|
6299
|
+
handleClosingDetailSession
|
|
6300
|
+
};
|
|
5965
6301
|
};
|
|
5966
|
-
var memoryCache = new MemoryCache();
|
|
5967
6302
|
|
|
5968
|
-
// src/services/
|
|
5969
|
-
|
|
5970
|
-
var
|
|
5971
|
-
|
|
5972
|
-
|
|
5973
|
-
|
|
5974
|
-
|
|
5975
|
-
|
|
5976
|
-
|
|
5977
|
-
|
|
5978
|
-
|
|
5979
|
-
}
|
|
5980
|
-
|
|
5981
|
-
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
const fileName = file.name;
|
|
5986
|
-
const modelName = fileName.replace(/\.json$/, "");
|
|
5987
|
-
const dataPath = `${MODELS_DIR}/${fileName}`;
|
|
5988
|
-
console.log("\u{1F4C2} Reading data from:", dataPath);
|
|
5989
|
-
const rawData = await fileService.read(dataPath);
|
|
5990
|
-
console.log("\u2705 Data read, length:", rawData?.length);
|
|
5991
|
-
if (!rawData) continue;
|
|
5992
|
-
console.log("\u{1F504} Parsing data...");
|
|
5993
|
-
const parsedData = await spawnParseWorker(rawData);
|
|
5994
|
-
console.log("\u2705 Data parsed");
|
|
5995
|
-
const data = Array.isArray(parsedData) ? parsedData : [];
|
|
5996
|
-
if (!includeMeta) {
|
|
5997
|
-
result[modelName] = { data };
|
|
5998
|
-
continue;
|
|
5999
|
-
}
|
|
6000
|
-
const metaPath = `${MODELS_META_DIR}/${encodeURIComponent(
|
|
6001
|
-
modelName
|
|
6002
|
-
)}.meta.json`;
|
|
6003
|
-
console.log("\u{1F4C2} Reading meta from:", metaPath);
|
|
6004
|
-
const rawMeta = await fileService.read(metaPath);
|
|
6005
|
-
let fields = [];
|
|
6006
|
-
let relations = {};
|
|
6007
|
-
if (rawMeta) {
|
|
6008
|
-
console.log("\u{1F504} Parsing meta...");
|
|
6009
|
-
const parsedMeta = await spawnParseWorker(rawMeta);
|
|
6010
|
-
fields = parsedMeta?.fields ?? [];
|
|
6011
|
-
relations = parsedMeta?.relations ?? {};
|
|
6012
|
-
console.log("\u2705 Meta parsed");
|
|
6013
|
-
}
|
|
6014
|
-
result[modelName] = {
|
|
6015
|
-
data,
|
|
6016
|
-
fields,
|
|
6017
|
-
relations
|
|
6303
|
+
// src/services/pos-service/handle-closing-session.ts
|
|
6304
|
+
import { useCallback as useCallback31 } from "react";
|
|
6305
|
+
var handleClosingSessionService = (env) => {
|
|
6306
|
+
const handleClosingSession = useCallback31(
|
|
6307
|
+
({
|
|
6308
|
+
model,
|
|
6309
|
+
method,
|
|
6310
|
+
ids,
|
|
6311
|
+
kwargs,
|
|
6312
|
+
xNode,
|
|
6313
|
+
service
|
|
6314
|
+
}) => {
|
|
6315
|
+
const jsonData = {
|
|
6316
|
+
model,
|
|
6317
|
+
method,
|
|
6318
|
+
ids,
|
|
6319
|
+
kwargs
|
|
6018
6320
|
};
|
|
6019
|
-
|
|
6020
|
-
|
|
6021
|
-
|
|
6022
|
-
|
|
6023
|
-
|
|
6024
|
-
|
|
6025
|
-
|
|
6026
|
-
}
|
|
6321
|
+
return env?.requests.post(
|
|
6322
|
+
"/call" /* CALL_PATH */,
|
|
6323
|
+
jsonData,
|
|
6324
|
+
{
|
|
6325
|
+
headers: {
|
|
6326
|
+
"Content-Type": "application/json",
|
|
6327
|
+
...xNode ? { "X-Node": xNode } : {}
|
|
6328
|
+
}
|
|
6329
|
+
},
|
|
6330
|
+
service
|
|
6331
|
+
);
|
|
6332
|
+
},
|
|
6333
|
+
[env]
|
|
6334
|
+
);
|
|
6335
|
+
return {
|
|
6336
|
+
handleClosingSession
|
|
6337
|
+
};
|
|
6338
|
+
};
|
|
6027
6339
|
|
|
6028
6340
|
// src/services/pos-service/load-data-pos-session.ts
|
|
6341
|
+
import { useCallback as useCallback32 } from "react";
|
|
6029
6342
|
var loadDataPosSessionService = (env) => {
|
|
6030
6343
|
const isLocalMode = env?.isLocalMode;
|
|
6031
6344
|
const loadDataPosSession = useCallback32(
|
|
@@ -6038,10 +6351,8 @@ var loadDataPosSessionService = (env) => {
|
|
|
6038
6351
|
modelsToLoad = [],
|
|
6039
6352
|
searchParams
|
|
6040
6353
|
}) => {
|
|
6041
|
-
console.log("isLocalMode", isLocalMode);
|
|
6042
6354
|
if (isLocalMode) {
|
|
6043
6355
|
const data = await loadData();
|
|
6044
|
-
console.log("\u2705 loadData resolved:", data);
|
|
6045
6356
|
return data;
|
|
6046
6357
|
}
|
|
6047
6358
|
const jsonData = {
|
|
@@ -6295,6 +6606,8 @@ var updateClosedSessionService = (env) => {
|
|
|
6295
6606
|
// src/services/pos-service/update-entity.ts
|
|
6296
6607
|
import { useCallback as useCallback39 } from "react";
|
|
6297
6608
|
var updateEntityService = (env) => {
|
|
6609
|
+
const isLocalMode = env?.isLocalMode;
|
|
6610
|
+
const repo = new ModelRepository();
|
|
6298
6611
|
const updateEntity = useCallback39(
|
|
6299
6612
|
({
|
|
6300
6613
|
model,
|
|
@@ -6304,6 +6617,15 @@ var updateEntityService = (env) => {
|
|
|
6304
6617
|
xNode,
|
|
6305
6618
|
service
|
|
6306
6619
|
}) => {
|
|
6620
|
+
if (isLocalMode) {
|
|
6621
|
+
const id = extractIdFromDomain(domain);
|
|
6622
|
+
if (!id) return;
|
|
6623
|
+
return repo.updateRecord({
|
|
6624
|
+
update: values,
|
|
6625
|
+
modelName: model,
|
|
6626
|
+
id
|
|
6627
|
+
});
|
|
6628
|
+
}
|
|
6307
6629
|
const jsonData = {
|
|
6308
6630
|
model,
|
|
6309
6631
|
domain,
|
|
@@ -6321,7 +6643,7 @@ var updateEntityService = (env) => {
|
|
|
6321
6643
|
service
|
|
6322
6644
|
);
|
|
6323
6645
|
},
|
|
6324
|
-
[env]
|
|
6646
|
+
[env, isLocalMode]
|
|
6325
6647
|
);
|
|
6326
6648
|
return {
|
|
6327
6649
|
updateEntity
|
|
@@ -6403,101 +6725,6 @@ var usePosService = () => {
|
|
|
6403
6725
|
return service;
|
|
6404
6726
|
};
|
|
6405
6727
|
|
|
6406
|
-
// src/services/filesystem-service/manifest.ts
|
|
6407
|
-
var MANIFEST_PATH = "pos/manifest.json";
|
|
6408
|
-
var MANIFEST_BAK_PATH = "pos/manifest.bak.json";
|
|
6409
|
-
async function writeManifest(manifest) {
|
|
6410
|
-
const oldRaw = await fileService.read(MANIFEST_PATH);
|
|
6411
|
-
if (oldRaw !== null) {
|
|
6412
|
-
await fileService.writeAtomic(MANIFEST_BAK_PATH, oldRaw);
|
|
6413
|
-
}
|
|
6414
|
-
await fileService.writeAtomic(MANIFEST_PATH, JSON.stringify(manifest));
|
|
6415
|
-
try {
|
|
6416
|
-
await fileService.delete(MANIFEST_BAK_PATH);
|
|
6417
|
-
} catch {
|
|
6418
|
-
}
|
|
6419
|
-
}
|
|
6420
|
-
|
|
6421
|
-
// src/services/filesystem-service/import-snapshot.ts
|
|
6422
|
-
var DATA_DIR = "pos";
|
|
6423
|
-
var MODELS_DIR2 = `${DATA_DIR}/models`;
|
|
6424
|
-
var MODELS_META_DIR2 = `${DATA_DIR}/models_meta`;
|
|
6425
|
-
var importSnapshot = async ({ data, onProgress }) => {
|
|
6426
|
-
onProgress?.(1, "Parsing snapshot");
|
|
6427
|
-
const parsed = await spawnParseWorker(data);
|
|
6428
|
-
const modelNames = Object.keys(parsed);
|
|
6429
|
-
const total = modelNames.length;
|
|
6430
|
-
const manifest = { version: (/* @__PURE__ */ new Date()).toISOString(), models: {} };
|
|
6431
|
-
const TMP_PREFIX = `pos/data/tmp_import_${Date.now()}`;
|
|
6432
|
-
await fileService.writeAtomic(`${TMP_PREFIX}/.marker`, "1");
|
|
6433
|
-
let i = 0;
|
|
6434
|
-
for (const model of modelNames) {
|
|
6435
|
-
i++;
|
|
6436
|
-
onProgress?.(
|
|
6437
|
-
Math.round(i / total * 100),
|
|
6438
|
-
`Processing ${model} (${i}/${total})`
|
|
6439
|
-
);
|
|
6440
|
-
const block = parsed[model];
|
|
6441
|
-
const dataPart = block?.data ?? block ?? [];
|
|
6442
|
-
const fields = block?.fields ?? [];
|
|
6443
|
-
const relations = block?.relations ?? {};
|
|
6444
|
-
const serialized = await spawnStringifyWorker(dataPart);
|
|
6445
|
-
const tmpModelPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.json`;
|
|
6446
|
-
await fileService.writeAtomic(tmpModelPath, serialized);
|
|
6447
|
-
const meta = {
|
|
6448
|
-
fields,
|
|
6449
|
-
relations,
|
|
6450
|
-
count: Array.isArray(dataPart) ? dataPart.length : 0,
|
|
6451
|
-
writtenAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
6452
|
-
};
|
|
6453
|
-
const tmpMetaPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`;
|
|
6454
|
-
await fileService.writeAtomic(tmpMetaPath, JSON.stringify(meta));
|
|
6455
|
-
manifest.models[model] = {
|
|
6456
|
-
file: `${MODELS_DIR2}/${encodeURIComponent(model)}.json`,
|
|
6457
|
-
metaFile: `${MODELS_META_DIR2}/${encodeURIComponent(model)}.meta.json`,
|
|
6458
|
-
count: meta.count,
|
|
6459
|
-
updatedAt: meta.writtenAt
|
|
6460
|
-
};
|
|
6461
|
-
}
|
|
6462
|
-
onProgress?.(95, "Committing import (moving files)");
|
|
6463
|
-
for (const model of modelNames) {
|
|
6464
|
-
const tmpModelPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.json`;
|
|
6465
|
-
const finalModelPath = `${MODELS_DIR2}/${encodeURIComponent(model)}.json`;
|
|
6466
|
-
const tmpMetaPath = `${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`;
|
|
6467
|
-
const finalMetaPath = `${MODELS_META_DIR2}/${encodeURIComponent(
|
|
6468
|
-
model
|
|
6469
|
-
)}.meta.json`;
|
|
6470
|
-
const tmpRaw = await fileService.read(tmpModelPath);
|
|
6471
|
-
if (tmpRaw !== null) await fileService.writeAtomic(finalModelPath, tmpRaw);
|
|
6472
|
-
const tmpMetaRaw = await fileService.read(tmpMetaPath);
|
|
6473
|
-
if (tmpMetaRaw !== null)
|
|
6474
|
-
await fileService.writeAtomic(finalMetaPath, tmpMetaRaw);
|
|
6475
|
-
onProgress?.(
|
|
6476
|
-
95 + Math.round(
|
|
6477
|
-
(Object.keys(manifest.models).indexOf(model) + 1) / modelNames.length * 5
|
|
6478
|
-
),
|
|
6479
|
-
`Committed ${model}`
|
|
6480
|
-
);
|
|
6481
|
-
}
|
|
6482
|
-
await writeManifest(manifest);
|
|
6483
|
-
try {
|
|
6484
|
-
for (const model of modelNames) {
|
|
6485
|
-
await fileService.delete(
|
|
6486
|
-
`${TMP_PREFIX}/${encodeURIComponent(model)}.json`
|
|
6487
|
-
);
|
|
6488
|
-
await fileService.delete(
|
|
6489
|
-
`${TMP_PREFIX}/${encodeURIComponent(model)}.meta.json`
|
|
6490
|
-
);
|
|
6491
|
-
}
|
|
6492
|
-
await fileService.delete(`${TMP_PREFIX}/.marker`);
|
|
6493
|
-
} catch (e) {
|
|
6494
|
-
console.log("Failed to cleanup tmp import files:", e);
|
|
6495
|
-
}
|
|
6496
|
-
onProgress?.(100, "Import complete");
|
|
6497
|
-
return manifest;
|
|
6498
|
-
};
|
|
6499
|
-
var import_snapshot_default = importSnapshot;
|
|
6500
|
-
|
|
6501
6728
|
// src/services/filesystem-service/init-snapshot.ts
|
|
6502
6729
|
var isSnapshotReady = async () => {
|
|
6503
6730
|
try {
|