w-serv-orm 1.1.15 → 1.1.17
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/README.md +119 -0
- package/dist/w-serv-orm.umd.js +2 -2
- package/dist/w-serv-orm.umd.js.map +1 -1
- package/docs/WServOrm.html +12 -6
- package/docs/WServOrm.mjs.html +96 -4
- package/docs/baseline.mjs.html +624 -0
- package/docs/global.html +1622 -0
- package/docs/index.html +2 -2
- package/package.json +1 -1
- package/src/WServOrm.mjs +94 -2
- package/src/baseline.mjs +552 -0
- package/src/getMapOrm.mjs +503 -54
- package/src/getProc.mjs +13 -4
- package/test/api-guard.test.mjs +401 -0
- package/test/api-keepuser.test.mjs +131 -0
- package/test/api-objcopy.test.mjs +277 -0
- package/test/tools/memOrm.mjs +122 -0
- package/test/unit-baseline.test.mjs +766 -0
- package/test/unit-guard.test.mjs +952 -0
- package/test/unit-keepuser.test.mjs +307 -0
- package/test/unit-objcopy.test.mjs +1522 -26
package/README.md
CHANGED
|
@@ -17,8 +17,127 @@ To view documentation or get support, visit [docs](https://yuda-lyu.github.io/w-
|
|
|
17
17
|
* 白名單外之運算子(例如 `$not $nor $regex $options $exists $all $where $expr`)、欄位層 `$and/$or`、函數值、`undefined` 值、空的 `$nin/$and/$or` 等由後端整批 reject,`procOrm` 以固定字串回傳(`select` 為 `failed to select data`,`delAll` 為 `failed to delete data`),後端錯誤原文只由 `console.log` 輸出,`delAll` 不刪除任何數據。
|
|
18
18
|
* `select` 未給、為 `undefined` 或 `{}` 回傳全部數據;傳了值卻不是條件物件(`null`、陣列、字串、數字、布林、函數、類別實例等)整批 reject。
|
|
19
19
|
* 條件內任何位置(含 `$and`/`$or` 元素與欄位運算子物件)若有 Symbol 鍵、不可列舉鍵(`invalid find of select, unsupported symbol key or non-enumerable property`),或 Proxy(含已撤銷者、原型為 Proxy 者)、帶 `Symbol.toStringTag` 者(含 Map、Set 等內建品牌物件)、內建品牌物件(含原型被改為 `null` 者)、非純物件(類別實例、偽原型等)、有空洞或額外屬性或不可列舉元素之陣列、帶自有屬性之 Date、函數值、Symbol 值(`invalid find of select, unsupported irregular object or array`),整批 reject(`delAll` 同),不查詢亦不刪除,且檢查期間與拒收後之診斷輸出皆不執行使用端程式(Proxy 陷阱、getter、`Symbol.toStringTag`、`util.inspect.custom`;被拒條件以本層建立之純資料快照輸出至 `console.log`,字串長度、層數與項數有上限)。這些結構在字串型主鍵表之轉型複製時會被洗掉,令後端本會拒收之條件變成較寬甚至無條件;JSON 資料通道無法產生這些結構。以 Proxy 包裝之條件(如 Vue 響應式物件)或 Mongoose、Sequelize 等文件須先轉為純物件(如 `{ ...filter }` 或 `JSON.parse(JSON.stringify(filter))`)。跨 realm(如 `vm`)之純物件照常:於字串型主鍵表之複製位置(頂層、`$and`/`$or` 元素、`id` 之運算子物件)被複製為本 realm 物件,其餘位置原樣交後端,現行 `w-orm-*` 之條件白名單要求本 realm 物件,故會 reject。
|
|
20
|
+
* 條件內共用子結構(同一物件被多處引用,僅行程內可造,JSON 資料通道只能產生樹):以最長路徑計深度(含循環),超過 64 個容器層(物件與陣列各算一層)者 reject `invalid find of select, too deep`;依出現次數展開後之物件總數(不含陣列)超過 100,000 者 reject `invalid find of select, too large`(`delAll` 同),不展開亦不查詢、不刪除;上限與後端 `cvOrmFind` 之 `maxNodes` 同值,本層只計物件(後端另計運算子物件、純量,且不計 `$and`/`$or` 之陣列),故凡本層因此拒收者後端必也拒收;同一子條件被重用於多處之合理寫法不受影響。物件或陣列之原型鏈長度超過 65 層者視為不乾淨而 reject `unsupported irregular object or array`(合法物件之原型鏈至多數層)。
|
|
20
21
|
* **`delAll` 為破壞性操作,須審慎使用,非必要不用**(刪除單筆請用 `del`):不給條件(未給、`undefined` 或 `{}`)即刪除全部數據,不另行確認;給了條件才是部分刪除。經資料通道(前端直接操作資料表)呼叫之 `delAll` 與此語意一致,不另加通道專屬限制,授權由開放處負責。條件值若來自可能為 `undefined`、`null` 或空陣列之變數,呼叫端須先自行判斷;經 JSON 傳輸時顯式傳入之 `undefined` 會成為 `null` 而被 reject,須省略參數或傳 `{}`。建議先以 `select(find)` 確認命中範圍再刪除(ORM 啟用快取而他方已寫入時,`select` 可能回傳快取,而 `delAll` 一律直讀資料庫,預覽不保證即實際刪除之集合)。
|
|
21
22
|
|
|
23
|
+
## Rows (insert, save, mix, del)
|
|
24
|
+
`insert`、`save`、`mix`(`add`、`del`、`diff`)與 `del` 之輸入列的檢查(皆於任何寫入之前整批 reject,訊息為固定字串,不回顯使用端之值;通過檢查之後,本層不再執行使用端程式——不呼叫 getter、setter 與 Proxy 陷阱,複製只取已驗證之資料):
|
|
25
|
+
* 列之主鍵 `id` 只認**自有、可列舉之資料屬性**(以屬性描述子讀取,不執行 getter):通過鍵檢查後,不可列舉、繼承而來或經存取器取得者視為未提供,寫入列由本套件補主鍵(與直接呼叫 ORM 寫入不可列舉之 `id` 時一致);自有可列舉之存取器(`get id()` 定義於列本身)則先整批 reject(`unsupported accessor property: data[k]`)。字串型主鍵欄之有限數字 `id` 僅在其為自有可列舉資料屬性時轉為字串。
|
|
26
|
+
* 列本身為 Proxy(含 Vue 響應式物件與已撤銷者)、函數(含 callable Proxy 與宣稱 `Symbol.toStringTag` 之函數)、原型鏈上有 `Symbol.toStringTag` 者、或 `util.types` 可辨識之內建品牌物件(Map、Set、WeakMap、WeakSet、Promise、ArrayBuffer、TypedArray、DataView、包裝物件、RegExp、Error 等,原型被改為 `null` 時無標籤可辨而會被洗成 `{}`)者 reject `failed to insert data, unsupported irregular object or array: data[0]`。`WeakRef`、`FinalizationRegistry`、`Intl.*`、`KeyObject`、`Blob`、`URL` 等宿主物件於原型被改為 `null` 時不辨識,結果與直接呼叫 ORM 一致(得到空物件:多筆批次中補主鍵而成只含主鍵之列,單筆批次則與直接以 `{}` 呼叫 ORM 相同,由後端視為無效而不寫入)。**以 Proxy 包裝之列或陣列(如 Vue 響應式)須先轉為純物件**(如 `{ ...row }`、`[...rows]` 或 `JSON.parse(JSON.stringify(rows))`)。類別實例含自有欄位之物件、`Object.create(proto)`、跨 realm 與 `null` 原型之列照常(僅複製自有可列舉鍵),這與條件(find)要求純物件不同:條件被洗掉會使查詢或刪除範圍變大,列被洗掉頂多得到多餘或空的列。
|
|
27
|
+
* 批次容器(`insert`、`save`、`del` 之輸入陣列,`mix` 之 `add`、`del`、`diff`)須為乾淨之真密陣列,且各索引須為自有資料屬性:Proxy(含已撤銷者,無法分類為陣列或單一列,不帶位置)、原型鏈有標籤、有空洞(`unsupported sparse array: data[1]`,`data[k]` 為首個空洞)、索引為存取器者 reject;稀疏巨陣列如 `new Array(2**32 - 1)` 於首個空洞即被拒,不逐索引迴圈;列內巢狀陣列有空洞者亦然。偽造 `Symbol.toStringTag` 為 `Array` 之類陣列物件不視為陣列:`insert`、`save` 視為單一列並以 irregular reject,`mix` 之三段回 `need the result object of ltdtDiffByKey`,單獨 `del` 視為單一列交 ORM(`del` 之各筆不檢查,ORM 可依其自身判準處置)。
|
|
28
|
+
* `mix` 之輸入物件本身須為乾淨之一般物件(Proxy、原型鏈有標籤者 reject `invalid input of mix, need the result object of ltdtDiffByKey`),`add`、`del`、`diff` 只取其自有資料屬性(繼承而來者不取,亦不執行原型上之 getter)。`mix` 之 `del` 列另須其 `id` 若存在為自有、可列舉之資料屬性(不得為存取器、繼承而來、不可列舉,列不得為 Proxy、函數宣稱標籤或帶標籤),否則 reject `failed to delete data, unsupported irregular object or array: data[0]`,使 `add`/`diff` 與 `del` 之同鍵比對所見之 `id` 即 ORM 刪除所用之 `id`(ORM 對不可列舉或繼承之 `id` 讀法不一)。
|
|
29
|
+
* 稽核欄位(`userId`、`timeCreate`、`userIdUpdate`、`timeUpdate`,schema 的 keys 含者)以 `defineProperty` 寫入列物件而不用賦值,故類別 DTO 原型上之 setter 不被執行;字串主鍵之列其原物件仍被寫入這些欄位(既有行為)。
|
|
30
|
+
* 上述各項只可能由行程內呼叫端構造,JSON 資料通道(解碼為一般物件與密陣列)不可達,通道來源之一般輸入行為不變。列內欄位值為共用子結構(DAG)者,其展開由 `wsemi` 之 `clearXSS` 進行,本套件之走訪為線性。
|
|
31
|
+
|
|
32
|
+
## Concurrent editing (write contract, withTabLocks, guardWrite, mustExist, keepUserId)
|
|
33
|
+
供「多位使用者可同時編輯、且可能開著舊畫面存檔」之後台使用:舊畫面存檔整次拒收(先動先贏、零寫入),看著最新資料改者與不帶基準之寫入(外部同步、外部應用)照常寫入,已刪之列不復活,不部分寫入。規格見 opensrcOper 之 `dspec/多人同時編輯之寫入契約.md`;以下為本套件提供之部分。
|
|
34
|
+
|
|
35
|
+
### 部署前提
|
|
36
|
+
* **單一行程**;**同表只由同一個 `WServOrm` 實例與同一個 `withTabLocks` 寫入**(鎖只在該實例內有效,多行程部署不在支援範圍,須另採資料庫交易或條件寫入)。
|
|
37
|
+
* **比對用之讀取不得經 ORM 快取**:`guardWrite` 之 `read` 由呼叫端提供,須直讀資料庫;`mustExist` 之存在檢查為 ORM 之 `select`,故同表須只由同一 ORM 實例寫入且不開 `useCache`(各 `w-orm-*` 之快取只反映本實例之寫入,且寫入後即作廢)。
|
|
38
|
+
* 不提供雜湊快取與 `getTabHash`:基準由使用端對「畫面所見之列」自算,伺服端於鎖內以新鮮讀取重算。
|
|
39
|
+
|
|
40
|
+
### 純函數子模組 `w-serv-orm/src/baseline.mjs`(零 import,前後端同構)
|
|
41
|
+
```alias
|
|
42
|
+
import { digestRow, buildBaseline, compareBaseline, checkContract, isBaselineValid, pickWriteRow, getRejectKey, cyrb53, BASELINE_VERSION, BASELINE_REJECT } from 'w-serv-orm/src/baseline.mjs'
|
|
43
|
+
```
|
|
44
|
+
使用端以深層匯入打包至瀏覽器;檔內只用標準全域、語法限 ES2017 以內,測試於只有標準全域之 `vm` 驗證算出與 Node 相同之摘要。
|
|
45
|
+
|
|
46
|
+
每張表一份**寫入契約**(前後端 import 同一檔):
|
|
47
|
+
```alias
|
|
48
|
+
export default {
|
|
49
|
+
table: 'users',
|
|
50
|
+
pk: 'id',
|
|
51
|
+
fields: ['account', 'name', 'timeBlocked'], //入基準之欄位(白名單)=存檔採用客戶端值之欄位;含後台可改且系統亦會寫之雙方欄位
|
|
52
|
+
serverOnly: ['password'], //伺服器專有欄位:不入基準,存檔不採用客戶端值
|
|
53
|
+
orderKey: 'order', //只限「存檔依列序重編 order」之表;其餘不設
|
|
54
|
+
scope: null, //函式;有則基準只含 scope 回傳真值之列,例 (r) => r.isApp === 'y'
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
`checkContract` 驗證契約:只允許 `table`、`pk`、`fields`、`serverOnly`、`orderKey`、`scope` 六鍵(含不可列舉鍵與 Symbol 鍵,拼錯之鍵拋錯);`pk` 為非空字串;`fields` 為非空、不重複之非空字串陣列;`serverOnly` 與 `fields` 不得有交集;`orderKey` 不得在 `fields` 內亦不得等於 `pk`;`scope` 為函數。三個函數皆先驗證,不合者拋 `Error`,不靜默。
|
|
58
|
+
|
|
59
|
+
| 函數 | 說明 |
|
|
60
|
+
|---|---|
|
|
61
|
+
| `digestRow(row, contract)` | 依 `fields` 之宣告序取值,正規化後序列化取 cyrb53,回 `'h1:' + 14 位 16 進位`。欄位頂層之 `undefined`、`null`、`''`(含缺欄)為同一空值;`Date` 轉 ISO 字串;`BigInt` 轉十進位字串;物件鍵遞迴依碼元序排序,陣列保序;**數字與字串不互轉**(`1` 與 `'1'` 不同);巢狀值只依 JSON 語意(物件鍵之值為 `undefined` 者略去、陣列內 `undefined` 為 `null`、巢狀之 `null` 與 `''` 不等價);其餘非 JSON 值(function、symbol、`NaN`、`±Infinity`、無效 `Date`、`Map`、`Set`、類別實例、帶自有可列舉非索引屬性之陣列如 `toJSON` 等)與深度超過 100、單列節點超過 10 萬者拋 `Error`;列本身須為一般物件。只讀自有屬性。 |
|
|
62
|
+
| `buildBaseline(rows, contract)` | 先依 `scope` 過濾;主鍵(非空字串、有限數字與 `BigInt` 轉字串)缺漏或同批重複拋帶 `key: 'baselineFormat'` 之 `Error`;排序:有 `orderKey` 依(order 數值, 主鍵碼元序),order 之有限數字、`BigInt`、整數字串作精確比較(超過 2^53 不轉 `Number`),缺漏或無法轉數字者排最後;否則依主鍵碼元序,不用 `localeCompare`;回 `[[id, digest], ...]`,**陣列之序即名次**:他人重排會被偵測,系統重編號(名次不變)不會。逐列存檔之基準即只含該列。 |
|
|
63
|
+
| `compareBaseline(rowsNow, baseline, contract)` | 相符回 `{ ok: true }`;不符回 `{ ok: false, reason, added, removed, changed, reordered }`:`reason` 為 `'baselineMismatch'`、`'rowNotFound'`(基準只含一列且該列已不在、無新增列:逐列存檔時該列已被刪)或 `'baselineFormat'`(基準格式或版本不識,未比對);`added`、`removed`、`changed` 為 id 陣列,`reordered` 為布林。不識之格式或版本一律 `baselineFormat`,**不得降級為不帶基準**。`rowsNow` 之主鍵缺漏或重複屬庫內資料異常,拋 `key` 為 `'rowsInvalid'` 之 `Error`(不與客戶端基準格式錯誤之 `baselineFormat` 混為一類,使用端應視為伺服端錯誤)。 |
|
|
64
|
+
| `isBaselineValid(baseline)` | 基準格式是否合法:`[[非空字串 id, 'h1:' 加 14 位小寫 16 進位], ...]`、id 不重複,空陣列合法。 |
|
|
65
|
+
| `pickWriteRow(row, contract)` | 存檔寫入列之白名單:只留 `pk` 與 `fields` 內、列上自有且非 `undefined` 之欄位(新物件);伺服器專有欄位、系統欄位與 `orderKey` 不輸出(`orderKey` 由使用端依列序補)。客戶端持舊列整列送出時,若不經此白名單,系統已改之伺服器專有欄位(如密碼、游標)會被回寫成舊值(規格 V5)。 |
|
|
66
|
+
| `getRejectKey(err)` | 統一取拒收鍵:字串原樣(`procOrm` 之 `'rowNotFound'`)、帶字串 `key` 之 `Error`(`guardWrite`)取其 `key`,其餘(一般例外)回 `null`。 |
|
|
67
|
+
|
|
68
|
+
### `withTabLocks(tableNames, fn)` 與 `guardWrite(...)`(`WServOrm(...)` 回傳物件之方法)
|
|
69
|
+
```alias
|
|
70
|
+
import WServOrm from 'w-serv-orm/src/WServOrm.mjs'
|
|
71
|
+
import { buildBaseline, pickWriteRow } from 'w-serv-orm/src/baseline.mjs'
|
|
72
|
+
import contract from './contractUsers.mjs'
|
|
73
|
+
|
|
74
|
+
let so = WServOrm(ds, WOrm, url, db)
|
|
75
|
+
let { procOrm, woItems, withTabLocks, guardWrite } = so
|
|
76
|
+
|
|
77
|
+
//逐列修改(只改不增): baseline 為前端開啟編輯時以 buildBaseline 對該列自算之 [[id, digest]]
|
|
78
|
+
async function saveUser(userId, row, baseline) {
|
|
79
|
+
return guardWrite({
|
|
80
|
+
tables: ['users'],
|
|
81
|
+
read: () => woItems.users.select({ id: { $in: [row.id] } }), //新鮮讀取, 不經快取;逐列存檔只讀該列
|
|
82
|
+
baseline, //undefined 為不帶基準之寫入(外部應用), 仍取鎖
|
|
83
|
+
contract,
|
|
84
|
+
write: async () => {
|
|
85
|
+
//同一表鎖內: 該列已被刪則 reject 'rowNotFound'(零寫入), 不會復活; 只寫白名單欄位(pk 與 fields), 伺服器專有欄位不回寫舊值
|
|
86
|
+
return procOrm(userId, 'users', 'save', [pickWriteRow(row, contract)], { mustExist: true })
|
|
87
|
+
},
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
//整表存檔: read 讀整表(或 scope 內之列), baseline 為載入時所見之整表;write 內依基準內且在 scope 內之 id 計算刪除集合
|
|
92
|
+
//(不得用「庫內全部 − 送出」,會刪掉他人於載入後新增者),再以 procOrm 之 mix 寫入
|
|
93
|
+
async function saveUsersAll(userId, diff, baseline) {
|
|
94
|
+
return guardWrite({
|
|
95
|
+
tables: ['users'],
|
|
96
|
+
read: () => woItems.users.select({}),
|
|
97
|
+
baseline,
|
|
98
|
+
contract,
|
|
99
|
+
write: async (rowsNow) => procOrm(userId, 'users', 'mix', diff),
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
//外部同步、系統直寫雙方欄位: 不帶基準, 但取同一表鎖
|
|
104
|
+
await withTabLocks(['users'], async () => {
|
|
105
|
+
await procOrm('sync', 'users', 'delAll', {})
|
|
106
|
+
await procOrm('sync', 'users', 'insert', rowsFromExternal)
|
|
107
|
+
})
|
|
108
|
+
```
|
|
109
|
+
* `withTabLocks`:每個實例一個鎖管理器(`wsemi` 之 `pmKeyMutex`),每表一鍵;`tableNames` 為本實例資料表名之非空陣列(拼錯之表名拋 `Error`),去重後依表名碼元序取鎖(多表呼叫之順序固定,不死結);回傳 `fn` 之結果,`fn` 拋錯亦釋放。**不可重入**:`fn` 內不得再對同表呼叫 `withTabLocks` 或 `guardWrite`(排隊等自己,永不返回);**巢狀取不同表亦有死結風險**(每次呼叫內雖依碼元序取鎖,跨層次序不受控:一個呼叫先持 `b` 再等 `a`、另一個先持 `a` 再等 `b` 即互等),故須**一次宣告全部要用之表**(如 `['users', 'tokens']`),不得於 `fn` 內再取其他表之鎖;若必須巢狀,所有呼叫路徑須依同一全域遞增次序。與逐列實體之業務鎖並用時先取表鎖、後取實體鎖。
|
|
110
|
+
* `guardWrite({ tables, read, baseline, contract, write })`:取鎖 → `read()`(須 resolve 陣列) → `compareBaseline` → 不符即 reject → `write(rows)`;比對與寫入在同一表鎖內,其間插不進其他寫入。`baseline` 為 `undefined` 才跳過比對(仍取鎖與讀取);`null` 與其他值皆比對,格式不合即 `baselineFormat`。不符時 reject 一個 `Error`:`message` 與 `key` 皆為固定英文拒收鍵(`baselineMismatch`、`rowNotFound`、`baselineFormat`),另附 `added`、`removed`、`changed`、`reordered`,`write` 不被呼叫。`write` 自身之 reject(如 `procOrm` 之字串)原樣轉出,使用端以 `getRejectKey(err)` 取拒收鍵。`rowsNow`(`read` 之回傳)之主鍵缺漏或重複為庫內資料異常,reject 之 `Error` 其 `key` 為 `'rowsInvalid'`,非 `baselineFormat`。`contract.table` 若有須在 `tables` 內。
|
|
111
|
+
|
|
112
|
+
### `procOrm(userId, woName, mode, input, opt)` 之 `opt.mustExist`(只改不增、刪除回報未命中)
|
|
113
|
+
`opt` 為選用之第 5 參數,既有四參數呼叫之行為不變。目前有兩個布林鍵:`mustExist`(只適用 `save` 與 `del`,本節)與 `keepUserId`(只適用 `insert`,見下一節);用於不適用之 mode、未知鍵、非布林者於任何讀寫之前(含早於擴充函數)以固定字串 reject,如 `invalid opt of procOrm, mustExist supports only save and del`。以下為 `{ mustExist: true }`:
|
|
114
|
+
* `save`:寫入前以 `select({ id: { $in: [...] } })` 分批(每批至多 1000 個主鍵,避開各 `w-orm-*` 共用條件檢核之 `$in` 上限 10000)檢查全部列(含補主鍵後)皆已存在,任一列不存在(含未帶主鍵者)即整批 reject `'rowNotFound'` 且**零寫入**;並轉傳 `autoInsert: false` 給 ORM 之 `save`,已被刪除之列不會復活。
|
|
115
|
+
* `del`:先檢查全部列皆存在,任一列不存在(含無有效主鍵者)即整批零刪除並 reject `'rowNotFound'`;同批重複之主鍵整批 reject `'invalid input of del, duplicate id: data[k]'`(列其位置,零刪除;否則第 1 筆刪除後第 2 筆必未命中)。未帶 `mustExist` 之 `del` 仍回 ORM 之逐筆結果,未命中為 `{ n: 0, nDeleted: 0, ok: 1 }`,不視為錯誤。
|
|
116
|
+
* 檢查之後 ORM 仍回報逐筆未命中者(表鎖紀律被破壞)亦 reject `'rowNotFound'`,已寫入或刪除之筆無從回復。
|
|
117
|
+
* **存在檢查與寫入非原子,須於該表之表鎖內呼叫**(`withTabLocks` 或 `guardWrite` 之 `write` 內);`procOrm` 本身不取鎖。擴充函數(`addFunCheck`、前後處理)之參數物件不含 `opt`。
|
|
118
|
+
* **w-orm-mdb**:其 Jet 比對不分大小寫(且忽略尾端空白),而存在檢查以嚴格字串相等比對,故於 mdb 可能把「ORM 會命中」之列判為不存在而 reject `'rowNotFound'`(零寫入)——這是**收嚴方向**(寧可誤拒、不誤寫),不是放寬;使用端若以 mdb 為後端,主鍵之大小寫與尾端空白須與庫內一致。
|
|
119
|
+
|
|
120
|
+
### `opt.keepUserId`(insert 保留列上之 `userId`,如權杖之擁有者)
|
|
121
|
+
預設 `procOrm` 於 `insert` 把列上之 `userId`(schema 之 keys 含者)一律設為第 1 參數(操作者),`userIdUpdate` 亦同。當 `userId` 之語意是「擁有者」而非「建立者」(例如 w-web-sso 之 `tokens.userId` 為權杖擁有者,而寫入者為代為建立之操作者),以 `{ keepUserId: true }` 保留擁有者,並讓稽核欄位仍記操作者:
|
|
122
|
+
|
|
123
|
+
```js
|
|
124
|
+
//操作者'admin-1'替擁有者'owner-1'建立權杖: 庫內 userId 為 'owner-1',userIdUpdate 為 'admin-1'
|
|
125
|
+
await procOrm('admin-1', 'tokens', 'insert', [{ id: 't1', userId: 'owner-1', name: 'tk' }], { keepUserId: true })
|
|
126
|
+
```
|
|
127
|
+
* 只適用 `insert`;用於 `save`、`del`、`select`、`delAll`、`mix` 或無效 mode 者於任何讀寫之前 reject `invalid opt of procOrm, keepUserId supports only insert`,非布林者 reject `invalid opt of procOrm, keepUserId needs a boolean`,未知鍵(含拼錯,如 `keepuserid`)reject `invalid opt of procOrm, unsupported key`,皆零讀寫、擴充函數(check、前處理)亦 0 次呼叫。`{ keepUserId: false }` 於各 mode 無效果,等同未給。
|
|
128
|
+
* **逐列判定**:該列自有、可列舉之資料屬性 `userId` 為**非空字串**者保留(單純空白字串亦屬非空字串);缺欄、空字串、`null`、`undefined`、非字串、繼承而來或不可列舉者視為未提供,照現行以操作者補。保留之值與其他字串欄位同,仍經 `clearXSS` 清除。
|
|
129
|
+
* `userIdUpdate`、`timeCreate`、`timeUpdate` 照現行(`userIdUpdate` 恆為操作者;呼叫端給之值皆被覆寫)。schema 之 keys 不含 `userId` 之表,`keepUserId` 無效果。判定之依據是前處理(`addFunPreProcessing`)改寫後、進入 ORM 之列。
|
|
130
|
+
* `save` 現行即不覆寫列上之 `userId`(只補 `userIdUpdate`、`timeUpdate`),擁有者語意之欄不被操作者覆寫,故 `save` 不需此選項;`mix` 之新增為內部步驟,不開放。
|
|
131
|
+
* 兩鍵可同物件給予,惟 `mustExist: true`(限 `save`、`del`)與 `keepUserId: true`(限 `insert`)無任何 mode 可同時為真:於 `insert` 以 `mustExist` 之句 reject,於 `save`、`del` 以 `keepUserId` 之句 reject;型別檢查先於 mode 檢查。
|
|
132
|
+
|
|
133
|
+
### 使用端之職責(本核心不代為處理)
|
|
134
|
+
* **所有寫入者取同一把表鎖**:後台存檔、逐列寫入、外部同步、系統直寫雙方欄位皆經同一實例之 `withTabLocks`/`guardWrite`;未取鎖之寫入者可插入比對與寫入之間。
|
|
135
|
+
* **寫入列只含白名單欄位**:用 `pickWriteRow`(或等效),伺服器專有欄位與系統欄位不入寫入列。
|
|
136
|
+
* **整表存檔之刪除集合**=基準內且在 `scope` 內之 id − 送出之 id;**不得**以「庫內全部 − 送出」(會刪掉他人於載入後新增者)。
|
|
137
|
+
* **外部同步沿用穩定 id**(依明確且唯一之來源識別),內容不變則摘要不變;`withTabLocks` 只保證互斥。
|
|
138
|
+
* **前端**:以 `buildBaseline` 對畫面所見之同一快照自算基準;草稿保護(推播時不重建、凍結基準)屬前端;基準經實際傳輸路徑(資料通道或 RPC)後須仍等於伺服端新鮮讀取所算(型別漂移,如數字被傳成字串,會使摘要不同),各使用端須以其實際傳輸路徑驗證。
|
|
139
|
+
* **同表只由同一 ORM 實例寫入、`read` 不經快取、單一行程**(部署前提)。
|
|
140
|
+
|
|
22
141
|
## Installation
|
|
23
142
|
|
|
24
143
|
### Using npm(ES6 module):
|
package/dist/w-serv-orm.umd.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* w-serv-orm v1.1.
|
|
2
|
+
* w-serv-orm v1.1.17
|
|
3
3
|
* (c) 2018-2021 yuda-lyu(semisphere)
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("fs"),require("util")):"function"==typeof define&&define.amd?define(["fs","util"],e):(t="undefined"!=typeof globalThis?globalThis:t||self)["w-serv-orm"]=e(t.fs,t.util$2)}(this,(function(t,e){"use strict";function r(t,e,r){var n=-1,o=t.length;e<0&&(e=-e>o?0:o+e),(r=r>o?o:r)<0&&(r+=o),o=e>r?0:r-e>>>0,e>>>=0;for(var i=Array(o);++n<o;)i[n]=t[n+e];return i}var n=/\s/;var o=/^\s+/;function i(t){return t?t.slice(0,function(t){for(var e=t.length;e--&&n.test(t.charAt(e)););return e}(t)+1).replace(o,""):t}function a(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}var u="object"==typeof global&&global&&global.Object===Object&&global,s="object"==typeof self&&self&&self.Object===Object&&self,c=u||s||Function("return this")(),l=c.Symbol,f=Object.prototype,d=f.hasOwnProperty,p=f.toString,h=l?l.toStringTag:void 0;var g=Object.prototype.toString;var v="[object Null]",b="[object Undefined]",y=l?l.toStringTag:void 0;function m(t){return null==t?void 0===t?b:v:y&&y in Object(t)?function(t){var e=d.call(t,h),r=t[h];try{t[h]=void 0;var n=!0}catch(t){}var o=p.call(t);return n&&(e?t[h]=r:delete t[h]),o}(t):function(t){return g.call(t)}(t)}function w(t){return null!=t&&"object"==typeof t}var j="[object Symbol]";function O(t){return"symbol"==typeof t||w(t)&&m(t)==j}var $=NaN,x=/^[-+]0x[0-9a-f]+$/i,_=/^0b[01]+$/i,S=/^0o[0-7]+$/i,A=parseInt;var k=1/0,P=17976931348623157e292;function I(t){return t?(t=function(t){if("number"==typeof t)return t;if(O(t))return $;if(a(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=a(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=i(t);var r=_.test(t);return r||S.test(t)?A(t.slice(2),r?2:8):x.test(t)?$:+t}(t))===k||t===-k?(t<0?-1:1)*P:t==t?t:0:0===t?t:0}function D(t){var e=I(t),r=e%1;return e==e?r?e-r:e:0}function T(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););return t}var M,E=function(t,e,r){for(var n=-1,o=Object(t),i=r(t),a=i.length;a--;){var u=i[M?a:++n];if(!1===e(o[u],u,o))break}return t};function C(t){return w(t)&&"[object Arguments]"==m(t)}var z=Object.prototype,F=z.hasOwnProperty,L=z.propertyIsEnumerable,U=C(function(){return arguments}())?C:function(t){return w(t)&&F.call(t,"callee")&&!L.call(t,"callee")},R=U,W=Array.isArray;var N="object"==typeof exports&&exports&&!exports.nodeType&&exports,B=N&&"object"==typeof module&&module&&!module.nodeType&&module,V=B&&B.exports===N?c.Buffer:void 0,H=(V?V.isBuffer:void 0)||function(){return!1},Y=9007199254740991,q=/^(?:0|[1-9]\d*)$/;function X(t,e){var r=typeof t;return!!(e=null==e?Y:e)&&("number"==r||"symbol"!=r&&q.test(t))&&t>-1&&t%1==0&&t<e}var K=9007199254740991;function Z(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=K}var G={};function J(t){return function(e){return t(e)}}G["[object Float32Array]"]=G["[object Float64Array]"]=G["[object Int8Array]"]=G["[object Int16Array]"]=G["[object Int32Array]"]=G["[object Uint8Array]"]=G["[object Uint8ClampedArray]"]=G["[object Uint16Array]"]=G["[object Uint32Array]"]=!0,G["[object Arguments]"]=G["[object Array]"]=G["[object ArrayBuffer]"]=G["[object Boolean]"]=G["[object DataView]"]=G["[object Date]"]=G["[object Error]"]=G["[object Function]"]=G["[object Map]"]=G["[object Number]"]=G["[object Object]"]=G["[object RegExp]"]=G["[object Set]"]=G["[object String]"]=G["[object WeakMap]"]=!1;var Q="object"==typeof exports&&exports&&!exports.nodeType&&exports,tt=Q&&"object"==typeof module&&module&&!module.nodeType&&module,et=tt&&tt.exports===Q&&u.process,rt=function(){try{var t=tt&&tt.require&&tt.require("util").types;return t||et&&et.binding&&et.binding("util")}catch(t){}}(),nt=rt&&rt.isTypedArray,ot=nt?J(nt):function(t){return w(t)&&Z(t.length)&&!!G[m(t)]},it=Object.prototype.hasOwnProperty;function at(t,e){var r=W(t),n=!r&&R(t),o=!r&&!n&&H(t),i=!r&&!n&&!o&&ot(t),a=r||n||o||i,u=a?function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}(t.length,String):[],s=u.length;for(var c in t)!e&&!it.call(t,c)||a&&("length"==c||o&&("offset"==c||"parent"==c)||i&&("buffer"==c||"byteLength"==c||"byteOffset"==c)||X(c,s))||u.push(c);return u}var ut=Object.prototype;function st(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||ut)}function ct(t,e){return function(r){return t(e(r))}}var lt=ct(Object.keys,Object),ft=Object.prototype.hasOwnProperty;function dt(t){if(!st(t))return lt(t);var e=[];for(var r in Object(t))ft.call(t,r)&&"constructor"!=r&&e.push(r);return e}var pt="[object AsyncFunction]",ht="[object Function]",gt="[object GeneratorFunction]",vt="[object Proxy]";function bt(t){if(!a(t))return!1;var e=m(t);return e==ht||e==gt||e==pt||e==vt}function yt(t){return null!=t&&Z(t.length)&&!bt(t)}function mt(t){return yt(t)?at(t):dt(t)}var wt=function(t,e){return function(r,n){if(null==r)return r;if(!yt(r))return t(r,n);for(var o=r.length,i=e?o:-1,a=Object(r);(e?i--:++i<o)&&!1!==n(a[i],i,a););return r}}((function(t,e){return t&&E(t,e,mt)})),jt=wt;function Ot(t){return t}function $t(t,e){var r;return(W(t)?T:jt)(t,"function"==typeof(r=e)?r:Ot)}function xt(t){return bt(t)}function _t(t){try{t instanceof Promise&&Promise.prototype.then.call(t,void 0,(()=>{}))}catch(t){}}function St(t){return"[object Array]"===Object.prototype.toString.call(t)}function At(t){return"[object Object]"===Object.prototype.toString.call(t)}function kt(t,e){let n=function(){let t,e,r=new Promise((function(){t=arguments[0],e=arguments[1]}));return r.resolve=t,r.reject=e,r}(),o=!1;try{let e=function(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=[],n=!1;try{if(Array.isArray(t)){let e=t.length;r.length=e;for(let n=0;n<e;n++)n in t&&(r[n]=t[n])}else{if(e||!At(t)&&!St(t))return null;{n=!0;let e=Object.keys(t);for(let n=0;n<e.length;n++)r.push({k:e[n],v:t[e[n]]})}}}catch(t){throw r.forEach((t=>{_t(n?t.v:t)})),t}return{items:r,useObj:n}}(t);if(null===e)return n.reject("rs is not an array or object"),n;t=e.items,o=e.useObj}catch(t){return n.reject(t),n}xt(e)||($t(t,(t=>{_t(o?t.v:t)})),e=function(t){return t});let i=xt(e),a=-1,u=[];return t.reduce((function(t,r){return t.then((function(t){u.push(t),a+=1;let n=a,s=r;return o&&(n=r.k,s=r.v),i?e(s,n):s}))}),Promise.resolve()).then((function(t){var e,o,i,a;u.push(t),a=null==(e=u)?0:e.length,u=a?r(e,(o=i||void 0===o?1:D(o))<0?0:o,a):[],n.resolve(u)})).catch((function(t){n.reject(t)})),n}var Pt=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,It=/^\w*$/;function Dt(t,e){if(W(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!O(t))||(It.test(t)||!Pt.test(t)||null!=e&&t in Object(e))}var Tt,Mt=c["__core-js_shared__"],Et=(Tt=/[^.]+$/.exec(Mt&&Mt.keys&&Mt.keys.IE_PROTO||""))?"Symbol(src)_1."+Tt:"";var Ct=Function.prototype.toString;function zt(t){if(null!=t){try{return Ct.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var Ft=/^\[object .+?Constructor\]$/,Lt=Function.prototype,Ut=Object.prototype,Rt=Lt.toString,Wt=Ut.hasOwnProperty,Nt=RegExp("^"+Rt.call(Wt).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Bt(t){return!(!a(t)||(e=t,Et&&Et in e))&&(bt(t)?Nt:Ft).test(zt(t));var e}function Vt(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return Bt(r)?r:void 0}var Ht=Vt(Object,"create");var Yt=Object.prototype.hasOwnProperty;var qt=Object.prototype.hasOwnProperty;function Xt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function Kt(t,e){return t===e||t!=t&&e!=e}function Zt(t,e){for(var r=t.length;r--;)if(Kt(t[r][0],e))return r;return-1}Xt.prototype.clear=function(){this.__data__=Ht?Ht(null):{},this.size=0},Xt.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Xt.prototype.get=function(t){var e=this.__data__;if(Ht){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return Yt.call(e,t)?e[t]:void 0},Xt.prototype.has=function(t){var e=this.__data__;return Ht?void 0!==e[t]:qt.call(e,t)},Xt.prototype.set=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=Ht&&void 0===e?"__lodash_hash_undefined__":e,this};var Gt=Array.prototype.splice;function Jt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Jt.prototype.clear=function(){this.__data__=[],this.size=0},Jt.prototype.delete=function(t){var e=this.__data__,r=Zt(e,t);return!(r<0)&&(r==e.length-1?e.pop():Gt.call(e,r,1),--this.size,!0)},Jt.prototype.get=function(t){var e=this.__data__,r=Zt(e,t);return r<0?void 0:e[r][1]},Jt.prototype.has=function(t){return Zt(this.__data__,t)>-1},Jt.prototype.set=function(t,e){var r=this.__data__,n=Zt(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var Qt=Vt(c,"Map");function te(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function ee(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}ee.prototype.clear=function(){this.size=0,this.__data__={hash:new Xt,map:new(Qt||Jt),string:new Xt}},ee.prototype.delete=function(t){var e=te(this,t).delete(t);return this.size-=e?1:0,e},ee.prototype.get=function(t){return te(this,t).get(t)},ee.prototype.has=function(t){return te(this,t).has(t)},ee.prototype.set=function(t,e){var r=te(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};var re="Expected a function";function ne(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError(re);var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],i=r.cache;if(i.has(o))return i.get(o);var a=t.apply(this,n);return r.cache=i.set(o,a)||i,a};return r.cache=new(ne.Cache||ee),r}ne.Cache=ee;var oe,ie,ae,ue=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,se=/\\(\\)?/g,ce=(oe=function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(ue,(function(t,r,n,o){e.push(n?o.replace(se,"$1"):r||t)})),e},ie=ne(oe,(function(t){return 500===ae.size&&ae.clear(),t})),ae=ie.cache,ie),le=ce;function fe(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o}var de=1/0,pe=l?l.prototype:void 0,he=pe?pe.toString:void 0;function ge(t){if("string"==typeof t)return t;if(W(t))return fe(t,ge)+"";if(O(t))return he?he.call(t):"";var e=t+"";return"0"==e&&1/t==-de?"-0":e}function ve(t){return null==t?"":ge(t)}function be(t,e){return W(t)?t:Dt(t,e)?[t]:le(ve(t))}var ye=1/0;function me(t){if("string"==typeof t||O(t))return t;var e=t+"";return"0"==e&&1/t==-ye?"-0":e}function we(t,e){for(var r=0,n=(e=be(e,t)).length;null!=t&&r<n;)t=t[me(e[r++])];return r&&r==n?t:void 0}function je(t,e,r){var n=null==t?void 0:we(t,e);return void 0===n?r:n}function Oe(t){let e="procOrm does not authorize users, authorize where procOrm is exposed to clients",r=[["useCheckUser",e],["getUserById",e],["useExcludeWhenNotAdmin","procOrm does not filter select results by user, use addFunPostProcessing if needed"]];for(let[e,n]of r){let r=je(t,e);if(null!=r&&!1!==r)throw new Error(`opt.${e} has been removed, ${n}`)}}function $e(t,e,n){var o=t.length;return n=void 0===n?o:n,!e&&n>=o?t:r(t,e,n)}function xe(t){return t!=t}function _e(t,e,r){return e==e?function(t,e,r){for(var n=r-1,o=t.length;++n<o;)if(t[n]===e)return n;return-1}(t,e,r):function(t,e,r,n){for(var o=t.length,i=r+(n?1:-1);n?i--:++i<o;)if(e(t[i],i,t))return i;return-1}(t,xe,r)}var Se=RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]");function Ae(t){return Se.test(t)}var ke="\\ud800-\\udfff",Pe="["+ke+"]",Ie="[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]",De="\\ud83c[\\udffb-\\udfff]",Te="[^"+ke+"]",Me="(?:\\ud83c[\\udde6-\\uddff]){2}",Ee="[\\ud800-\\udbff][\\udc00-\\udfff]",Ce="(?:"+Ie+"|"+De+")"+"?",ze="[\\ufe0e\\ufe0f]?",Fe=ze+Ce+("(?:\\u200d(?:"+[Te,Me,Ee].join("|")+")"+ze+Ce+")*"),Le="(?:"+[Te+Ie+"?",Ie,Me,Ee,Pe].join("|")+")",Ue=RegExp(De+"(?="+De+")|"+Le+Fe,"g");function Re(t){return Ae(t)?function(t){return t.match(Ue)||[]}(t):function(t){return t.split("")}(t)}function We(t,e,r){if((t=ve(t))&&(r||void 0===e))return i(t);if(!t||!(e=ge(e)))return t;var n=Re(t),o=Re(e),a=function(t,e){for(var r=-1,n=t.length;++r<n&&_e(e,t[r],0)>-1;);return r}(n,o),u=function(t,e){for(var r=t.length;r--&&_e(e,t[r],0)>-1;);return r}(n,o)+1;return $e(n,a,u).join("")}var Ne=Vt(c,"DataView"),Be=Vt(c,"Promise"),Ve=Vt(c,"Set"),He=Vt(c,"WeakMap"),Ye="[object Map]",qe="[object Promise]",Xe="[object Set]",Ke="[object WeakMap]",Ze="[object DataView]",Ge=zt(Ne),Je=zt(Qt),Qe=zt(Be),tr=zt(Ve),er=zt(He),rr=m;(Ne&&rr(new Ne(new ArrayBuffer(1)))!=Ze||Qt&&rr(new Qt)!=Ye||Be&&rr(Be.resolve())!=qe||Ve&&rr(new Ve)!=Xe||He&&rr(new He)!=Ke)&&(rr=function(t){var e=m(t),r="[object Object]"==e?t.constructor:void 0,n=r?zt(r):"";if(n)switch(n){case Ge:return Ze;case Je:return Ye;case Qe:return qe;case tr:return Xe;case er:return Ke}return e});var nr=rr,or="[object String]";function ir(t){return function(e){return null==e?void 0:e[t]}}var ar=ir("length"),ur="\\ud800-\\udfff",sr="["+ur+"]",cr="[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]",lr="\\ud83c[\\udffb-\\udfff]",fr="[^"+ur+"]",dr="(?:\\ud83c[\\udde6-\\uddff]){2}",pr="[\\ud800-\\udbff][\\udc00-\\udfff]",hr="(?:"+cr+"|"+lr+")"+"?",gr="[\\ufe0e\\ufe0f]?",vr=gr+hr+("(?:\\u200d(?:"+[fr,dr,pr].join("|")+")"+gr+hr+")*"),br="(?:"+[fr+cr+"?",cr,dr,pr,sr].join("|")+")",yr=RegExp(lr+"(?="+lr+")|"+br+vr,"g");function mr(t){return Ae(t)?function(t){for(var e=yr.lastIndex=0;yr.test(t);)++e;return e}(t):ar(t)}var wr="[object Map]",jr="[object Set]";function Or(t){if(null==t)return 0;if(yt(t))return"string"==typeof(e=t)||!W(e)&&w(e)&&m(e)==or?mr(t):t.length;var e,r=nr(t);return r==wr||r==jr?t.size:dt(t).length}function $r(t){let e=je(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},"fs");return!!function(t){let e=je(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},"fs"),r=!1;try{e.statSync(t),r=!0}catch{r=!1}return r}(t,{fs:e})&&(!e.lstatSync(t).isDirectory()&&!e.lstatSync(t).isSymbolicLink())}function xr(t){if(At(t)){for(let e in t)return!0;return!1}return!1}function _r(t){return"[object String]"===Object.prototype.toString.call(t)}function Sr(t){if(t!=t)return!0;if(null!==t&&"object"==typeof t)try{let e=Number.prototype.valueOf.call(t);return Number.isNaN(e)}catch(t){return!1}return!1}function Ar(t){return!!function(t){return"[object Undefined]"===Object.prototype.toString.call(t)}(t)||(!!function(t){return"[object Null]"===Object.prototype.toString.call(t)}(t)||(!!function(t){if(At(t)){for(let e in t)return!1;return!0}return!1}(t)||(!!function(t){return!(!_r(t)||0!==t.length)}(t)||(!!function(t){return!!St(t)&&0===t.length}(t)||!!Sr(t)))))}function kr(t){return!!St(t)&&(0!==t.length&&(1!==t.length||!Ar(t[0])))}function Pr(t){return!!(_r(t)&&t.length>0)}var Ir="[object Boolean]";function Dr(t){return!0===(e=t)||!1===e||w(e)&&m(e)==Ir;var e}let Tr={backup:async function(t){if(!xr(t))throw console.log("woItems",t),new Error("invalid woItems");return await kt(t,(async(t,e)=>(console.log("backup...",e),{name:e,data:await t.select()})))},recover:async function(e,r,n){let o=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(!$r(e,{fs:t}))throw console.log("fp",e),new Error("fp is not exist");if(!xr(r))throw console.log("woItems",r),new Error("invalid woItems");xt(n)||(n=null),Dr(o)||(o=!1);let i=t.readFileSync(e,"utf8");i=We(i);let a=function(t){let e=je(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},"returnWithStateAndMsg",null);Dr(e)||(e=!1);let r=t=>e?{state:"error",msg:t}:{};if(!Pr(t))return r("invalid v");let n={};try{n=JSON.parse(t)}catch(t){return r(t.toString())}return e?{state:"success",msg:n}:n}(i);if(!kr(a))throw new Error("invalid backup data, need a non-empty array");$t(a,((t,e)=>{let n=je(t,"name");if(!Pr(n))throw new Error(`invalid backup data, rs[${e}].name is not a string`);if(!Object.prototype.hasOwnProperty.call(r,n))throw new Error(`invalid backup data, table[${n}] is not in woItems`)})),xt(n)&&n(),await kt(a,(async t=>{console.log("recover...",t.name),o&&(console.log("needCreateStorage"),await r[t.name].createStorage());let e=null;return Or(t.data)>0&&(e=await r[t.name].insert(t.data)),e}))}};function Mr(t){var e=this.__data__=new Jt(t);this.size=e.size}Mr.prototype.clear=function(){this.__data__=new Jt,this.size=0},Mr.prototype.delete=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},Mr.prototype.get=function(t){return this.__data__.get(t)},Mr.prototype.has=function(t){return this.__data__.has(t)},Mr.prototype.set=function(t,e){var r=this.__data__;if(r instanceof Jt){var n=r.__data__;if(!Qt||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new ee(n)}return r.set(t,e),this.size=r.size,this};function Er(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new ee;++e<r;)this.add(t[e])}function Cr(t,e){for(var r=-1,n=null==t?0:t.length;++r<n;)if(e(t[r],r,t))return!0;return!1}function zr(t,e){return t.has(e)}Er.prototype.add=Er.prototype.push=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},Er.prototype.has=function(t){return this.__data__.has(t)};var Fr=1,Lr=2;function Ur(t,e,r,n,o,i){var a=r&Fr,u=t.length,s=e.length;if(u!=s&&!(a&&s>u))return!1;var c=i.get(t),l=i.get(e);if(c&&l)return c==e&&l==t;var f=-1,d=!0,p=r&Lr?new Er:void 0;for(i.set(t,e),i.set(e,t);++f<u;){var h=t[f],g=e[f];if(n)var v=a?n(g,h,f,e,t,i):n(h,g,f,t,e,i);if(void 0!==v){if(v)continue;d=!1;break}if(p){if(!Cr(e,(function(t,e){if(!zr(p,e)&&(h===t||o(h,t,r,n,i)))return p.push(e)}))){d=!1;break}}else if(h!==g&&!o(h,g,r,n,i)){d=!1;break}}return i.delete(t),i.delete(e),d}var Rr=c.Uint8Array;function Wr(t){var e=-1,r=Array(t.size);return t.forEach((function(t,n){r[++e]=[n,t]})),r}function Nr(t){var e=-1,r=Array(t.size);return t.forEach((function(t){r[++e]=t})),r}var Br=1,Vr=2,Hr="[object Boolean]",Yr="[object Date]",qr="[object Error]",Xr="[object Map]",Kr="[object Number]",Zr="[object RegExp]",Gr="[object Set]",Jr="[object String]",Qr="[object Symbol]",tn="[object ArrayBuffer]",en="[object DataView]",rn=l?l.prototype:void 0,nn=rn?rn.valueOf:void 0;function on(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t}function an(t,e,r){var n=e(t);return W(t)?n:on(n,r(t))}function un(){return[]}var sn=Object.prototype.propertyIsEnumerable,cn=Object.getOwnPropertySymbols,ln=cn?function(t){return null==t?[]:(t=Object(t),function(t,e){for(var r=-1,n=null==t?0:t.length,o=0,i=[];++r<n;){var a=t[r];e(a,r,t)&&(i[o++]=a)}return i}(cn(t),(function(e){return sn.call(t,e)})))}:un,fn=ln;function dn(t){return an(t,mt,fn)}var pn=1,hn=Object.prototype.hasOwnProperty;var gn=1,vn="[object Arguments]",bn="[object Array]",yn="[object Object]",mn=Object.prototype.hasOwnProperty;function wn(t,e,r,n,o,i){var a=W(t),u=W(e),s=a?bn:nr(t),c=u?bn:nr(e),l=(s=s==vn?yn:s)==yn,f=(c=c==vn?yn:c)==yn,d=s==c;if(d&&H(t)){if(!H(e))return!1;a=!0,l=!1}if(d&&!l)return i||(i=new Mr),a||ot(t)?Ur(t,e,r,n,o,i):function(t,e,r,n,o,i,a){switch(r){case en:if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case tn:return!(t.byteLength!=e.byteLength||!i(new Rr(t),new Rr(e)));case Hr:case Yr:case Kr:return Kt(+t,+e);case qr:return t.name==e.name&&t.message==e.message;case Zr:case Jr:return t==e+"";case Xr:var u=Wr;case Gr:var s=n&Br;if(u||(u=Nr),t.size!=e.size&&!s)return!1;var c=a.get(t);if(c)return c==e;n|=Vr,a.set(t,e);var l=Ur(u(t),u(e),n,o,i,a);return a.delete(t),l;case Qr:if(nn)return nn.call(t)==nn.call(e)}return!1}(t,e,s,r,n,o,i);if(!(r&gn)){var p=l&&mn.call(t,"__wrapped__"),h=f&&mn.call(e,"__wrapped__");if(p||h){var g=p?t.value():t,v=h?e.value():e;return i||(i=new Mr),o(g,v,r,n,i)}}return!!d&&(i||(i=new Mr),function(t,e,r,n,o,i){var a=r&pn,u=dn(t),s=u.length;if(s!=dn(e).length&&!a)return!1;for(var c=s;c--;){var l=u[c];if(!(a?l in e:hn.call(e,l)))return!1}var f=i.get(t),d=i.get(e);if(f&&d)return f==e&&d==t;var p=!0;i.set(t,e),i.set(e,t);for(var h=a;++c<s;){var g=t[l=u[c]],v=e[l];if(n)var b=a?n(v,g,l,e,t,i):n(g,v,l,t,e,i);if(!(void 0===b?g===v||o(g,v,r,n,i):b)){p=!1;break}h||(h="constructor"==l)}if(p&&!h){var y=t.constructor,m=e.constructor;y==m||!("constructor"in t)||!("constructor"in e)||"function"==typeof y&&y instanceof y&&"function"==typeof m&&m instanceof m||(p=!1)}return i.delete(t),i.delete(e),p}(t,e,r,n,o,i))}function jn(t,e,r,n,o){return t===e||(null==t||null==e||!w(t)&&!w(e)?t!=t&&e!=e:wn(t,e,r,n,jn,o))}var On=1,$n=2;function xn(t){return t==t&&!a(t)}function _n(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}}function Sn(t){var e=function(t){for(var e=mt(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,xn(o)]}return e}(t);return 1==e.length&&e[0][2]?_n(e[0][0],e[0][1]):function(r){return r===t||function(t,e,r,n){var o=r.length,i=o,a=!n;if(null==t)return!i;for(t=Object(t);o--;){var u=r[o];if(a&&u[2]?u[1]!==t[u[0]]:!(u[0]in t))return!1}for(;++o<i;){var s=(u=r[o])[0],c=t[s],l=u[1];if(a&&u[2]){if(void 0===c&&!(s in t))return!1}else{var f=new Mr;if(n)var d=n(c,l,s,t,e,f);if(!(void 0===d?jn(l,c,On|$n,n,f):d))return!1}}return!0}(r,t,e)}}function An(t,e){return null!=t&&e in Object(t)}function kn(t,e){return null!=t&&function(t,e,r){for(var n=-1,o=(e=be(e,t)).length,i=!1;++n<o;){var a=me(e[n]);if(!(i=null!=t&&r(t,a)))break;t=t[a]}return i||++n!=o?i:!!(o=null==t?0:t.length)&&Z(o)&&X(a,o)&&(W(t)||R(t))}(t,e,An)}var Pn=1,In=2;function Dn(t){return Dt(t)?ir(me(t)):function(t){return function(e){return we(e,t)}}(t)}function Tn(t){return"function"==typeof t?t:null==t?Ot:"object"==typeof t?W(t)?(e=t[0],r=t[1],Dt(e)&&xn(r)?_n(me(e),r):function(t){var n=je(t,e);return void 0===n&&n===r?kn(t,e):jn(r,n,Pn|In)}):Sn(t):Dn(t);var e,r}function Mn(t,e){var r=-1,n=yt(t)?Array(t.length):[];return jt(t,(function(t,o,i){n[++r]=e(t,o,i)})),n}function En(t,e){return(W(t)?fe:Mn)(t,Tn(e))}var Cn=Array.prototype.join;function zn(t,e){return null==t?"":Cn.call(t,e)}var Fn=rt&&rt.isRegExp,Ln=Fn?J(Fn):function(t){return w(t)&&"[object RegExp]"==m(t)},Un=30,Rn="...",Wn=/\w*$/;function Nn(t,e){var r=Un,n=Rn;if(a(e)){var o="separator"in e?e.separator:o;r="length"in e?D(e.length):r,n="omission"in e?ge(e.omission):n}var i=(t=ve(t)).length;if(Ae(t)){var u=Re(t);i=u.length}if(r>=i)return t;var s=r-mr(n);if(s<1)return n;var c=u?$e(u,0,s).join(""):t.slice(0,s);if(void 0===o)return c+n;if(u&&(s+=c.length-s),Ln(o)){if(t.slice(s).search(o)){var l,f=c;for(o.global||(o=RegExp(o.source,ve(Wn.exec(o))+"g")),o.lastIndex=0;l=o.exec(f);)var d=l.index;c=c.slice(0,void 0===d?s:d)}}else if(t.indexOf(ge(o),s)!=s){var p=c.lastIndexOf(o);p>-1&&(c=c.slice(0,p))}return c+n}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var Bn={};!function(t,e){t.exports=function(){var t=1e3,e=6e4,r=36e5,n="millisecond",o="second",i="minute",a="hour",u="day",s="week",c="month",l="quarter",f="year",d="date",p="Invalid Date",h=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,g=/\[([^\]]+)]|YYYY|YY|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,v={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(t){var e=["th","st","nd","rd"],r=t%100;return"["+t+(e[(r-20)%10]||e[r]||e[0])+"]"}},b=function(t,e,r){var n=String(t);return!n||n.length>=e?t:""+Array(e+1-n.length).join(r)+t},y={s:b,z:function(t){var e=-t.utcOffset(),r=Math.abs(e),n=Math.floor(r/60),o=r%60;return(e<=0?"+":"-")+b(n,2,"0")+":"+b(o,2,"0")},m:function t(e,r){if(e.date()<r.date())return-t(r,e);var n=12*(r.year()-e.year())+(r.month()-e.month()),o=e.clone().add(n,c),i=r-o<0,a=e.clone().add(n+(i?-1:1),c);return+(-(n+(r-o)/(i?o-a:a-o))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return{M:c,y:f,w:s,d:u,D:d,h:a,m:i,s:o,ms:n,Q:l}[t]||String(t||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},m="en",w={};w[m]=v;var j="$isDayjsObject",O=function(t){return t instanceof S||!(!t||!t[j])},$=function t(e,r,n){var o;if(!e)return m;if("string"==typeof e){var i=e.toLowerCase();w[i]&&(o=i),r&&(w[i]=r,o=i);var a=e.split("-");if(!o&&a.length>1)return t(a[0])}else{var u=e.name;w[u]=e,o=u}return!n&&o&&(m=o),o||!n&&m},x=function(t,e){if(O(t))return t.clone();var r="object"==typeof e?e:{};return r.date=t,r.args=arguments,new S(r)},_=y;_.l=$,_.i=O,_.w=function(t,e){return x(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var S=function(){function v(t){this.$L=$(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[j]=!0}var b=v.prototype;return b.parse=function(t){this.$d=function(t){var e=t.date,r=t.utc;if(null===e)return new Date(NaN);if(_.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var n=e.match(h);if(n){var o=n[2]-1||0,i=(n[7]||"0").substring(0,3);return r?new Date(Date.UTC(n[1],o,n[3]||1,n[4]||0,n[5]||0,n[6]||0,i)):new Date(n[1],o,n[3]||1,n[4]||0,n[5]||0,n[6]||0,i)}}return new Date(e)}(t),this.init()},b.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds()},b.$utils=function(){return _},b.isValid=function(){return!(this.$d.toString()===p)},b.isSame=function(t,e){var r=x(t);return this.startOf(e)<=r&&r<=this.endOf(e)},b.isAfter=function(t,e){return x(t)<this.startOf(e)},b.isBefore=function(t,e){return this.endOf(e)<x(t)},b.$g=function(t,e,r){return _.u(t)?this[e]:this.set(r,t)},b.unix=function(){return Math.floor(this.valueOf()/1e3)},b.valueOf=function(){return this.$d.getTime()},b.startOf=function(t,e){var r=this,n=!!_.u(e)||e,l=_.p(t),p=function(t,e){var o=_.w(r.$u?Date.UTC(r.$y,e,t):new Date(r.$y,e,t),r);return n?o:o.endOf(u)},h=function(t,e){return _.w(r.toDate()[t].apply(r.toDate("s"),(n?[0,0,0,0]:[23,59,59,999]).slice(e)),r)},g=this.$W,v=this.$M,b=this.$D,y="set"+(this.$u?"UTC":"");switch(l){case f:return n?p(1,0):p(31,11);case c:return n?p(1,v):p(0,v+1);case s:var m=this.$locale().weekStart||0,w=(g<m?g+7:g)-m;return p(n?b-w:b+(6-w),v);case u:case d:return h(y+"Hours",0);case a:return h(y+"Minutes",1);case i:return h(y+"Seconds",2);case o:return h(y+"Milliseconds",3);default:return this.clone()}},b.endOf=function(t){return this.startOf(t,!1)},b.$set=function(t,e){var r,s=_.p(t),l="set"+(this.$u?"UTC":""),p=(r={},r[u]=l+"Date",r[d]=l+"Date",r[c]=l+"Month",r[f]=l+"FullYear",r[a]=l+"Hours",r[i]=l+"Minutes",r[o]=l+"Seconds",r[n]=l+"Milliseconds",r)[s],h=s===u?this.$D+(e-this.$W):e;if(s===c||s===f){var g=this.clone().set(d,1);g.$d[p](h),g.init(),this.$d=g.set(d,Math.min(this.$D,g.daysInMonth())).$d}else p&&this.$d[p](h);return this.init(),this},b.set=function(t,e){return this.clone().$set(t,e)},b.get=function(t){return this[_.p(t)]()},b.add=function(n,l){var d,p=this;n=Number(n);var h=_.p(l),g=function(t){var e=x(p);return _.w(e.date(e.date()+Math.round(t*n)),p)};if(h===c)return this.set(c,this.$M+n);if(h===f)return this.set(f,this.$y+n);if(h===u)return g(1);if(h===s)return g(7);var v=(d={},d[i]=e,d[a]=r,d[o]=t,d)[h]||1,b=this.$d.getTime()+n*v;return _.w(b,this)},b.subtract=function(t,e){return this.add(-1*t,e)},b.format=function(t){var e=this,r=this.$locale();if(!this.isValid())return r.invalidDate||p;var n=t||"YYYY-MM-DDTHH:mm:ssZ",o=_.z(this),i=this.$H,a=this.$m,u=this.$M,s=r.weekdays,c=r.months,l=r.meridiem,f=function(t,r,o,i){return t&&(t[r]||t(e,n))||o[r].slice(0,i)},d=function(t){return _.s(i%12||12,t,"0")},h=l||function(t,e,r){var n=t<12?"AM":"PM";return r?n.toLowerCase():n};return n.replace(g,(function(t,n){return n||function(t){switch(t){case"YY":return String(e.$y).slice(-2);case"YYYY":return _.s(e.$y,4,"0");case"M":return u+1;case"MM":return _.s(u+1,2,"0");case"MMM":return f(r.monthsShort,u,c,3);case"MMMM":return f(c,u);case"D":return e.$D;case"DD":return _.s(e.$D,2,"0");case"d":return String(e.$W);case"dd":return f(r.weekdaysMin,e.$W,s,2);case"ddd":return f(r.weekdaysShort,e.$W,s,3);case"dddd":return s[e.$W];case"H":return String(i);case"HH":return _.s(i,2,"0");case"h":return d(1);case"hh":return d(2);case"a":return h(i,a,!0);case"A":return h(i,a,!1);case"m":return String(a);case"mm":return _.s(a,2,"0");case"s":return String(e.$s);case"ss":return _.s(e.$s,2,"0");case"SSS":return _.s(e.$ms,3,"0");case"Z":return o}return null}(t)||o.replace(":","")}))},b.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},b.diff=function(n,d,p){var h,g=this,v=_.p(d),b=x(n),y=(b.utcOffset()-this.utcOffset())*e,m=this-b,w=function(){return _.m(g,b)};switch(v){case f:h=w()/12;break;case c:h=w();break;case l:h=w()/3;break;case s:h=(m-y)/6048e5;break;case u:h=(m-y)/864e5;break;case a:h=m/r;break;case i:h=m/e;break;case o:h=m/t;break;default:h=m}return p?h:_.a(h)},b.daysInMonth=function(){return this.endOf(c).$D},b.$locale=function(){return w[this.$L]},b.locale=function(t,e){if(!t)return this.$L;var r=this.clone(),n=$(t,e,!0);return n&&(r.$L=n),r},b.clone=function(){return _.w(this.$d,this)},b.toDate=function(){return new Date(this.valueOf())},b.toJSON=function(){return this.isValid()?this.toISOString():null},b.toISOString=function(){return this.$d.toISOString()},b.toString=function(){return this.$d.toUTCString()},v}(),A=S.prototype;return x.prototype=A,[["$ms",n],["$s",o],["$m",i],["$H",a],["$W",u],["$M",c],["$y",f],["$D",d]].forEach((function(t){A[t[1]]=function(e){return this.$g(e,t[0],t[1])}})),x.extend=function(t,e){return t.$i||(t(e,S,x),t.$i=!0),x},x.locale=$,x.isDayjs=O,x.unix=function(t){return x(1e3*t)},x.en=w[m],x.Ls=w,x.p={},x}()}({get exports(){return Bn},set exports(t){Bn=t}});var Vn=Bn;const Hn=[];for(let t=0;t<256;++t)Hn.push((t+256).toString(16).slice(1));const Yn=new Uint8Array(16);function qn(){return crypto.getRandomValues(Yn)}const Xn={};function Kn(t,e,r){let n;if(t)n=Zn(t.random??t.rng?.()??qn(),t.msecs,t.seq,e,r);else{const t=Date.now(),o=qn();!function(t,e,r){t.msecs??=-1/0,t.seq??=0,e>t.msecs?(t.seq=Gn(r),t.msecs=e):(t.seq=t.seq+1|0,0===t.seq&&t.msecs++)}(Xn,t,o),n=Zn(o,Xn.msecs,Xn.seq,e,r)}return e??function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(Hn[t[e+0]]+Hn[t[e+1]]+Hn[t[e+2]]+Hn[t[e+3]]+"-"+Hn[t[e+4]]+Hn[t[e+5]]+"-"+Hn[t[e+6]]+Hn[t[e+7]]+"-"+Hn[t[e+8]]+Hn[t[e+9]]+"-"+Hn[t[e+10]]+Hn[t[e+11]]+Hn[t[e+12]]+Hn[t[e+13]]+Hn[t[e+14]]+Hn[t[e+15]]).toLowerCase()}(n)}function Zn(t,e,r,n){let o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0;if(t.length<16)throw new Error("Random bytes length must be >= 16");if(n){if(o<0||o+16>n.length)throw new RangeError(`UUID byte range ${o}:${o+15} is out of buffer bounds`)}else n=new Uint8Array(16),o=0;return e??=Date.now(),r??=Gn(t),n[o++]=e/1099511627776&255,n[o++]=e/4294967296&255,n[o++]=e/16777216&255,n[o++]=e/65536&255,n[o++]=e/256&255,n[o++]=255&e,n[o++]=112|r>>>28&15,n[o++]=r>>>20&255,n[o++]=128|r>>>14&63,n[o++]=r>>>6&255,n[o++]=r<<2&255|3&t[10],n[o++]=t[11],n[o++]=t[12],n[o++]=t[13],n[o++]=t[14],n[o++]=t[15],n}function Gn(t){return(127&t[6])<<24|t[7]<<16|t[8]<<8|t[9]}function Jn(t){let e=!1;if(Pr(t)){if(""===t.trim())return!1;e=!isNaN(Number(t))}else if(function(t){return"[object Number]"===Object.prototype.toString.call(t)}(t)){if(Sr(t))return!1;e=!0}return e}var Qn=function(){try{var t=Vt(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),to=Qn;function eo(t,e,r){"__proto__"==e&&to?to(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}var ro=Object.prototype.hasOwnProperty;function no(t,e,r){var n=t[e];ro.call(t,e)&&Kt(n,r)&&(void 0!==r||e in t)||eo(t,e,r)}function oo(t,e,r,n){var o=!r;r||(r={});for(var i=-1,a=e.length;++i<a;){var u=e[i],s=n?n(r[u],t[u],u,r,t):void 0;void 0===s&&(s=t[u]),o?eo(r,u,s):no(r,u,s)}return r}var io=Object.prototype.hasOwnProperty;function ao(t){if(!a(t))return function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e}(t);var e=st(t),r=[];for(var n in t)("constructor"!=n||!e&&io.call(t,n))&&r.push(n);return r}function uo(t){return yt(t)?at(t,!0):ao(t)}var so="object"==typeof exports&&exports&&!exports.nodeType&&exports,co=so&&"object"==typeof module&&module&&!module.nodeType&&module,lo=co&&co.exports===so?c.Buffer:void 0,fo=lo?lo.allocUnsafe:void 0;var po=ct(Object.getPrototypeOf,Object),ho=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)on(e,fn(t)),t=po(t);return e}:un,go=ho;function vo(t){return an(t,uo,go)}var bo=Object.prototype.hasOwnProperty;function yo(t){var e=new t.constructor(t.byteLength);return new Rr(e).set(new Rr(t)),e}var mo=/\w*$/;var wo=l?l.prototype:void 0,jo=wo?wo.valueOf:void 0;var Oo="[object Boolean]",$o="[object Date]",xo="[object Map]",_o="[object Number]",So="[object RegExp]",Ao="[object Set]",ko="[object String]",Po="[object Symbol]",Io="[object ArrayBuffer]",Do="[object DataView]",To="[object Float32Array]",Mo="[object Float64Array]",Eo="[object Int8Array]",Co="[object Int16Array]",zo="[object Int32Array]",Fo="[object Uint8Array]",Lo="[object Uint8ClampedArray]",Uo="[object Uint16Array]",Ro="[object Uint32Array]";function Wo(t,e,r){var n,o=t.constructor;switch(e){case Io:return yo(t);case Oo:case $o:return new o(+t);case Do:return function(t,e){var r=e?yo(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}(t,r);case To:case Mo:case Eo:case Co:case zo:case Fo:case Lo:case Uo:case Ro:return function(t,e){var r=e?yo(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}(t,r);case xo:return new o;case _o:case ko:return new o(t);case So:return function(t){var e=new t.constructor(t.source,mo.exec(t));return e.lastIndex=t.lastIndex,e}(t);case Ao:return new o;case Po:return n=t,jo?Object(jo.call(n)):{}}}var No=Object.create,Bo=function(){function t(){}return function(e){if(!a(e))return{};if(No)return No(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),Vo=Bo;var Ho=rt&&rt.isMap,Yo=Ho?J(Ho):function(t){return w(t)&&"[object Map]"==nr(t)};var qo=rt&&rt.isSet,Xo=qo?J(qo):function(t){return w(t)&&"[object Set]"==nr(t)},Ko=1,Zo=2,Go=4,Jo="[object Arguments]",Qo="[object Function]",ti="[object GeneratorFunction]",ei="[object Object]",ri={};function ni(t,e,r,n,o,i){var u,s=e&Ko,c=e&Zo,l=e&Go;if(r&&(u=o?r(t,n,o,i):r(t)),void 0!==u)return u;if(!a(t))return t;var f=W(t);if(f){if(u=function(t){var e=t.length,r=new t.constructor(e);return e&&"string"==typeof t[0]&&bo.call(t,"index")&&(r.index=t.index,r.input=t.input),r}(t),!s)return function(t,e){var r=-1,n=t.length;for(e||(e=Array(n));++r<n;)e[r]=t[r];return e}(t,u)}else{var d=nr(t),p=d==Qo||d==ti;if(H(t))return function(t,e){if(e)return t.slice();var r=t.length,n=fo?fo(r):new t.constructor(r);return t.copy(n),n}(t,s);if(d==ei||d==Jo||p&&!o){if(u=c||p?{}:function(t){return"function"!=typeof t.constructor||st(t)?{}:Vo(po(t))}(t),!s)return c?function(t,e){return oo(t,go(t),e)}(t,function(t,e){return t&&oo(e,uo(e),t)}(u,t)):function(t,e){return oo(t,fn(t),e)}(t,function(t,e){return t&&oo(e,mt(e),t)}(u,t))}else{if(!ri[d])return o?t:{};u=Wo(t,d,s)}}i||(i=new Mr);var h=i.get(t);if(h)return h;i.set(t,u),Xo(t)?t.forEach((function(n){u.add(ni(n,e,r,n,t,i))})):Yo(t)&&t.forEach((function(n,o){u.set(o,ni(n,e,r,o,t,i))}));var g=f?void 0:(l?c?vo:dn:c?uo:mt)(t);return T(g||t,(function(n,o){g&&(n=t[o=n]),no(u,o,ni(n,e,r,o,t,i))})),u}ri[Jo]=ri["[object Array]"]=ri["[object ArrayBuffer]"]=ri["[object DataView]"]=ri["[object Boolean]"]=ri["[object Date]"]=ri["[object Float32Array]"]=ri["[object Float64Array]"]=ri["[object Int8Array]"]=ri["[object Int16Array]"]=ri["[object Int32Array]"]=ri["[object Map]"]=ri["[object Number]"]=ri[ei]=ri["[object RegExp]"]=ri["[object Set]"]=ri["[object String]"]=ri["[object Symbol]"]=ri["[object Uint8Array]"]=ri["[object Uint8ClampedArray]"]=ri["[object Uint16Array]"]=ri["[object Uint32Array]"]=!0,ri["[object Error]"]=ri[Qo]=ri["[object WeakMap]"]=!1;var oi=1,ii=4;var ai={},ui={get exports(){return ai},set exports(t){ai=t}},si={},ci={},li={get exports(){return ci},set exports(t){ci=t}},fi={};function di(){var t={"align-content":!1,"align-items":!1,"align-self":!1,"alignment-adjust":!1,"alignment-baseline":!1,all:!1,"anchor-point":!1,animation:!1,"animation-delay":!1,"animation-direction":!1,"animation-duration":!1,"animation-fill-mode":!1,"animation-iteration-count":!1,"animation-name":!1,"animation-play-state":!1,"animation-timing-function":!1,azimuth:!1,"backface-visibility":!1,background:!0,"background-attachment":!0,"background-clip":!0,"background-color":!0,"background-image":!0,"background-origin":!0,"background-position":!0,"background-repeat":!0,"background-size":!0,"baseline-shift":!1,binding:!1,bleed:!1,"bookmark-label":!1,"bookmark-level":!1,"bookmark-state":!1,border:!0,"border-bottom":!0,"border-bottom-color":!0,"border-bottom-left-radius":!0,"border-bottom-right-radius":!0,"border-bottom-style":!0,"border-bottom-width":!0,"border-collapse":!0,"border-color":!0,"border-image":!0,"border-image-outset":!0,"border-image-repeat":!0,"border-image-slice":!0,"border-image-source":!0,"border-image-width":!0,"border-left":!0,"border-left-color":!0,"border-left-style":!0,"border-left-width":!0,"border-radius":!0,"border-right":!0,"border-right-color":!0,"border-right-style":!0,"border-right-width":!0,"border-spacing":!0,"border-style":!0,"border-top":!0,"border-top-color":!0,"border-top-left-radius":!0,"border-top-right-radius":!0,"border-top-style":!0,"border-top-width":!0,"border-width":!0,bottom:!1,"box-decoration-break":!0,"box-shadow":!0,"box-sizing":!0,"box-snap":!0,"box-suppress":!0,"break-after":!0,"break-before":!0,"break-inside":!0,"caption-side":!1,chains:!1,clear:!0,clip:!1,"clip-path":!1,"clip-rule":!1,color:!0,"color-interpolation-filters":!0,"column-count":!1,"column-fill":!1,"column-gap":!1,"column-rule":!1,"column-rule-color":!1,"column-rule-style":!1,"column-rule-width":!1,"column-span":!1,"column-width":!1,columns:!1,contain:!1,content:!1,"counter-increment":!1,"counter-reset":!1,"counter-set":!1,crop:!1,cue:!1,"cue-after":!1,"cue-before":!1,cursor:!1,direction:!1,display:!0,"display-inside":!0,"display-list":!0,"display-outside":!0,"dominant-baseline":!1,elevation:!1,"empty-cells":!1,filter:!1,flex:!1,"flex-basis":!1,"flex-direction":!1,"flex-flow":!1,"flex-grow":!1,"flex-shrink":!1,"flex-wrap":!1,float:!1,"float-offset":!1,"flood-color":!1,"flood-opacity":!1,"flow-from":!1,"flow-into":!1,font:!0,"font-family":!0,"font-feature-settings":!0,"font-kerning":!0,"font-language-override":!0,"font-size":!0,"font-size-adjust":!0,"font-stretch":!0,"font-style":!0,"font-synthesis":!0,"font-variant":!0,"font-variant-alternates":!0,"font-variant-caps":!0,"font-variant-east-asian":!0,"font-variant-ligatures":!0,"font-variant-numeric":!0,"font-variant-position":!0,"font-weight":!0,grid:!1,"grid-area":!1,"grid-auto-columns":!1,"grid-auto-flow":!1,"grid-auto-rows":!1,"grid-column":!1,"grid-column-end":!1,"grid-column-start":!1,"grid-row":!1,"grid-row-end":!1,"grid-row-start":!1,"grid-template":!1,"grid-template-areas":!1,"grid-template-columns":!1,"grid-template-rows":!1,"hanging-punctuation":!1,height:!0,hyphens:!1,icon:!1,"image-orientation":!1,"image-resolution":!1,"ime-mode":!1,"initial-letters":!1,"inline-box-align":!1,"justify-content":!1,"justify-items":!1,"justify-self":!1,left:!1,"letter-spacing":!0,"lighting-color":!0,"line-box-contain":!1,"line-break":!1,"line-grid":!1,"line-height":!1,"line-snap":!1,"line-stacking":!1,"line-stacking-ruby":!1,"line-stacking-shift":!1,"line-stacking-strategy":!1,"list-style":!0,"list-style-image":!0,"list-style-position":!0,"list-style-type":!0,margin:!0,"margin-bottom":!0,"margin-left":!0,"margin-right":!0,"margin-top":!0,"marker-offset":!1,"marker-side":!1,marks:!1,mask:!1,"mask-box":!1,"mask-box-outset":!1,"mask-box-repeat":!1,"mask-box-slice":!1,"mask-box-source":!1,"mask-box-width":!1,"mask-clip":!1,"mask-image":!1,"mask-origin":!1,"mask-position":!1,"mask-repeat":!1,"mask-size":!1,"mask-source-type":!1,"mask-type":!1,"max-height":!0,"max-lines":!1,"max-width":!0,"min-height":!0,"min-width":!0,"move-to":!1,"nav-down":!1,"nav-index":!1,"nav-left":!1,"nav-right":!1,"nav-up":!1,"object-fit":!1,"object-position":!1,opacity:!1,order:!1,orphans:!1,outline:!1,"outline-color":!1,"outline-offset":!1,"outline-style":!1,"outline-width":!1,overflow:!1,"overflow-wrap":!1,"overflow-x":!1,"overflow-y":!1,padding:!0,"padding-bottom":!0,"padding-left":!0,"padding-right":!0,"padding-top":!0,page:!1,"page-break-after":!1,"page-break-before":!1,"page-break-inside":!1,"page-policy":!1,pause:!1,"pause-after":!1,"pause-before":!1,perspective:!1,"perspective-origin":!1,pitch:!1,"pitch-range":!1,"play-during":!1,position:!1,"presentation-level":!1,quotes:!1,"region-fragment":!1,resize:!1,rest:!1,"rest-after":!1,"rest-before":!1,richness:!1,right:!1,rotation:!1,"rotation-point":!1,"ruby-align":!1,"ruby-merge":!1,"ruby-position":!1,"shape-image-threshold":!1,"shape-outside":!1,"shape-margin":!1,size:!1,speak:!1,"speak-as":!1,"speak-header":!1,"speak-numeral":!1,"speak-punctuation":!1,"speech-rate":!1,stress:!1,"string-set":!1,"tab-size":!1,"table-layout":!1,"text-align":!0,"text-align-last":!0,"text-combine-upright":!0,"text-decoration":!0,"text-decoration-color":!0,"text-decoration-line":!0,"text-decoration-skip":!0,"text-decoration-style":!0,"text-emphasis":!0,"text-emphasis-color":!0,"text-emphasis-position":!0,"text-emphasis-style":!0,"text-height":!0,"text-indent":!0,"text-justify":!0,"text-orientation":!0,"text-overflow":!0,"text-shadow":!0,"text-space-collapse":!0,"text-transform":!0,"text-underline-position":!0,"text-wrap":!0,top:!1,transform:!1,"transform-origin":!1,"transform-style":!1,transition:!1,"transition-delay":!1,"transition-duration":!1,"transition-property":!1,"transition-timing-function":!1,"unicode-bidi":!1,"vertical-align":!1,visibility:!1,"voice-balance":!1,"voice-duration":!1,"voice-family":!1,"voice-pitch":!1,"voice-range":!1,"voice-rate":!1,"voice-stress":!1,"voice-volume":!1,volume:!1,"white-space":!1,widows:!1,width:!0,"will-change":!1,"word-break":!0,"word-spacing":!0,"word-wrap":!0,"wrap-flow":!1,"wrap-through":!1,"writing-mode":!1,"z-index":!1};return t}var pi=/javascript\s*\:/gim;fi.whiteList=di(),fi.getDefaultWhiteList=di,fi.onAttr=function(t,e,r){},fi.onIgnoreAttr=function(t,e,r){},fi.safeAttrValue=function(t,e){return pi.test(e)?"":e};var hi={indexOf:function(t,e){var r,n;if(Array.prototype.indexOf)return t.indexOf(e);for(r=0,n=t.length;r<n;r++)if(t[r]===e)return r;return-1},forEach:function(t,e,r){var n,o;if(Array.prototype.forEach)return t.forEach(e,r);for(n=0,o=t.length;n<o;n++)e.call(r,t[n],n,t)},trim:function(t){return String.prototype.trim?t.trim():t.replace(/(^\s*)|(\s*$)/g,"")},trimRight:function(t){return String.prototype.trimRight?t.trimRight():t.replace(/(\s*$)/g,"")}};var gi=function(t,e){";"!==(t=hi.trimRight(t))[t.length-1]&&(t+=";");var r=t.length,n=!1,o=0,i=0,a="";function u(){if(!n){var r=hi.trim(t.slice(o,i)),u=r.indexOf(":");if(-1!==u){var s=hi.trim(r.slice(0,u)),c=hi.trim(r.slice(u+1));if(s){var l=e(o,a.length,s,c,r);l&&(a+=l+"; ")}}}o=i+1}for(;i<r;i++){var s=t[i];if("/"===s&&"*"===t[i+1]){var c=t.indexOf("*/",i+2);if(-1===c)break;o=(i=c+1)+1,n=!1}else"("===s?n=!0:")"===s?n=!1:";"===s?n||u():"\n"===s&&u()}return hi.trim(a)},vi=fi,bi=gi;function yi(t){return null==t}function mi(t){(t=function(t){var e={};for(var r in t)e[r]=t[r];return e}(t||{})).whiteList=t.whiteList||vi.whiteList,t.onAttr=t.onAttr||vi.onAttr,t.onIgnoreAttr=t.onIgnoreAttr||vi.onIgnoreAttr,t.safeAttrValue=t.safeAttrValue||vi.safeAttrValue,this.options=t}mi.prototype.process=function(t){if(!(t=(t=t||"").toString()))return"";var e=this.options,r=e.whiteList,n=e.onAttr,o=e.onIgnoreAttr,i=e.safeAttrValue;return bi(t,(function(t,e,a,u,s){var c=r[a],l=!1;if(!0===c?l=c:"function"==typeof c?l=c(u):c instanceof RegExp&&(l=c.test(u)),!0!==l&&(l=!1),u=i(a,u)){var f,d={position:e,sourcePosition:t,source:s,isWhite:l};return l?yi(f=n(a,u,d))?a+":"+u:f:yi(f=o(a,u,d))?void 0:f}}))};var wi=mi;!function(t,e){var r=fi,n=wi;for(var o in(e=t.exports=function(t,e){return new n(e).process(t)}).FilterCSS=n,r)e[o]=r[o];"undefined"!=typeof window&&(window.filterCSS=t.exports)}(li,ci);var ji={indexOf:function(t,e){var r,n;if(Array.prototype.indexOf)return t.indexOf(e);for(r=0,n=t.length;r<n;r++)if(t[r]===e)return r;return-1},forEach:function(t,e,r){var n,o;if(Array.prototype.forEach)return t.forEach(e,r);for(n=0,o=t.length;n<o;n++)e.call(r,t[n],n,t)},trim:function(t){return String.prototype.trim?t.trim():t.replace(/(^\s*)|(\s*$)/g,"")},spaceIndex:function(t){var e=/\s|\n|\t/.exec(t);return e?e.index:-1}},Oi=ci.FilterCSS,$i=ci.getDefaultWhiteList,xi=ji;function _i(){return{a:["target","href","title"],abbr:["title"],address:[],area:["shape","coords","href","alt"],article:[],aside:[],audio:["autoplay","controls","crossorigin","loop","muted","preload","src"],b:[],bdi:["dir"],bdo:["dir"],big:[],blockquote:["cite"],br:[],caption:[],center:[],cite:[],code:[],col:["align","valign","span","width"],colgroup:["align","valign","span","width"],dd:[],del:["datetime"],details:["open"],div:[],dl:[],dt:[],em:[],figcaption:[],figure:[],font:["color","size","face"],footer:[],h1:[],h2:[],h3:[],h4:[],h5:[],h6:[],header:[],hr:[],i:[],img:["src","alt","title","width","height","loading"],ins:["datetime"],kbd:[],li:[],mark:[],nav:[],ol:[],p:[],pre:[],s:[],section:[],small:[],span:[],sub:[],summary:[],sup:[],strong:[],strike:[],table:["width","border","align","valign"],tbody:["align","valign"],td:["width","rowspan","colspan","align","valign"],tfoot:["align","valign"],th:["width","rowspan","colspan","align","valign"],thead:["align","valign"],tr:["rowspan","align","valign"],tt:[],u:[],ul:[],video:["autoplay","controls","crossorigin","loop","muted","playsinline","poster","preload","src","height","width"]}}var Si=new Oi;function Ai(t){return t.replace(ki,"<").replace(Pi,">")}var ki=/</g,Pi=/>/g,Ii=/"/g,Di=/"/g,Ti=/&#([a-zA-Z0-9]*);?/gim,Mi=/:?/gim,Ei=/&newline;?/gim,Ci=/((j\s*a\s*v\s*a|v\s*b|l\s*i\s*v\s*e)\s*s\s*c\s*r\s*i\s*p\s*t\s*|m\s*o\s*c\s*h\s*a):/gi,zi=/e\s*x\s*p\s*r\s*e\s*s\s*s\s*i\s*o\s*n\s*\(.*/gi,Fi=/u\s*r\s*l\s*\(.*/gi;function Li(t){return t.replace(Ii,""")}function Ui(t){return t.replace(Di,'"')}function Ri(t){return t.replace(Ti,(function(t,e){return"x"===e[0]||"X"===e[0]?String.fromCharCode(parseInt(e.substr(1),16)):String.fromCharCode(parseInt(e,10))}))}function Wi(t){return t.replace(Mi,":").replace(Ei," ")}function Ni(t){for(var e="",r=0,n=t.length;r<n;r++)e+=t.charCodeAt(r)<32?" ":t.charAt(r);return xi.trim(e)}function Bi(t){return t=Ni(t=Wi(t=Ri(t=Ui(t))))}function Vi(t){return t=Ai(t=Li(t))}si.whiteList={a:["target","href","title"],abbr:["title"],address:[],area:["shape","coords","href","alt"],article:[],aside:[],audio:["autoplay","controls","crossorigin","loop","muted","preload","src"],b:[],bdi:["dir"],bdo:["dir"],big:[],blockquote:["cite"],br:[],caption:[],center:[],cite:[],code:[],col:["align","valign","span","width"],colgroup:["align","valign","span","width"],dd:[],del:["datetime"],details:["open"],div:[],dl:[],dt:[],em:[],figcaption:[],figure:[],font:["color","size","face"],footer:[],h1:[],h2:[],h3:[],h4:[],h5:[],h6:[],header:[],hr:[],i:[],img:["src","alt","title","width","height","loading"],ins:["datetime"],kbd:[],li:[],mark:[],nav:[],ol:[],p:[],pre:[],s:[],section:[],small:[],span:[],sub:[],summary:[],sup:[],strong:[],strike:[],table:["width","border","align","valign"],tbody:["align","valign"],td:["width","rowspan","colspan","align","valign"],tfoot:["align","valign"],th:["width","rowspan","colspan","align","valign"],thead:["align","valign"],tr:["rowspan","align","valign"],tt:[],u:[],ul:[],video:["autoplay","controls","crossorigin","loop","muted","playsinline","poster","preload","src","height","width"]},si.getDefaultWhiteList=_i,si.onTag=function(t,e,r){},si.onIgnoreTag=function(t,e,r){},si.onTagAttr=function(t,e,r){},si.onIgnoreTagAttr=function(t,e,r){},si.safeAttrValue=function(t,e,r,n){if(r=Bi(r),"href"===e||"src"===e){if("#"===(r=xi.trim(r)))return"#";if("http://"!==r.substr(0,7)&&"https://"!==r.substr(0,8)&&"mailto:"!==r.substr(0,7)&&"tel:"!==r.substr(0,4)&&"data:image/"!==r.substr(0,11)&&"ftp://"!==r.substr(0,6)&&"./"!==r.substr(0,2)&&"../"!==r.substr(0,3)&&"#"!==r[0]&&"/"!==r[0])return""}else if("background"===e){if(Ci.lastIndex=0,Ci.test(r))return""}else if("style"===e){if(zi.lastIndex=0,zi.test(r))return"";if(Fi.lastIndex=0,Fi.test(r)&&(Ci.lastIndex=0,Ci.test(r)))return"";!1!==n&&(r=(n=n||Si).process(r))}return r=Vi(r)},si.escapeHtml=Ai,si.escapeQuote=Li,si.unescapeQuote=Ui,si.escapeHtmlEntities=Ri,si.escapeDangerHtml5Entities=Wi,si.clearNonPrintableCharacter=Ni,si.friendlyAttrValue=Bi,si.escapeAttrValue=Vi,si.onIgnoreTagStripAll=function(){return""},si.StripTagBody=function(t,e){"function"!=typeof e&&(e=function(){});var r=!Array.isArray(t),n=[],o=!1;return{onIgnoreTag:function(i,a,u){if(function(e){return!!r||-1!==xi.indexOf(t,e)}(i)){if(u.isClosing){var s="[/removed]",c=u.position+s.length;return n.push([!1!==o?o:u.position,c]),o=!1,s}return o||(o=u.position),"[removed]"}return e(i,a,u)},remove:function(t){var e="",r=0;return xi.forEach(n,(function(n){e+=t.slice(r,n[0]),r=n[1]})),e+=t.slice(r)}}},si.stripCommentTag=function(t){for(var e="",r=0;r<t.length;){var n=t.indexOf("\x3c!--",r);if(-1===n){e+=t.slice(r);break}e+=t.slice(r,n);var o=t.indexOf("--\x3e",n);if(-1===o)break;r=o+3}return e},si.stripBlankChar=function(t){var e=t.split("");return(e=e.filter((function(t){var e=t.charCodeAt(0);return 127!==e&&(!(e<=31)||(10===e||13===e))}))).join("")},si.attributeWrapSign='"',si.cssFilter=Si,si.getDefaultCSSWhiteList=$i;var Hi={},Yi=ji;function qi(t){var e,r=Yi.spaceIndex(t);return e=-1===r?t.slice(1,-1):t.slice(1,r+1),"/"===(e=Yi.trim(e).toLowerCase()).slice(0,1)&&(e=e.slice(1)),"/"===e.slice(-1)&&(e=e.slice(0,-1)),e}function Xi(t){return"</"===t.slice(0,2)}var Ki=/[^a-zA-Z0-9\\_:.-]/gim;function Zi(t,e){for(;e<t.length;e++){var r=t[e];if(" "!==r)return"="===r?e:-1}}function Gi(t,e){for(;e<t.length;e++){var r=t[e];if(" "!==r)return"'"===r||'"'===r?e:-1}}function Ji(t,e){for(;e>0;e--){var r=t[e];if(" "!==r)return"="===r?e:-1}}function Qi(t){return function(t){return'"'===t[0]&&'"'===t[t.length-1]||"'"===t[0]&&"'"===t[t.length-1]}(t)?t.substr(1,t.length-2):t}Hi.parseTag=function(t,e,r){var n="",o=0,i=!1,a=!1,u=0,s=t.length,c="",l="";t:for(u=0;u<s;u++){var f=t.charAt(u);if(!1===i){if("<"===f){i=u;continue}}else if(!1===a){if("<"===f){n+=r(t.slice(o,u)),i=u,o=u;continue}if(">"===f||u===s-1){n+=r(t.slice(o,i)),c=qi(l=t.slice(i,u+1)),n+=e(i,n.length,c,l,Xi(l)),o=u+1,i=!1;continue}if('"'===f||"'"===f)for(var d=1,p=t.charAt(u-d);""===p.trim()||"="===p;){if("="===p){a=f;continue t}p=t.charAt(u-++d)}}else if(f===a){a=!1;continue}}return o<s&&(n+=r(t.substr(o))),n},Hi.parseAttr=function(t,e){var r=0,n=0,o=[],i=!1,a=t.length;function u(t,r){if(!((t=(t=Yi.trim(t)).replace(Ki,"").toLowerCase()).length<1)){var n=e(t,r||"");n&&o.push(n)}}for(var s=0;s<a;s++){var c,l=t.charAt(s);if(!1!==i||"="!==l)if(!1===i||s!==n)if(/\s|\n|\t/.test(l)){if(t=t.replace(/\s|\n|\t/g," "),!1===i){if(-1===(c=Zi(t,s))){u(Yi.trim(t.slice(r,s))),i=!1,r=s+1;continue}s=c-1;continue}if(-1===(c=Ji(t,s-1))){u(i,Qi(Yi.trim(t.slice(r,s)))),i=!1,r=s+1;continue}}else;else{if(-1===(c=t.indexOf(l,s+1)))break;u(i,Yi.trim(t.slice(n+1,c))),i=!1,r=(s=c)+1}else i=t.slice(r,s),r=s+1,n='"'===t.charAt(r)||"'"===t.charAt(r)?r:Gi(t,s+1)}return r<t.length&&(!1===i?u(t.slice(r)):u(i,Qi(Yi.trim(t.slice(r))))),Yi.trim(o.join(" "))};var ta=ci.FilterCSS,ea=si,ra=Hi,na=ra.parseTag,oa=ra.parseAttr,ia=ji;function aa(t){return null==t}function ua(t){(t=function(t){var e={};for(var r in t)e[r]=t[r];return e}(t||{})).stripIgnoreTag&&(t.onIgnoreTag&&console.error('Notes: cannot use these two options "stripIgnoreTag" and "onIgnoreTag" at the same time'),t.onIgnoreTag=ea.onIgnoreTagStripAll),t.whiteList||t.allowList?t.whiteList=function(t){var e={};for(var r in t)Array.isArray(t[r])?e[r.toLowerCase()]=t[r].map((function(t){return t.toLowerCase()})):e[r.toLowerCase()]=t[r];return e}(t.whiteList||t.allowList):t.whiteList=ea.whiteList,this.attributeWrapSign=!0===t.singleQuotedAttributeValue?"'":ea.attributeWrapSign,t.onTag=t.onTag||ea.onTag,t.onTagAttr=t.onTagAttr||ea.onTagAttr,t.onIgnoreTag=t.onIgnoreTag||ea.onIgnoreTag,t.onIgnoreTagAttr=t.onIgnoreTagAttr||ea.onIgnoreTagAttr,t.safeAttrValue=t.safeAttrValue||ea.safeAttrValue,t.escapeHtml=t.escapeHtml||ea.escapeHtml,this.options=t,!1===t.css?this.cssFilter=!1:(t.css=t.css||{},this.cssFilter=new ta(t.css))}ua.prototype.process=function(t){if(!(t=(t=t||"").toString()))return"";var e=this,r=e.options,n=r.whiteList,o=r.onTag,i=r.onIgnoreTag,a=r.onTagAttr,u=r.onIgnoreTagAttr,s=r.safeAttrValue,c=r.escapeHtml,l=e.attributeWrapSign,f=e.cssFilter;r.stripBlankChar&&(t=ea.stripBlankChar(t)),r.allowCommentTag||(t=ea.stripCommentTag(t));var d=!1;r.stripIgnoreTagBody&&(d=ea.StripTagBody(r.stripIgnoreTagBody,i),i=d.onIgnoreTag);var p=na(t,(function(t,e,r,d,p){var h={sourcePosition:t,position:e,isClosing:p,isWhite:Object.prototype.hasOwnProperty.call(n,r)},g=o(r,d,h);if(!aa(g))return g;if(h.isWhite){if(h.isClosing)return"</"+r+">";var v=function(t){var e=ia.spaceIndex(t);if(-1===e)return{html:"",closing:"/"===t[t.length-2]};var r="/"===(t=ia.trim(t.slice(e+1,-1)))[t.length-1];return r&&(t=ia.trim(t.slice(0,-1))),{html:t,closing:r}}(d),b=n[r],y=oa(v.html,(function(t,e){var n=-1!==ia.indexOf(b,t),o=a(r,t,e,n);return aa(o)?n?(e=s(r,t,e,f))?t+"="+l+e+l:t:aa(o=u(r,t,e,n))?void 0:o:o}));return d="<"+r,y&&(d+=" "+y),v.closing&&(d+=" /"),d+=">"}return aa(g=i(r,d,h))?c(d):g}),c);return d&&(p=d.remove(p)),p};var sa=ua;!function(t,e){var r=si,n=Hi,o=sa;function i(t,e){return new o(e).process(t)}(e=t.exports=i).filterXSS=i,e.FilterXSS=o,function(){for(var t in r)e[t]=r[t];for(var o in n)e[o]=n[o]}(),"undefined"!=typeof window&&(window.filterXSS=t.exports),"undefined"!=typeof self&&"undefined"!=typeof DedicatedWorkerGlobalScope&&self instanceof DedicatedWorkerGlobalScope&&(self.filterXSS=t.exports)}(ui,ai);var ca=ai;function la(){return"undefined"!=typeof self?self:"undefined"!=typeof window&&void 0!==window.document?window:"undefined"!=typeof global?global:null}let fa=/<(?=[A-Za-z!/?]|$)/g;function da(t){return t.replace(fa,"<")}let pa={getFilterXSS:function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:ca;if(xt(t))return t;let e=la(),r=je(e,"filterXSS",null);if(xt(r))return r;let n=je(e,"xss",null);if(xt(n))return n;throw new Error("invalid filterXSS, g.filterXSS, use script for import")},getOpt:function(t){return{escapeHtml:da,onIgnoreTagAttr:function(e,r,n,o){if("style"===r)return r+'="'+t.escapeAttrValue(n)+'"'}}}};function ha(t){let e=null,r=null;let n=function t(n){if(Array.isArray(n)){for(let e=0;e<n.length;e++)n[e]=t(n[e]);return n}if(At(n)||St(n)){for(let e of Object.keys(n))n[e]=t(n[e]);return n}return Pr(n)?(o=n,null===e&&(e=pa.getFilterXSS(),r=pa.getOpt(e)),e(o,r)):n;var o}(ni(t,oi|ii));return n}function ga(t,e){if(!St(t))return[];St(e)||(e=[e]);let r=[];return $t(t,((t,n)=>{0===je(t,"ok")&&r.push({k:n,id:je(e,[n,"id"]),err:je(t,"err","")})})),r}function va(t,e){var n,o,i;let a=`${t}: ${zn(En((o=10,(n=e)&&n.length?r(n,0,(o=i||void 0===o?1:D(o))<0?0:o):[]),(t=>Pr(t.ref)?t.ref:Pr(t.id)||Jn(t.id)?`id[${Nn(String(t.id),{length:100,omission:"…"})}]`:`data[${t.k}]`)),", ")}`;return Or(e)>10&&(a+=`, ... (${Or(e)} in total)`),a}function ba(t,e){if(e.indexOf("id")<0)return!1;let r=je(t,"settings",null);if(xr(r)&&!0!==je(r,"id.pk"))return!1;let n=je(r,"id.type","")||je(t,"kpType.id","");return!(Pr(n)&&["STRING","TEXT","CHAR","UUID","CITEXT"].indexOf(n.split("(")[0].trim().toUpperCase())<0)}function ya(t,e){return null!==t&&"object"==typeof t&&"string"==typeof e&&Object.prototype.hasOwnProperty.call(t,e)?void 0===t[e]?null:t[e]:null}function ma(t){return"number"==typeof t&&Number.isFinite(t)}function wa(t){return ma(t)?String(t):t}function ja(t,e){return Object.fromEntries(Object.keys(t).map((r=>[r,e(t[r],r)])))}const Oa=Object.freeze({proto:"unsupported key[__proto__]",accessor:"unsupported accessor property",unreadable:"unreadable value",deep:"too deep",hidden:"unsupported symbol key or non-enumerable property",irregular:"unsupported irregular object or array"}),$a=64,xa=4e6,_a=200,Sa=8,Aa=50,ka=200,Pa="function"==typeof WeakRef?Function.prototype.call.bind(WeakRef.prototype.deref):null,Ia="function"==typeof FinalizationRegistry?Function.prototype.call.bind(FinalizationRegistry.prototype.unregister):null,Da={};function Ta(t){for(let r=t;null!==r;r=Object.getPrototypeOf(r))if(e.types.isProxy(r)||Object.prototype.hasOwnProperty.call(r,Symbol.toStringTag))return!1;return!0}function Ma(t){return e.types.isMap(t)||e.types.isSet(t)||e.types.isWeakMap(t)||e.types.isWeakSet(t)||e.types.isPromise(t)||e.types.isAnyArrayBuffer(t)||e.types.isArrayBufferView(t)||e.types.isBoxedPrimitive(t)||e.types.isRegExp(t)||e.types.isNativeError(t)||e.types.isGeneratorObject(t)||e.types.isMapIterator(t)||e.types.isSetIterator(t)||e.types.isModuleNamespaceObject(t)}function Ea(t){if("object"!=typeof t||null===t||!Ta(t)||!At(t))return!1;let r=Object.getPrototypeOf(t);return null===r||r===Object.prototype||function(t){if(null!==Object.getPrototypeOf(t))return!1;let r=Reflect.ownKeys(Object.prototype);if(Reflect.ownKeys(t).length!==r.length)return!1;for(let e of r)if(!Object.prototype.hasOwnProperty.call(t,e))return!1;let n=Object.getOwnPropertyDescriptor(t,"constructor");if(void 0===n||"function"!=typeof n.value||e.types.isProxy(n.value))return!1;if(Function.prototype.toString.call(n.value)!==Function.prototype.toString.call(Object))return!1;let o=Object.getOwnPropertyDescriptor(n.value,"prototype");return void 0!==o&&o.value===t}(r)}function Ca(t){return"object"!=typeof t||null===t||!Ta(t)||Ma(t)?null:Array.isArray(t)?"arr":At(t)?"obj":null}function za(t){if(null!==Pa)try{return Pa(t),!0}catch(t){}if(null!==Ia)try{return Ia(t,Da),!0}catch(t){}return!1}function Fa(t){try{for(var e=arguments.length,r=new Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];console.log(t,...r)}catch(e){try{console.log(t,"(unprintable)")}catch(t){}}}function La(t){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{n:0},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(r.n>=_a)return"[...]";if(r.n++,"string"==typeof t)return Nn(t,{length:ka});if("function"==typeof t)return"[Function]";if("symbol"==typeof t)return"[Symbol]";if("object"!=typeof t||null===t)return t;if(e.types.isProxy(t))return"[Proxy]";if(e.types.isDate(t))return"[Date]";if(Ma(t))return"[Object]";if(n>=Sa)return"[...]";let o=t=>void 0===t?"[empty]":void 0!==t.get||void 0!==t.set?"[Getter/Setter]":La(t.value,r,n+1);if(Array.isArray(t)){let e=Math.min(t.length,Aa),r=[];for(let n=0;n<e;n++)r.push(o(Object.getOwnPropertyDescriptor(t,n)));return t.length>e&&r.push(`[${t.length-e} more]`),r}let i=Reflect.ownKeys(t),a={};for(let e of i.slice(0,Aa)){let r=Object.getOwnPropertyDescriptor(t,e),n="symbol"==typeof e?String(e):e;Object.defineProperty(a,r.enumerable?n:`${n} (non-enumerable)`,{value:o(r),enumerable:!0,writable:!0,configurable:!0})}return i.length>Aa&&Object.defineProperty(a,"[more]",{value:i.length-Aa,enumerable:!0,writable:!0,configurable:!0}),a}function Ua(t,e){let r;try{r=La(e)}catch(t){r="(unprintable)"}Fa(t,r)}function Ra(t){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1/0,n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];try{let o=new Set,i=[t,1],a=0,u=[];for(;i.length>0;){let t,s=i.pop(),c=i.pop();if(o.has(c))continue;if(n){if("object"==typeof c&&null!==c){if(!Ta(c)||Ma(c))return"irregular";if(e.types.isDate(c)){if(Reflect.ownKeys(c).length>0)return"irregular";continue}}t=Ca(c)}else t=Array.isArray(c)?"arr":At(c)?"obj":null;if(null===t)continue;let l="arr"===t;if(s>r)return"deep";if(o.add(c),Object.prototype.hasOwnProperty.call(c,"__proto__"))return"proto";let f=l?null:Object.keys(c);if(n&&!l){if(!Ea(c))return"irregular";if(Reflect.ownKeys(c).length!==f.length)return"hidden";u.push(c)}let d=l?c.length:f.length;for(let t=0;t<d;t++){let e=Object.getOwnPropertyDescriptor(c,l?t:f[t]);if(void 0!==e){if(void 0!==e.get||void 0!==e.set)return"accessor";if(n&&l&&!e.enumerable)return"irregular";n&&(a+=l?0:f[t].length,"string"==typeof e.value&&(a+=e.value.length)),"object"==typeof e.value&&null!==e.value&&i.push(e.value,s+1)}else if(n)return"irregular"}if(n&&l&&Reflect.ownKeys(c).length!==d+1)return"irregular"}if(n&&"object"==typeof t&&null!==t)if(a<=xa&&"function"==typeof structuredClone){if(function(t){if("function"!=typeof structuredClone)return!1;let e;try{e=structuredClone(t)}catch(t){return!0}let r=new Set,n=[e];for(;n.length>0;){let t=n.pop();if("object"!=typeof t||null===t||r.has(t))continue;r.add(t);let e=Object.getPrototypeOf(t);if(e!==Date.prototype){if(e!==Object.prototype&&e!==Array.prototype)return!0;for(let e of Object.keys(t))n.push(t[e])}}return!1}(t))return"irregular"}else for(let t=0;t<u.length;t++)if(za(u[t]))return"irregular";return null}catch(t){return"unreadable"}}function Wa(t,r){try{if(void 0!==r&&"object"==typeof r&&null!==r&&e.types.isProxy(r))return`invalid find of ${t}, ${Oa.irregular}`;if(void 0!==r&&!Ea(r))return`invalid find of ${t}, need an object`;let n=Ra(r,$a,!0);return null!==n?`invalid find of ${t}, ${Oa[n]}`:null}catch(e){return`invalid find of ${t}, ${Oa.unreadable}`}}function Na(t,e){let r=new Map,n=(t,e)=>{r.has(t)||r.set(t,[]),r.get(t).push({k:e})};if(Array.isArray(e))for(let t=0;t<e.length;t++)try{let r=Object.getOwnPropertyDescriptor(e,t);if(void 0===r)continue;if(void 0!==r.get||void 0!==r.set){n("accessor",t);continue}let o=Ra(r.value);null!==o&&n(o,t)}catch(e){n("unreadable",t)}else{let t=Ra(e);null!==t&&n(t,0)}return En([...r],(e=>{let[r,n]=e;return va(`${t}, ${Oa[r]}`,n)}))}function Ba(t){let e=!St(t),r=En(e?[t]:t,(t=>At(t)&&ma(t.id)?{...t,id:wa(t.id)}:t));return e?r[0]:r}function Va(t){return"obj"!==Ca(t)?t:ja(t,((t,e)=>{return"id"===e?"obj"!==Ca(r=t)?wa(r):ja(r,((t,e)=>["$eq","$ne","$gt","$gte","$lt","$lte","$in","$nin"].indexOf(e)>=0?"arr"===Ca(t)?En(t,wa):wa(t):t)):["$and","$or"].indexOf(e)>=0&&"arr"===Ca(t)?En(t,Va):t;var r}))}function Ha(t){let e=[];return $t(St(t)?t:[t],((t,r)=>{At(t)||e.push({k:r})})),e}function Ya(t){let e=wa(je(t,"id"));return Pr(e)?e:null}function qa(t){let e=[];return $t(St(t)?t:[t],((t,r)=>{let n=je(t,"id");Pr(n)&&ha(n)!==n&&e.push({k:r,id:n})})),e}function Xa(t,e){return va(`${t}, id contains HTML markup`,En(e,(t=>({k:t.k}))))}function Ka(t,e,r,n){let o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"save";if(!xr(t))throw console.log("ds",t),new Error("invalid ds");let i=t[e].keys,a=!1;St(n)||(a=!0,n=[n]);let u=function(){if(!xt(Vn))throw new Error("invalid dayjs");return Vn().format("YYYY-MM-DDTHH:mm:ss.SSSZ")}();if(o.indexOf("insert")>=0&&(i.indexOf("userId")>=0&&$t(n,((t,e)=>{n[e].userId=r})),i.indexOf("timeCreate")>=0&&$t(n,((t,e)=>{n[e].timeCreate=u})),i.indexOf("userIdUpdate")>=0&&$t(n,((t,e)=>{n[e].userIdUpdate=r})),i.indexOf("timeUpdate")>=0&&$t(n,((t,e)=>{n[e].timeUpdate=u}))),(o.indexOf("insert")>=0||o.indexOf("save")>=0)&&(i.indexOf("userIdUpdate")>=0&&$t(n,((t,e)=>{n[e].userIdUpdate=r})),i.indexOf("timeUpdate")>=0&&$t(n,((t,e)=>{n[e].timeUpdate=u}))),n=En(n,(t=>ja(t,(t=>ha(t))))),ba(t[e],i)){(a?xr(n[0]):kr(n))&&$t(n,(t=>{Pr(t.id)||(t.id=Kn())}))}return n=a?n[0]:n}async function Za(t,e,r,n,o,i){try{return await async function(t,e,r,n,o,i){let a,u=null;if(!xr(e))return Promise.reject("invalid woItems");let s=ya(e,n);if(null===s)return Promise.reject(`can not find table[${"string"==typeof n?n:""}] in ORM`);let c=function(t,e){let r=ya(t,e),n=je(r,"keys",null);return!!St(n)&&ba(r,n)}(t,n);if("select"===o){let t=Wa("select",i);if(null!==t)return Ua(`${n}.select invalid find`,i),Promise.reject(t);if(a=await s.select(c?Va(i):i).catch((t=>{console.log(`${n}.select catch`,t),u="failed to select data"})),Pr(u))return Promise.reject(u)}else if("insert"===o||"save"===o){let e=i,l="insert"===o?"failed to insert data":"failed to save data",f=Ha(i);if(Or(f)>0)return console.log(`${n}.${o} data is not an object`,f),Promise.reject(va(`${l}, not an object`,f));let d=Na(l,i);if(Or(d)>0)return console.log(`${n}.${o} data has unsupported key`,d),Promise.reject(zn(d,"; "));c&&(i=Ba(i));let p=qa(i);if(Or(p)>0)return console.log(`${n}.${o} id changed by clearXSS`,p),Promise.reject(Xa(l,p));try{i=Ka(t,n,r,i,o)}catch(t){return console.log(`${n}.adjustData catch`,t.toString()),u="failed to adjust data",Promise.reject(u)}if("insert"===o?a=await s.insert(i).catch((t=>{console.log(`${n}.insert catch`,t),u="failed to insert data"})):"save"===o&&(a=await s.save(i).catch((t=>{console.log(`${n}.save catch`,t),u="failed to save data"}))),Pr(u))return Promise.reject(u);if("save"===o){let t=ga(a,i);if(Or(t)>0)return console.log(`${n}.save fail`,t),Promise.reject(va("failed to save data",ga(a,e)))}a=St(i)?En(i,(t=>({id:t.id}))):{id:i.id}}else if("del"===o){if(c&&(i=Ba(i)),a=await s.del(i).catch((t=>{console.log(`${n}.del catch`,t),u="failed to delete data"})),!Pr(u)){let t=ga(a,i);Or(t)>0&&(console.log(`${n}.del fail`,t),u=va("failed to delete data",t))}}else if("delAll"===o){let t=Wa("delAll",i);if(null!==t)return Ua(`${n}.delAll invalid find`,i),Promise.reject(t);a=await s.delAll(c?Va(i):i).catch((t=>{console.log(`${n}.delAll catch`,t),u="failed to delete data"}))}else if("mix"===o){if(!xr(i))return Promise.reject("invalid input of mix, need the result object of ltdtDiffByKey");for(let t of["add","del","diff"]){let e=Object.getOwnPropertyDescriptor(i,t);if(void 0!==e&&(void 0!==e.get||void 0!==e.set))return Promise.reject(`invalid input of mix, ${Oa.accessor}`)}i={add:i.add,del:i.del,diff:i.diff};for(let t of["add","del","diff"])if(void 0!==i[t]&&!St(i[t]))return Promise.reject("invalid input of mix, need the result object of ltdtDiffByKey");let e=[];for(let[t,r]of[["add","failed to insert data"],["diff","failed to update data"]]){let o=Ha(je(i,t,[]));Or(o)>0&&(console.log(`${n}.mix ${t} data is not an object`,o),e.push(va(`${r}, not an object`,o)))}if(Or(e)>0)return Promise.reject(zn(e,"; "));let o=[];for(let[t,e]of[["add","failed to insert data"],["diff","failed to update data"]])o.push(...Na(e,je(i,t,[])));if(Or(o)>0)return console.log(`${n}.mix data has unsupported key`,o),Promise.reject(zn(o,"; "));if(c){i={...i};for(let t of["add","del","diff"])St(i[t])&&(i[t]=Ba(i[t]))}let l=[];for(let[t,e]of[["add","failed to insert data"],["diff","failed to update data"]]){let r=qa(je(i,t,[]));Or(r)>0&&(console.log(`${n}.mix ${t} id changed by clearXSS`,r),l.push(Xa(e,r)))}if(Or(l)>0)return Promise.reject(zn(l,"; "));let f,d=function(t){let e=[];for(let[r,n]of[["add","del"],["del","diff"]]){let o=new Map;$t(je(t,r,[]),((t,e)=>{let r=Ya(t);null!==r&&o.set(r,[...o.get(r)||[],e])}));let i=[],a=[];if($t(je(t,n,[]),((t,e)=>{let r=Ya(t);null!==r&&o.has(r)&&(i=[...i,...o.get(r)],a.push(e))})),Or(a)>0){let t=[...En([...new Set(i)].sort(((t,e)=>t-e)),(t=>({ref:`${r}[${t}]`}))),...En(a,(t=>({ref:`${n}[${t}]`})))];e.push(va(`invalid input of mix, same id in ${r} and ${n}`,t))}}return e}(i);if(Or(d)>0)return console.log(`${n}.mix same id across steps`,d),Promise.reject(zn(d,"; "));a=[];let p=[],h=je(i,"add",[]);if(Or(h)>0){try{h=Ka(t,n,r,h,"insert+save")}catch(t){return console.log(`${n}.adjustData catch`,t.toString()),u="failed to adjust data",Promise.reject(u)}if(await s.insert(h).catch((t=>{console.log(`${n}.insert catch`,t),u="failed to insert data"})),Pr(u))return Promise.reject(u);f=En(h,(t=>({id:t.id}))),a=[...a,...f]}let g=je(i,"del",[]);if(Or(g)>0){let t=await s.del(g).catch((t=>{console.log(`${n}.del catch`,t),u="failed to delete data"}));if(Pr(u))return Promise.reject(u);let e=ga(t,g);Or(e)>0&&(console.log(`${n}.del fail`,e),p.push(va("failed to delete data",e))),f=En(g,(t=>({id:t.id}))),a=[...a,...f]}let v=je(i,"diff",[]);if(Or(v)>0){let e=v;try{v=Ka(t,n,r,v)}catch(t){return console.log(`${n}.adjustData catch`,t.toString()),u="failed to adjust data",Promise.reject(u)}let o=await s.save(v).catch((t=>{console.log(`${n}.save catch`,t),u="failed to update data"}));if(Pr(u))return Promise.reject(u);let i=ga(o,v);Or(i)>0&&(console.log(`${n}.save fail`,i),p.push(va("failed to update data",ga(o,e)))),f=En(v,(t=>({id:t.id}))),a=[...a,...f]}if(Or(p)>0)return Promise.reject(zn(p,"; "))}else u=`invalid mode: ${o}`;if(Pr(u))return Promise.reject(u);return a}(t,e,r,n,o,i)}catch(t){return"string"==typeof t?Promise.reject(t):(Fa(`${"string"==typeof n?n:""}.${"string"==typeof o?o:""} mapOrm catch`,t),Promise.reject("failed to process input"))}}function Ga(t,e){return async(r,n,o,i)=>Za(t,e,r,n,o,i)}function Ja(t,e,r){let n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(!xt(e)){let o=`${r} needs a function, but got ${typeof e}`;throw n&&t.push((()=>Promise.reject(o))),new Error(o)}setTimeout((()=>{t.push(e)}),1)}function Qa(t){if(Oe(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}),!xt(t))throw new Error("invalid mapOrm");let e={funChecks:[],funPreProcessing:[],funPostProcessing:[],mapOrm:t};return{addFunCheck:t=>{Ja(e.funChecks,t,"addFunCheck",!0)},addFunPreProcessing:t=>{Ja(e.funPreProcessing,t,"addFunPreProcessing")},addFunPostProcessing:t=>{Ja(e.funPostProcessing,t,"addFunPostProcessing")},procOrm:async(t,r,n,o)=>async function(t,e,r,n,o){await kt(t.funChecks,(t=>t({woName:r,userId:e,mode:n,input:o})));for(let i of[...t.funPreProcessing]){let t=await i({woName:r,userId:e,mode:n,input:o});if(!xr(t)||void 0===t.input)return Promise.reject("invalid return of pre-processing, need an object with input");o=t.input}let i=await t.mapOrm(e,r,n,o);for(let a of[...t.funPostProcessing])i=await a({woName:r,userId:e,mode:n,input:o,output:i});return i}(e,t,r,n,o)}}return function(t,e,r,n){let o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};Oe(o);let i=function(t,e,r,n){if(!xr(t))throw console.log("ds",t),new Error("invalid ds");if(!xt(e))throw console.log("WOrm",e),new Error("invalid WOrm");if(!Pr(r))throw console.log("url",r),new Error("invalid url");if(!Pr(n))throw console.log("db",n),new Error("invalid db");let o={};return $t(mt(t),(t=>{let i=new e({url:r,db:n,cl:t});Object.defineProperty(o,t,{value:i,enumerable:!0,writable:!0,configurable:!0})})),o}(t,e,r,n),a=Qa(Ga(t,i),o);return{...Tr,woItems:i,closeAll:async()=>{await kt(i,(async t=>{t&&xt(t.close)&&await t.close()}))},...a}}}));
|
|
6
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("fs"),require("util")):"function"==typeof define&&define.amd?define(["fs","util"],t):(e="undefined"!=typeof globalThis?globalThis:e||self)["w-serv-orm"]=t(e.fs,e.util$2)}(this,(function(e,t){"use strict";function r(e,t,r){var n=-1,o=e.length;t<0&&(t=-t>o?0:o+t),(r=r>o?o:r)<0&&(r+=o),o=t>r?0:r-t>>>0,t>>>=0;for(var i=Array(o);++n<o;)i[n]=e[n+t];return i}var n=/\s/;var o=/^\s+/;function i(e){return e?e.slice(0,function(e){for(var t=e.length;t--&&n.test(e.charAt(t)););return t}(e)+1).replace(o,""):e}function a(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}var u="object"==typeof global&&global&&global.Object===Object&&global,l="object"==typeof self&&self&&self.Object===Object&&self,s=u||l||Function("return this")(),c=s.Symbol,f=Object.prototype,d=f.hasOwnProperty,p=f.toString,h=c?c.toStringTag:void 0;var g=Object.prototype.toString;var y="[object Null]",v="[object Undefined]",b=c?c.toStringTag:void 0;function m(e){return null==e?void 0===e?v:y:b&&b in Object(e)?function(e){var t=d.call(e,h),r=e[h];try{e[h]=void 0;var n=!0}catch(e){}var o=p.call(e);return n&&(t?e[h]=r:delete e[h]),o}(e):function(e){return g.call(e)}(e)}function w(e){return null!=e&&"object"==typeof e}var j="[object Symbol]";function O(e){return"symbol"==typeof e||w(e)&&m(e)==j}var $=NaN,x=/^[-+]0x[0-9a-f]+$/i,k=/^0b[01]+$/i,S=/^0o[0-7]+$/i,A=parseInt;var _=1/0,P=17976931348623157e292;function E(e){return e?(e=function(e){if("number"==typeof e)return e;if(O(e))return $;if(a(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=a(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=i(e);var r=k.test(e);return r||S.test(e)?A(e.slice(2),r?2:8):x.test(e)?$:+e}(e))===_||e===-_?(e<0?-1:1)*P:e==e?e:0:0===e?e:0}function I(e){var t=E(e),r=t%1;return t==t?r?t-r:t:0}function D(e,t){for(var r=-1,n=null==e?0:e.length;++r<n&&!1!==t(e[r],r,e););return e}var M,T=function(e,t,r){for(var n=-1,o=Object(e),i=r(e),a=i.length;a--;){var u=i[M?a:++n];if(!1===t(o[u],u,o))break}return e};function C(e){return w(e)&&"[object Arguments]"==m(e)}var F=Object.prototype,z=F.hasOwnProperty,N=F.propertyIsEnumerable,U=C(function(){return arguments}())?C:function(e){return w(e)&&z.call(e,"callee")&&!N.call(e,"callee")},L=U,W=Array.isArray;var R="object"==typeof exports&&exports&&!exports.nodeType&&exports,B=R&&"object"==typeof module&&module&&!module.nodeType&&module,V=B&&B.exports===R?s.Buffer:void 0,H=(V?V.isBuffer:void 0)||function(){return!1},K=9007199254740991,Y=/^(?:0|[1-9]\d*)$/;function q(e,t){var r=typeof e;return!!(t=null==t?K:t)&&("number"==r||"symbol"!=r&&Y.test(e))&&e>-1&&e%1==0&&e<t}var X=9007199254740991;function J(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=X}var Z={};function G(e){return function(t){return e(t)}}Z["[object Float32Array]"]=Z["[object Float64Array]"]=Z["[object Int8Array]"]=Z["[object Int16Array]"]=Z["[object Int32Array]"]=Z["[object Uint8Array]"]=Z["[object Uint8ClampedArray]"]=Z["[object Uint16Array]"]=Z["[object Uint32Array]"]=!0,Z["[object Arguments]"]=Z["[object Array]"]=Z["[object ArrayBuffer]"]=Z["[object Boolean]"]=Z["[object DataView]"]=Z["[object Date]"]=Z["[object Error]"]=Z["[object Function]"]=Z["[object Map]"]=Z["[object Number]"]=Z["[object Object]"]=Z["[object RegExp]"]=Z["[object Set]"]=Z["[object String]"]=Z["[object WeakMap]"]=!1;var Q="object"==typeof exports&&exports&&!exports.nodeType&&exports,ee=Q&&"object"==typeof module&&module&&!module.nodeType&&module,te=ee&&ee.exports===Q&&u.process,re=function(){try{var e=ee&&ee.require&&ee.require("util").types;return e||te&&te.binding&&te.binding("util")}catch(e){}}(),ne=re&&re.isTypedArray,oe=ne?G(ne):function(e){return w(e)&&J(e.length)&&!!Z[m(e)]},ie=Object.prototype.hasOwnProperty;function ae(e,t){var r=W(e),n=!r&&L(e),o=!r&&!n&&H(e),i=!r&&!n&&!o&&oe(e),a=r||n||o||i,u=a?function(e,t){for(var r=-1,n=Array(e);++r<e;)n[r]=t(r);return n}(e.length,String):[],l=u.length;for(var s in e)!t&&!ie.call(e,s)||a&&("length"==s||o&&("offset"==s||"parent"==s)||i&&("buffer"==s||"byteLength"==s||"byteOffset"==s)||q(s,l))||u.push(s);return u}var ue=Object.prototype;function le(e){var t=e&&e.constructor;return e===("function"==typeof t&&t.prototype||ue)}function se(e,t){return function(r){return e(t(r))}}var ce=se(Object.keys,Object),fe=Object.prototype.hasOwnProperty;function de(e){if(!le(e))return ce(e);var t=[];for(var r in Object(e))fe.call(e,r)&&"constructor"!=r&&t.push(r);return t}var pe="[object AsyncFunction]",he="[object Function]",ge="[object GeneratorFunction]",ye="[object Proxy]";function ve(e){if(!a(e))return!1;var t=m(e);return t==he||t==ge||t==pe||t==ye}function be(e){return null!=e&&J(e.length)&&!ve(e)}function me(e){return be(e)?ae(e):de(e)}var we=function(e,t){return function(r,n){if(null==r)return r;if(!be(r))return e(r,n);for(var o=r.length,i=t?o:-1,a=Object(r);(t?i--:++i<o)&&!1!==n(a[i],i,a););return r}}((function(e,t){return e&&T(e,t,me)})),je=we;function Oe(e){return e}function $e(e,t){var r;return(W(e)?D:je)(e,"function"==typeof(r=t)?r:Oe)}function xe(e){return ve(e)}function ke(e){try{e instanceof Promise&&Promise.prototype.then.call(e,void 0,(()=>{}))}catch(e){}}function Se(e){return"[object Array]"===Object.prototype.toString.call(e)}function Ae(e){return"[object Object]"===Object.prototype.toString.call(e)}function _e(e,t){let n=function(){let e,t,r=new Promise((function(){e=arguments[0],t=arguments[1]}));return r.resolve=e,r.reject=t,r}(),o=!1;try{let t=function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=[],n=!1;try{if(Array.isArray(e)){let t=e.length;r.length=t;for(let n=0;n<t;n++)n in e&&(r[n]=e[n])}else{if(t||!Ae(e)&&!Se(e))return null;{n=!0;let t=Object.keys(e);for(let n=0;n<t.length;n++)r.push({k:t[n],v:e[t[n]]})}}}catch(e){throw r.forEach((e=>{ke(n?e.v:e)})),e}return{items:r,useObj:n}}(e);if(null===t)return n.reject("rs is not an array or object"),n;e=t.items,o=t.useObj}catch(e){return n.reject(e),n}xe(t)||($e(e,(e=>{ke(o?e.v:e)})),t=function(e){return e});let i=xe(t),a=-1,u=[];return e.reduce((function(e,r){return e.then((function(e){u.push(e),a+=1;let n=a,l=r;return o&&(n=r.k,l=r.v),i?t(l,n):l}))}),Promise.resolve()).then((function(e){var t,o,i,a;u.push(e),a=null==(t=u)?0:t.length,u=a?r(t,(o=i||void 0===o?1:I(o))<0?0:o,a):[],n.resolve(u)})).catch((function(e){n.reject(e)})),n}var Pe=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Ee=/^\w*$/;function Ie(e,t){if(W(e))return!1;var r=typeof e;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=e&&!O(e))||(Ee.test(e)||!Pe.test(e)||null!=t&&e in Object(t))}var De,Me=s["__core-js_shared__"],Te=(De=/[^.]+$/.exec(Me&&Me.keys&&Me.keys.IE_PROTO||""))?"Symbol(src)_1."+De:"";var Ce=Function.prototype.toString;function Fe(e){if(null!=e){try{return Ce.call(e)}catch(e){}try{return e+""}catch(e){}}return""}var ze=/^\[object .+?Constructor\]$/,Ne=Function.prototype,Ue=Object.prototype,Le=Ne.toString,We=Ue.hasOwnProperty,Re=RegExp("^"+Le.call(We).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Be(e){return!(!a(e)||(t=e,Te&&Te in t))&&(ve(e)?Re:ze).test(Fe(e));var t}function Ve(e,t){var r=function(e,t){return null==e?void 0:e[t]}(e,t);return Be(r)?r:void 0}var He=Ve(Object,"create");var Ke=Object.prototype.hasOwnProperty;var Ye=Object.prototype.hasOwnProperty;function qe(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function Xe(e,t){return e===t||e!=e&&t!=t}function Je(e,t){for(var r=e.length;r--;)if(Xe(e[r][0],t))return r;return-1}qe.prototype.clear=function(){this.__data__=He?He(null):{},this.size=0},qe.prototype.delete=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},qe.prototype.get=function(e){var t=this.__data__;if(He){var r=t[e];return"__lodash_hash_undefined__"===r?void 0:r}return Ke.call(t,e)?t[e]:void 0},qe.prototype.has=function(e){var t=this.__data__;return He?void 0!==t[e]:Ye.call(t,e)},qe.prototype.set=function(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=He&&void 0===t?"__lodash_hash_undefined__":t,this};var Ze=Array.prototype.splice;function Ge(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}Ge.prototype.clear=function(){this.__data__=[],this.size=0},Ge.prototype.delete=function(e){var t=this.__data__,r=Je(t,e);return!(r<0)&&(r==t.length-1?t.pop():Ze.call(t,r,1),--this.size,!0)},Ge.prototype.get=function(e){var t=this.__data__,r=Je(t,e);return r<0?void 0:t[r][1]},Ge.prototype.has=function(e){return Je(this.__data__,e)>-1},Ge.prototype.set=function(e,t){var r=this.__data__,n=Je(r,e);return n<0?(++this.size,r.push([e,t])):r[n][1]=t,this};var Qe=Ve(s,"Map");function et(e,t){var r,n,o=e.__data__;return("string"==(n=typeof(r=t))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof t?"string":"hash"]:o.map}function tt(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}tt.prototype.clear=function(){this.size=0,this.__data__={hash:new qe,map:new(Qe||Ge),string:new qe}},tt.prototype.delete=function(e){var t=et(this,e).delete(e);return this.size-=t?1:0,t},tt.prototype.get=function(e){return et(this,e).get(e)},tt.prototype.has=function(e){return et(this,e).has(e)},tt.prototype.set=function(e,t){var r=et(this,e),n=r.size;return r.set(e,t),this.size+=r.size==n?0:1,this};var rt="Expected a function";function nt(e,t){if("function"!=typeof e||null!=t&&"function"!=typeof t)throw new TypeError(rt);var r=function(){var n=arguments,o=t?t.apply(this,n):n[0],i=r.cache;if(i.has(o))return i.get(o);var a=e.apply(this,n);return r.cache=i.set(o,a)||i,a};return r.cache=new(nt.Cache||tt),r}nt.Cache=tt;var ot,it,at,ut=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,lt=/\\(\\)?/g,st=(ot=function(e){var t=[];return 46===e.charCodeAt(0)&&t.push(""),e.replace(ut,(function(e,r,n,o){t.push(n?o.replace(lt,"$1"):r||e)})),t},it=nt(ot,(function(e){return 500===at.size&&at.clear(),e})),at=it.cache,it),ct=st;function ft(e,t){for(var r=-1,n=null==e?0:e.length,o=Array(n);++r<n;)o[r]=t(e[r],r,e);return o}var dt=1/0,pt=c?c.prototype:void 0,ht=pt?pt.toString:void 0;function gt(e){if("string"==typeof e)return e;if(W(e))return ft(e,gt)+"";if(O(e))return ht?ht.call(e):"";var t=e+"";return"0"==t&&1/e==-dt?"-0":t}function yt(e){return null==e?"":gt(e)}function vt(e,t){return W(e)?e:Ie(e,t)?[e]:ct(yt(e))}var bt=1/0;function mt(e){if("string"==typeof e||O(e))return e;var t=e+"";return"0"==t&&1/e==-bt?"-0":t}function wt(e,t){for(var r=0,n=(t=vt(t,e)).length;null!=e&&r<n;)e=e[mt(t[r++])];return r&&r==n?e:void 0}function jt(e,t,r){var n=null==e?void 0:wt(e,t);return void 0===n?r:n}function Ot(e){let t="procOrm does not authorize users, authorize where procOrm is exposed to clients",r=[["useCheckUser",t],["getUserById",t],["useExcludeWhenNotAdmin","procOrm does not filter select results by user, use addFunPostProcessing if needed"]];for(let[t,n]of r){let r=jt(e,t);if(null!=r&&!1!==r)throw new Error(`opt.${t} has been removed, ${n}`)}}const $t="h1",xt=Object.freeze({mismatch:"baselineMismatch",rowNotFound:"rowNotFound",format:"baselineFormat"}),kt=14,St=100,At=1e5,_t=["table","pk","fields","serverOnly","orderKey","scope"];function Pt(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Et(e){return Object.prototype.toString.call(e)}function It(e){if(null===e||"object"!=typeof e||"[object Object]"!==Et(e))return!1;let t=Object.getPrototypeOf(e);return null===t||null===Object.getPrototypeOf(t)}function Dt(e){return"string"==typeof e&&""!==e}function Mt(e,t){let r=new Error(t);return r.key=e,r}function Tt(e,t,r){if(!Array.isArray(e)||!r&&0===e.length)throw new Error(`invalid contract: ${t} needs ${r?"an array":"a non-empty array"}`);let n=new Set;for(let r=0;r<e.length;r++){if(!Dt(e[r]))throw new Error(`invalid contract: ${t}[${r}] needs a non-empty string`);if(n.has(e[r]))throw new Error(`invalid contract: ${t} has a duplicate name at [${r}]`);n.add(e[r])}}function Ct(e){if(!It(e))throw new Error("invalid contract: need an object");for(let t of Reflect.ownKeys(e))if(_t.indexOf(t)<0)throw new Error("invalid contract: unsupported key");if(!Dt(e.pk))throw new Error("invalid contract: pk needs a non-empty string");if(Tt(e.fields,"fields",!1),void 0!==e.serverOnly&&null!==e.serverOnly){Tt(e.serverOnly,"serverOnly",!0);for(let t of e.serverOnly)if(e.fields.indexOf(t)>=0)throw new Error("invalid contract: serverOnly and fields must not overlap")}if(void 0!==e.orderKey&&null!==e.orderKey){if(!Dt(e.orderKey))throw new Error("invalid contract: orderKey needs a non-empty string");if(e.fields.indexOf(e.orderKey)>=0)throw new Error("invalid contract: fields must not contain orderKey");if(e.orderKey===e.pk)throw new Error("invalid contract: orderKey must not be pk")}if(void 0!==e.scope&&null!==e.scope&&"function"!=typeof e.scope)throw new Error("invalid contract: scope needs a function");if(void 0!==e.table&&null!==e.table&&!Dt(e.table))throw new Error("invalid contract: table needs a non-empty string");return!0}function Ft(e,t,r,n){if(t.n+=1,t.n>At)throw new Error(`unsupported value of ${n}: too many nodes`);if(r>St)throw new Error(`unsupported value of ${n}: too deep or circular`);let o=typeof e;if(null==e)return"null";if("string"===o)return JSON.stringify(e);if("boolean"===o)return e?"true":"false";if("number"===o){if(!isFinite(e))throw new Error(`unsupported value of ${n}: non-finite number`);return JSON.stringify(e)}if("bigint"===o)return JSON.stringify(e.toString());if("object"===o){if(Array.isArray(e)){let o=Object.keys(e);for(let t=0;t<o.length;t++){let r=Number(o[t]);if(!(String(r)===o[t]&&r>=0&&r<e.length&&Math.floor(r)===r))throw new Error(`unsupported value of ${n}: array with extra properties`)}let i=[];for(let o=0;o<e.length;o++)i.push(Ft(e[o],t,r+1,n));return"["+i.join(",")+"]"}let o=Et(e);if("[object Date]"===o){let t;try{t=Date.prototype.toISOString.call(e)}catch(e){throw new Error(`unsupported value of ${n}: invalid Date`)}return JSON.stringify(t)}if(It(e)){let o=Object.keys(e).sort(),i=[];for(let a=0;a<o.length;a++){let u=e[o[a]];void 0!==u&&i.push(JSON.stringify(o[a])+":"+Ft(u,t,r+1,n))}return"{"+i.join(",")+"}"}throw new Error(`unsupported value of ${n}: ${o}`)}throw new Error(`unsupported value of ${n}: ${o}`)}function zt(e,t,r){return null==e||""===e?"null":Ft(e,t,0,r)}function Nt(e){return null!==e&&"object"==typeof e&&"[object Object]"===Et(e)}function Ut(e,t){if(!Nt(e))throw new Error("invalid row: need an object");let r=[],n={n:0};for(let o=0;o<t.length;o++){let i=t[o];r.push(zt(Pt(e,i)?e[i]:void 0,n,`field[${i}]`))}let o=function(e,t){let r="number"==typeof t?t:0,n=3735928559^r,o=1103547991^r;for(let t=0;t<e.length;t++){let r=e.charCodeAt(t);n=Math.imul(n^r,2654435761),o=Math.imul(o^r,1597334677)}return n=Math.imul(n^n>>>16,2246822507)^Math.imul(o^o>>>13,3266489909),o=Math.imul(o^o>>>16,2246822507)^Math.imul(n^n>>>13,3266489909),4294967296*(2097151&o)+(n>>>0)}("["+r.join(",")+"]").toString(16);for(;o.length<kt;)o="0"+o;return $t+":"+o}function Lt(e,t){let r=Pt(e,t)?e[t]:void 0;return"string"==typeof r?""===r?null:r:"number"==typeof r&&isFinite(r)?String(r):"bigint"==typeof r?r.toString():null}function Wt(e,t){let r=Pt(e,t)?e[t]:void 0;if("number"==typeof r)return isFinite(r)?r:1/0;if("bigint"==typeof r)return r;if("string"==typeof r){let e=r.trim();if(""===e)return 1/0;if("function"==typeof BigInt&&/^[+-]?\d+$/.test(e))return BigInt(e);let t=Number(e);return isFinite(t)?t:1/0}return 1/0}function Rt(e,t,r){if(Ct(r),!function(e){if(!Array.isArray(e))return!1;let t=new RegExp("^"+$t+":[0-9a-f]{"+kt+"}$"),r=new Set;for(let n=0;n<e.length;n++){let o=e[n];if(!Array.isArray(o)||2!==o.length||!Dt(o[0])||"string"!=typeof o[1]||!t.test(o[1]))return!1;if(r.has(o[0]))return!1;r.add(o[0])}return!0}(t))return{ok:!1,reason:xt.format,added:[],removed:[],changed:[],reordered:!1};let n;try{n=function(e,t){if(Ct(t),!Array.isArray(e))throw new Error("invalid rows: need an array");let r=t.fields,n="function"==typeof t.scope,o=Dt(t.orderKey),i=[],a=new Set;for(let u=0;u<e.length;u++){let l=e[u];if(!Nt(l))throw new Error(`invalid row: rows[${u}] needs an object`);if(n&&!t.scope(l))continue;let s=Lt(l,t.pk);if(null===s)throw Mt(xt.format,`invalid row: rows[${u}] has no valid primary key`);if(a.has(s))throw Mt(xt.format,`invalid row: rows[${u}] has a duplicate primary key`);a.add(s),i.push({id:s,o:o?Wt(l,t.orderKey):0,d:Ut(l,r)})}return i.sort(((e,t)=>e.o<t.o?-1:e.o>t.o?1:e.id!==t.id?e.id<t.id?-1:1:0)),i.map((e=>[e.id,e.d]))}(e,r)}catch(e){if(null!==e&&"object"==typeof e&&e.key===xt.format){let t=new Error(`invalid rowsNow: ${e.message}`);throw t.key="rowsInvalid",t}throw e}let o=new Map(t),i=new Map(n),a=[],u=[],l=[];for(let[e]of t)i.has(e)||u.push(e);for(let[e,t]of n)o.has(e)?o.get(e)!==t&&l.push(e):a.push(e);let s=t.map((e=>e[0])).filter((e=>i.has(e))),c=n.map((e=>e[0])).filter((e=>o.has(e))),f=!1;for(let e=0;e<s.length;e++)if(s[e]!==c[e]){f=!0;break}if(0===a.length&&0===u.length&&0===l.length&&!f)return{ok:!0};let d=xt.mismatch;return 1===t.length&&1===u.length&&0===a.length&&(d=xt.rowNotFound),{ok:!1,reason:d,added:a,removed:u,changed:l,reordered:f}}function Bt(e,t,n){var o=e.length;return n=void 0===n?o:n,!t&&n>=o?e:r(e,t,n)}function Vt(e){return e!=e}function Ht(e,t,r){return t==t?function(e,t,r){for(var n=r-1,o=e.length;++n<o;)if(e[n]===t)return n;return-1}(e,t,r):function(e,t,r,n){for(var o=e.length,i=r+(n?1:-1);n?i--:++i<o;)if(t(e[i],i,e))return i;return-1}(e,Vt,r)}var Kt=RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]");function Yt(e){return Kt.test(e)}var qt="\\ud800-\\udfff",Xt="["+qt+"]",Jt="[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]",Zt="\\ud83c[\\udffb-\\udfff]",Gt="[^"+qt+"]",Qt="(?:\\ud83c[\\udde6-\\uddff]){2}",er="[\\ud800-\\udbff][\\udc00-\\udfff]",tr="(?:"+Jt+"|"+Zt+")"+"?",rr="[\\ufe0e\\ufe0f]?",nr=rr+tr+("(?:\\u200d(?:"+[Gt,Qt,er].join("|")+")"+rr+tr+")*"),or="(?:"+[Gt+Jt+"?",Jt,Qt,er,Xt].join("|")+")",ir=RegExp(Zt+"(?="+Zt+")|"+or+nr,"g");function ar(e){return Yt(e)?function(e){return e.match(ir)||[]}(e):function(e){return e.split("")}(e)}function ur(e,t,r){if((e=yt(e))&&(r||void 0===t))return i(e);if(!e||!(t=gt(t)))return e;var n=ar(e),o=ar(t),a=function(e,t){for(var r=-1,n=e.length;++r<n&&Ht(t,e[r],0)>-1;);return r}(n,o),u=function(e,t){for(var r=e.length;r--&&Ht(t,e[r],0)>-1;);return r}(n,o)+1;return Bt(n,a,u).join("")}var lr=Ve(s,"DataView"),sr=Ve(s,"Promise"),cr=Ve(s,"Set"),fr=Ve(s,"WeakMap"),dr="[object Map]",pr="[object Promise]",hr="[object Set]",gr="[object WeakMap]",yr="[object DataView]",vr=Fe(lr),br=Fe(Qe),mr=Fe(sr),wr=Fe(cr),jr=Fe(fr),Or=m;(lr&&Or(new lr(new ArrayBuffer(1)))!=yr||Qe&&Or(new Qe)!=dr||sr&&Or(sr.resolve())!=pr||cr&&Or(new cr)!=hr||fr&&Or(new fr)!=gr)&&(Or=function(e){var t=m(e),r="[object Object]"==t?e.constructor:void 0,n=r?Fe(r):"";if(n)switch(n){case vr:return yr;case br:return dr;case mr:return pr;case wr:return hr;case jr:return gr}return t});var $r=Or,xr="[object String]";function kr(e){return function(t){return null==t?void 0:t[e]}}var Sr=kr("length"),Ar="\\ud800-\\udfff",_r="["+Ar+"]",Pr="[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]",Er="\\ud83c[\\udffb-\\udfff]",Ir="[^"+Ar+"]",Dr="(?:\\ud83c[\\udde6-\\uddff]){2}",Mr="[\\ud800-\\udbff][\\udc00-\\udfff]",Tr="(?:"+Pr+"|"+Er+")"+"?",Cr="[\\ufe0e\\ufe0f]?",Fr=Cr+Tr+("(?:\\u200d(?:"+[Ir,Dr,Mr].join("|")+")"+Cr+Tr+")*"),zr="(?:"+[Ir+Pr+"?",Pr,Dr,Mr,_r].join("|")+")",Nr=RegExp(Er+"(?="+Er+")|"+zr+Fr,"g");function Ur(e){return Yt(e)?function(e){for(var t=Nr.lastIndex=0;Nr.test(e);)++t;return t}(e):Sr(e)}var Lr="[object Map]",Wr="[object Set]";function Rr(e){if(null==e)return 0;if(be(e))return"string"==typeof(t=e)||!W(t)&&w(t)&&m(t)==xr?Ur(e):e.length;var t,r=$r(e);return r==Lr||r==Wr?e.size:de(e).length}function Br(e){let t=jt(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},"fs");return!!function(e){let t=jt(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},"fs"),r=!1;try{t.statSync(e),r=!0}catch{r=!1}return r}(e,{fs:t})&&(!t.lstatSync(e).isDirectory()&&!t.lstatSync(e).isSymbolicLink())}function Vr(e){if(Ae(e)){for(let t in e)return!0;return!1}return!1}function Hr(e){return"[object String]"===Object.prototype.toString.call(e)}function Kr(e){if(e!=e)return!0;if(null!==e&&"object"==typeof e)try{let t=Number.prototype.valueOf.call(e);return Number.isNaN(t)}catch(e){return!1}return!1}function Yr(e){return!!function(e){return"[object Undefined]"===Object.prototype.toString.call(e)}(e)||(!!function(e){return"[object Null]"===Object.prototype.toString.call(e)}(e)||(!!function(e){if(Ae(e)){for(let t in e)return!1;return!0}return!1}(e)||(!!function(e){return!(!Hr(e)||0!==e.length)}(e)||(!!function(e){return!!Se(e)&&0===e.length}(e)||!!Kr(e)))))}function qr(e){return!!Se(e)&&(0!==e.length&&(1!==e.length||!Yr(e[0])))}function Xr(e){return!!(Hr(e)&&e.length>0)}var Jr="[object Boolean]";function Zr(e){return!0===(t=e)||!1===t||w(t)&&m(t)==Jr;var t}let Gr={backup:async function(e){if(!Vr(e))throw console.log("woItems",e),new Error("invalid woItems");return await _e(e,(async(e,t)=>(console.log("backup...",t),{name:t,data:await e.select()})))},recover:async function(t,r,n){let o=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(!Br(t,{fs:e}))throw console.log("fp",t),new Error("fp is not exist");if(!Vr(r))throw console.log("woItems",r),new Error("invalid woItems");xe(n)||(n=null),Zr(o)||(o=!1);let i=e.readFileSync(t,"utf8");i=ur(i);let a=function(e){let t=jt(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},"returnWithStateAndMsg",null);Zr(t)||(t=!1);let r=e=>t?{state:"error",msg:e}:{};if(!Xr(e))return r("invalid v");let n={};try{n=JSON.parse(e)}catch(e){return r(e.toString())}return t?{state:"success",msg:n}:n}(i);if(!qr(a))throw new Error("invalid backup data, need a non-empty array");$e(a,((e,t)=>{let n=jt(e,"name");if(!Xr(n))throw new Error(`invalid backup data, rs[${t}].name is not a string`);if(!Object.prototype.hasOwnProperty.call(r,n))throw new Error(`invalid backup data, table[${n}] is not in woItems`)})),xe(n)&&n(),await _e(a,(async e=>{console.log("recover...",e.name),o&&(console.log("needCreateStorage"),await r[e.name].createStorage());let t=null;return Rr(e.data)>0&&(t=await r[e.name].insert(e.data)),t}))}};function Qr(e){var t=this.__data__=new Ge(e);this.size=t.size}Qr.prototype.clear=function(){this.__data__=new Ge,this.size=0},Qr.prototype.delete=function(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r},Qr.prototype.get=function(e){return this.__data__.get(e)},Qr.prototype.has=function(e){return this.__data__.has(e)},Qr.prototype.set=function(e,t){var r=this.__data__;if(r instanceof Ge){var n=r.__data__;if(!Qe||n.length<199)return n.push([e,t]),this.size=++r.size,this;r=this.__data__=new tt(n)}return r.set(e,t),this.size=r.size,this};function en(e){var t=-1,r=null==e?0:e.length;for(this.__data__=new tt;++t<r;)this.add(e[t])}function tn(e,t){for(var r=-1,n=null==e?0:e.length;++r<n;)if(t(e[r],r,e))return!0;return!1}function rn(e,t){return e.has(t)}en.prototype.add=en.prototype.push=function(e){return this.__data__.set(e,"__lodash_hash_undefined__"),this},en.prototype.has=function(e){return this.__data__.has(e)};var nn=1,on=2;function an(e,t,r,n,o,i){var a=r&nn,u=e.length,l=t.length;if(u!=l&&!(a&&l>u))return!1;var s=i.get(e),c=i.get(t);if(s&&c)return s==t&&c==e;var f=-1,d=!0,p=r&on?new en:void 0;for(i.set(e,t),i.set(t,e);++f<u;){var h=e[f],g=t[f];if(n)var y=a?n(g,h,f,t,e,i):n(h,g,f,e,t,i);if(void 0!==y){if(y)continue;d=!1;break}if(p){if(!tn(t,(function(e,t){if(!rn(p,t)&&(h===e||o(h,e,r,n,i)))return p.push(t)}))){d=!1;break}}else if(h!==g&&!o(h,g,r,n,i)){d=!1;break}}return i.delete(e),i.delete(t),d}var un=s.Uint8Array;function ln(e){var t=-1,r=Array(e.size);return e.forEach((function(e,n){r[++t]=[n,e]})),r}function sn(e){var t=-1,r=Array(e.size);return e.forEach((function(e){r[++t]=e})),r}var cn=1,fn=2,dn="[object Boolean]",pn="[object Date]",hn="[object Error]",gn="[object Map]",yn="[object Number]",vn="[object RegExp]",bn="[object Set]",mn="[object String]",wn="[object Symbol]",jn="[object ArrayBuffer]",On="[object DataView]",$n=c?c.prototype:void 0,xn=$n?$n.valueOf:void 0;function kn(e,t){for(var r=-1,n=t.length,o=e.length;++r<n;)e[o+r]=t[r];return e}function Sn(e,t,r){var n=t(e);return W(e)?n:kn(n,r(e))}function An(){return[]}var _n=Object.prototype.propertyIsEnumerable,Pn=Object.getOwnPropertySymbols,En=Pn?function(e){return null==e?[]:(e=Object(e),function(e,t){for(var r=-1,n=null==e?0:e.length,o=0,i=[];++r<n;){var a=e[r];t(a,r,e)&&(i[o++]=a)}return i}(Pn(e),(function(t){return _n.call(e,t)})))}:An,In=En;function Dn(e){return Sn(e,me,In)}var Mn=1,Tn=Object.prototype.hasOwnProperty;var Cn=1,Fn="[object Arguments]",zn="[object Array]",Nn="[object Object]",Un=Object.prototype.hasOwnProperty;function Ln(e,t,r,n,o,i){var a=W(e),u=W(t),l=a?zn:$r(e),s=u?zn:$r(t),c=(l=l==Fn?Nn:l)==Nn,f=(s=s==Fn?Nn:s)==Nn,d=l==s;if(d&&H(e)){if(!H(t))return!1;a=!0,c=!1}if(d&&!c)return i||(i=new Qr),a||oe(e)?an(e,t,r,n,o,i):function(e,t,r,n,o,i,a){switch(r){case On:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case jn:return!(e.byteLength!=t.byteLength||!i(new un(e),new un(t)));case dn:case pn:case yn:return Xe(+e,+t);case hn:return e.name==t.name&&e.message==t.message;case vn:case mn:return e==t+"";case gn:var u=ln;case bn:var l=n&cn;if(u||(u=sn),e.size!=t.size&&!l)return!1;var s=a.get(e);if(s)return s==t;n|=fn,a.set(e,t);var c=an(u(e),u(t),n,o,i,a);return a.delete(e),c;case wn:if(xn)return xn.call(e)==xn.call(t)}return!1}(e,t,l,r,n,o,i);if(!(r&Cn)){var p=c&&Un.call(e,"__wrapped__"),h=f&&Un.call(t,"__wrapped__");if(p||h){var g=p?e.value():e,y=h?t.value():t;return i||(i=new Qr),o(g,y,r,n,i)}}return!!d&&(i||(i=new Qr),function(e,t,r,n,o,i){var a=r&Mn,u=Dn(e),l=u.length;if(l!=Dn(t).length&&!a)return!1;for(var s=l;s--;){var c=u[s];if(!(a?c in t:Tn.call(t,c)))return!1}var f=i.get(e),d=i.get(t);if(f&&d)return f==t&&d==e;var p=!0;i.set(e,t),i.set(t,e);for(var h=a;++s<l;){var g=e[c=u[s]],y=t[c];if(n)var v=a?n(y,g,c,t,e,i):n(g,y,c,e,t,i);if(!(void 0===v?g===y||o(g,y,r,n,i):v)){p=!1;break}h||(h="constructor"==c)}if(p&&!h){var b=e.constructor,m=t.constructor;b==m||!("constructor"in e)||!("constructor"in t)||"function"==typeof b&&b instanceof b&&"function"==typeof m&&m instanceof m||(p=!1)}return i.delete(e),i.delete(t),p}(e,t,r,n,o,i))}function Wn(e,t,r,n,o){return e===t||(null==e||null==t||!w(e)&&!w(t)?e!=e&&t!=t:Ln(e,t,r,n,Wn,o))}var Rn=1,Bn=2;function Vn(e){return e==e&&!a(e)}function Hn(e,t){return function(r){return null!=r&&(r[e]===t&&(void 0!==t||e in Object(r)))}}function Kn(e){var t=function(e){for(var t=me(e),r=t.length;r--;){var n=t[r],o=e[n];t[r]=[n,o,Vn(o)]}return t}(e);return 1==t.length&&t[0][2]?Hn(t[0][0],t[0][1]):function(r){return r===e||function(e,t,r,n){var o=r.length,i=o,a=!n;if(null==e)return!i;for(e=Object(e);o--;){var u=r[o];if(a&&u[2]?u[1]!==e[u[0]]:!(u[0]in e))return!1}for(;++o<i;){var l=(u=r[o])[0],s=e[l],c=u[1];if(a&&u[2]){if(void 0===s&&!(l in e))return!1}else{var f=new Qr;if(n)var d=n(s,c,l,e,t,f);if(!(void 0===d?Wn(c,s,Rn|Bn,n,f):d))return!1}}return!0}(r,e,t)}}function Yn(e,t){return null!=e&&t in Object(e)}function qn(e,t){return null!=e&&function(e,t,r){for(var n=-1,o=(t=vt(t,e)).length,i=!1;++n<o;){var a=mt(t[n]);if(!(i=null!=e&&r(e,a)))break;e=e[a]}return i||++n!=o?i:!!(o=null==e?0:e.length)&&J(o)&&q(a,o)&&(W(e)||L(e))}(e,t,Yn)}var Xn=1,Jn=2;function Zn(e){return Ie(e)?kr(mt(e)):function(e){return function(t){return wt(t,e)}}(e)}function Gn(e){return"function"==typeof e?e:null==e?Oe:"object"==typeof e?W(e)?(t=e[0],r=e[1],Ie(t)&&Vn(r)?Hn(mt(t),r):function(e){var n=jt(e,t);return void 0===n&&n===r?qn(e,t):Wn(r,n,Xn|Jn)}):Kn(e):Zn(e);var t,r}function Qn(e,t){var r=-1,n=be(e)?Array(e.length):[];return je(e,(function(e,o,i){n[++r]=t(e,o,i)})),n}function eo(e,t){return(W(e)?ft:Qn)(e,Gn(t))}var to=Array.prototype.join;function ro(e,t){return null==e?"":to.call(e,t)}var no=re&&re.isRegExp,oo=no?G(no):function(e){return w(e)&&"[object RegExp]"==m(e)},io=30,ao="...",uo=/\w*$/;function lo(e,t){var r=io,n=ao;if(a(t)){var o="separator"in t?t.separator:o;r="length"in t?I(t.length):r,n="omission"in t?gt(t.omission):n}var i=(e=yt(e)).length;if(Yt(e)){var u=ar(e);i=u.length}if(r>=i)return e;var l=r-Ur(n);if(l<1)return n;var s=u?Bt(u,0,l).join(""):e.slice(0,l);if(void 0===o)return s+n;if(u&&(l+=s.length-l),oo(o)){if(e.slice(l).search(o)){var c,f=s;for(o.global||(o=RegExp(o.source,yt(uo.exec(o))+"g")),o.lastIndex=0;c=o.exec(f);)var d=c.index;s=s.slice(0,void 0===d?l:d)}}else if(e.indexOf(gt(o),l)!=l){var p=s.lastIndexOf(o);p>-1&&(s=s.slice(0,p))}return s+n}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var so={};!function(e,t){e.exports=function(){var e=1e3,t=6e4,r=36e5,n="millisecond",o="second",i="minute",a="hour",u="day",l="week",s="month",c="quarter",f="year",d="date",p="Invalid Date",h=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,g=/\[([^\]]+)]|YYYY|YY|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,y={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(e){var t=["th","st","nd","rd"],r=e%100;return"["+e+(t[(r-20)%10]||t[r]||t[0])+"]"}},v=function(e,t,r){var n=String(e);return!n||n.length>=t?e:""+Array(t+1-n.length).join(r)+e},b={s:v,z:function(e){var t=-e.utcOffset(),r=Math.abs(t),n=Math.floor(r/60),o=r%60;return(t<=0?"+":"-")+v(n,2,"0")+":"+v(o,2,"0")},m:function e(t,r){if(t.date()<r.date())return-e(r,t);var n=12*(r.year()-t.year())+(r.month()-t.month()),o=t.clone().add(n,s),i=r-o<0,a=t.clone().add(n+(i?-1:1),s);return+(-(n+(r-o)/(i?o-a:a-o))||0)},a:function(e){return e<0?Math.ceil(e)||0:Math.floor(e)},p:function(e){return{M:s,y:f,w:l,d:u,D:d,h:a,m:i,s:o,ms:n,Q:c}[e]||String(e||"").toLowerCase().replace(/s$/,"")},u:function(e){return void 0===e}},m="en",w={};w[m]=y;var j="$isDayjsObject",O=function(e){return e instanceof S||!(!e||!e[j])},$=function e(t,r,n){var o;if(!t)return m;if("string"==typeof t){var i=t.toLowerCase();w[i]&&(o=i),r&&(w[i]=r,o=i);var a=t.split("-");if(!o&&a.length>1)return e(a[0])}else{var u=t.name;w[u]=t,o=u}return!n&&o&&(m=o),o||!n&&m},x=function(e,t){if(O(e))return e.clone();var r="object"==typeof t?t:{};return r.date=e,r.args=arguments,new S(r)},k=b;k.l=$,k.i=O,k.w=function(e,t){return x(e,{locale:t.$L,utc:t.$u,x:t.$x,$offset:t.$offset})};var S=function(){function y(e){this.$L=$(e.locale,null,!0),this.parse(e),this.$x=this.$x||e.x||{},this[j]=!0}var v=y.prototype;return v.parse=function(e){this.$d=function(e){var t=e.date,r=e.utc;if(null===t)return new Date(NaN);if(k.u(t))return new Date;if(t instanceof Date)return new Date(t);if("string"==typeof t&&!/Z$/i.test(t)){var n=t.match(h);if(n){var o=n[2]-1||0,i=(n[7]||"0").substring(0,3);return r?new Date(Date.UTC(n[1],o,n[3]||1,n[4]||0,n[5]||0,n[6]||0,i)):new Date(n[1],o,n[3]||1,n[4]||0,n[5]||0,n[6]||0,i)}}return new Date(t)}(e),this.init()},v.init=function(){var e=this.$d;this.$y=e.getFullYear(),this.$M=e.getMonth(),this.$D=e.getDate(),this.$W=e.getDay(),this.$H=e.getHours(),this.$m=e.getMinutes(),this.$s=e.getSeconds(),this.$ms=e.getMilliseconds()},v.$utils=function(){return k},v.isValid=function(){return!(this.$d.toString()===p)},v.isSame=function(e,t){var r=x(e);return this.startOf(t)<=r&&r<=this.endOf(t)},v.isAfter=function(e,t){return x(e)<this.startOf(t)},v.isBefore=function(e,t){return this.endOf(t)<x(e)},v.$g=function(e,t,r){return k.u(e)?this[t]:this.set(r,e)},v.unix=function(){return Math.floor(this.valueOf()/1e3)},v.valueOf=function(){return this.$d.getTime()},v.startOf=function(e,t){var r=this,n=!!k.u(t)||t,c=k.p(e),p=function(e,t){var o=k.w(r.$u?Date.UTC(r.$y,t,e):new Date(r.$y,t,e),r);return n?o:o.endOf(u)},h=function(e,t){return k.w(r.toDate()[e].apply(r.toDate("s"),(n?[0,0,0,0]:[23,59,59,999]).slice(t)),r)},g=this.$W,y=this.$M,v=this.$D,b="set"+(this.$u?"UTC":"");switch(c){case f:return n?p(1,0):p(31,11);case s:return n?p(1,y):p(0,y+1);case l:var m=this.$locale().weekStart||0,w=(g<m?g+7:g)-m;return p(n?v-w:v+(6-w),y);case u:case d:return h(b+"Hours",0);case a:return h(b+"Minutes",1);case i:return h(b+"Seconds",2);case o:return h(b+"Milliseconds",3);default:return this.clone()}},v.endOf=function(e){return this.startOf(e,!1)},v.$set=function(e,t){var r,l=k.p(e),c="set"+(this.$u?"UTC":""),p=(r={},r[u]=c+"Date",r[d]=c+"Date",r[s]=c+"Month",r[f]=c+"FullYear",r[a]=c+"Hours",r[i]=c+"Minutes",r[o]=c+"Seconds",r[n]=c+"Milliseconds",r)[l],h=l===u?this.$D+(t-this.$W):t;if(l===s||l===f){var g=this.clone().set(d,1);g.$d[p](h),g.init(),this.$d=g.set(d,Math.min(this.$D,g.daysInMonth())).$d}else p&&this.$d[p](h);return this.init(),this},v.set=function(e,t){return this.clone().$set(e,t)},v.get=function(e){return this[k.p(e)]()},v.add=function(n,c){var d,p=this;n=Number(n);var h=k.p(c),g=function(e){var t=x(p);return k.w(t.date(t.date()+Math.round(e*n)),p)};if(h===s)return this.set(s,this.$M+n);if(h===f)return this.set(f,this.$y+n);if(h===u)return g(1);if(h===l)return g(7);var y=(d={},d[i]=t,d[a]=r,d[o]=e,d)[h]||1,v=this.$d.getTime()+n*y;return k.w(v,this)},v.subtract=function(e,t){return this.add(-1*e,t)},v.format=function(e){var t=this,r=this.$locale();if(!this.isValid())return r.invalidDate||p;var n=e||"YYYY-MM-DDTHH:mm:ssZ",o=k.z(this),i=this.$H,a=this.$m,u=this.$M,l=r.weekdays,s=r.months,c=r.meridiem,f=function(e,r,o,i){return e&&(e[r]||e(t,n))||o[r].slice(0,i)},d=function(e){return k.s(i%12||12,e,"0")},h=c||function(e,t,r){var n=e<12?"AM":"PM";return r?n.toLowerCase():n};return n.replace(g,(function(e,n){return n||function(e){switch(e){case"YY":return String(t.$y).slice(-2);case"YYYY":return k.s(t.$y,4,"0");case"M":return u+1;case"MM":return k.s(u+1,2,"0");case"MMM":return f(r.monthsShort,u,s,3);case"MMMM":return f(s,u);case"D":return t.$D;case"DD":return k.s(t.$D,2,"0");case"d":return String(t.$W);case"dd":return f(r.weekdaysMin,t.$W,l,2);case"ddd":return f(r.weekdaysShort,t.$W,l,3);case"dddd":return l[t.$W];case"H":return String(i);case"HH":return k.s(i,2,"0");case"h":return d(1);case"hh":return d(2);case"a":return h(i,a,!0);case"A":return h(i,a,!1);case"m":return String(a);case"mm":return k.s(a,2,"0");case"s":return String(t.$s);case"ss":return k.s(t.$s,2,"0");case"SSS":return k.s(t.$ms,3,"0");case"Z":return o}return null}(e)||o.replace(":","")}))},v.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},v.diff=function(n,d,p){var h,g=this,y=k.p(d),v=x(n),b=(v.utcOffset()-this.utcOffset())*t,m=this-v,w=function(){return k.m(g,v)};switch(y){case f:h=w()/12;break;case s:h=w();break;case c:h=w()/3;break;case l:h=(m-b)/6048e5;break;case u:h=(m-b)/864e5;break;case a:h=m/r;break;case i:h=m/t;break;case o:h=m/e;break;default:h=m}return p?h:k.a(h)},v.daysInMonth=function(){return this.endOf(s).$D},v.$locale=function(){return w[this.$L]},v.locale=function(e,t){if(!e)return this.$L;var r=this.clone(),n=$(e,t,!0);return n&&(r.$L=n),r},v.clone=function(){return k.w(this.$d,this)},v.toDate=function(){return new Date(this.valueOf())},v.toJSON=function(){return this.isValid()?this.toISOString():null},v.toISOString=function(){return this.$d.toISOString()},v.toString=function(){return this.$d.toUTCString()},y}(),A=S.prototype;return x.prototype=A,[["$ms",n],["$s",o],["$m",i],["$H",a],["$W",u],["$M",s],["$y",f],["$D",d]].forEach((function(e){A[e[1]]=function(t){return this.$g(t,e[0],e[1])}})),x.extend=function(e,t){return e.$i||(e(t,S,x),e.$i=!0),x},x.locale=$,x.isDayjs=O,x.unix=function(e){return x(1e3*e)},x.en=w[m],x.Ls=w,x.p={},x}()}({get exports(){return so},set exports(e){so=e}});var co=so;const fo=[];for(let e=0;e<256;++e)fo.push((e+256).toString(16).slice(1));const po=new Uint8Array(16);function ho(){return crypto.getRandomValues(po)}const go={};function yo(e,t,r){let n;if(e)n=vo(e.random??e.rng?.()??ho(),e.msecs,e.seq,t,r);else{const e=Date.now(),o=ho();!function(e,t,r){e.msecs??=-1/0,e.seq??=0,t>e.msecs?(e.seq=bo(r),e.msecs=t):(e.seq=e.seq+1|0,0===e.seq&&e.msecs++)}(go,e,o),n=vo(o,go.msecs,go.seq,t,r)}return t??function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(fo[e[t+0]]+fo[e[t+1]]+fo[e[t+2]]+fo[e[t+3]]+"-"+fo[e[t+4]]+fo[e[t+5]]+"-"+fo[e[t+6]]+fo[e[t+7]]+"-"+fo[e[t+8]]+fo[e[t+9]]+"-"+fo[e[t+10]]+fo[e[t+11]]+fo[e[t+12]]+fo[e[t+13]]+fo[e[t+14]]+fo[e[t+15]]).toLowerCase()}(n)}function vo(e,t,r,n){let o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0;if(e.length<16)throw new Error("Random bytes length must be >= 16");if(n){if(o<0||o+16>n.length)throw new RangeError(`UUID byte range ${o}:${o+15} is out of buffer bounds`)}else n=new Uint8Array(16),o=0;return t??=Date.now(),r??=bo(e),n[o++]=t/1099511627776&255,n[o++]=t/4294967296&255,n[o++]=t/16777216&255,n[o++]=t/65536&255,n[o++]=t/256&255,n[o++]=255&t,n[o++]=112|r>>>28&15,n[o++]=r>>>20&255,n[o++]=128|r>>>14&63,n[o++]=r>>>6&255,n[o++]=r<<2&255|3&e[10],n[o++]=e[11],n[o++]=e[12],n[o++]=e[13],n[o++]=e[14],n[o++]=e[15],n}function bo(e){return(127&e[6])<<24|e[7]<<16|e[8]<<8|e[9]}function mo(e){let t=!1;if(Xr(e)){if(""===e.trim())return!1;t=!isNaN(Number(e))}else if(function(e){return"[object Number]"===Object.prototype.toString.call(e)}(e)){if(Kr(e))return!1;t=!0}return t}var wo=function(){try{var e=Ve(Object,"defineProperty");return e({},"",{}),e}catch(e){}}(),jo=wo;function Oo(e,t,r){"__proto__"==t&&jo?jo(e,t,{configurable:!0,enumerable:!0,value:r,writable:!0}):e[t]=r}var $o=Object.prototype.hasOwnProperty;function xo(e,t,r){var n=e[t];$o.call(e,t)&&Xe(n,r)&&(void 0!==r||t in e)||Oo(e,t,r)}function ko(e,t,r,n){var o=!r;r||(r={});for(var i=-1,a=t.length;++i<a;){var u=t[i],l=n?n(r[u],e[u],u,r,e):void 0;void 0===l&&(l=e[u]),o?Oo(r,u,l):xo(r,u,l)}return r}var So=Object.prototype.hasOwnProperty;function Ao(e){if(!a(e))return function(e){var t=[];if(null!=e)for(var r in Object(e))t.push(r);return t}(e);var t=le(e),r=[];for(var n in e)("constructor"!=n||!t&&So.call(e,n))&&r.push(n);return r}function _o(e){return be(e)?ae(e,!0):Ao(e)}var Po="object"==typeof exports&&exports&&!exports.nodeType&&exports,Eo=Po&&"object"==typeof module&&module&&!module.nodeType&&module,Io=Eo&&Eo.exports===Po?s.Buffer:void 0,Do=Io?Io.allocUnsafe:void 0;var Mo=se(Object.getPrototypeOf,Object),To=Object.getOwnPropertySymbols?function(e){for(var t=[];e;)kn(t,In(e)),e=Mo(e);return t}:An,Co=To;function Fo(e){return Sn(e,_o,Co)}var zo=Object.prototype.hasOwnProperty;function No(e){var t=new e.constructor(e.byteLength);return new un(t).set(new un(e)),t}var Uo=/\w*$/;var Lo=c?c.prototype:void 0,Wo=Lo?Lo.valueOf:void 0;var Ro="[object Boolean]",Bo="[object Date]",Vo="[object Map]",Ho="[object Number]",Ko="[object RegExp]",Yo="[object Set]",qo="[object String]",Xo="[object Symbol]",Jo="[object ArrayBuffer]",Zo="[object DataView]",Go="[object Float32Array]",Qo="[object Float64Array]",ei="[object Int8Array]",ti="[object Int16Array]",ri="[object Int32Array]",ni="[object Uint8Array]",oi="[object Uint8ClampedArray]",ii="[object Uint16Array]",ai="[object Uint32Array]";function ui(e,t,r){var n,o=e.constructor;switch(t){case Jo:return No(e);case Ro:case Bo:return new o(+e);case Zo:return function(e,t){var r=t?No(e.buffer):e.buffer;return new e.constructor(r,e.byteOffset,e.byteLength)}(e,r);case Go:case Qo:case ei:case ti:case ri:case ni:case oi:case ii:case ai:return function(e,t){var r=t?No(e.buffer):e.buffer;return new e.constructor(r,e.byteOffset,e.length)}(e,r);case Vo:return new o;case Ho:case qo:return new o(e);case Ko:return function(e){var t=new e.constructor(e.source,Uo.exec(e));return t.lastIndex=e.lastIndex,t}(e);case Yo:return new o;case Xo:return n=e,Wo?Object(Wo.call(n)):{}}}var li=Object.create,si=function(){function e(){}return function(t){if(!a(t))return{};if(li)return li(t);e.prototype=t;var r=new e;return e.prototype=void 0,r}}(),ci=si;var fi=re&&re.isMap,di=fi?G(fi):function(e){return w(e)&&"[object Map]"==$r(e)};var pi=re&&re.isSet,hi=pi?G(pi):function(e){return w(e)&&"[object Set]"==$r(e)},gi=1,yi=2,vi=4,bi="[object Arguments]",mi="[object Function]",wi="[object GeneratorFunction]",ji="[object Object]",Oi={};function $i(e,t,r,n,o,i){var u,l=t&gi,s=t&yi,c=t&vi;if(r&&(u=o?r(e,n,o,i):r(e)),void 0!==u)return u;if(!a(e))return e;var f=W(e);if(f){if(u=function(e){var t=e.length,r=new e.constructor(t);return t&&"string"==typeof e[0]&&zo.call(e,"index")&&(r.index=e.index,r.input=e.input),r}(e),!l)return function(e,t){var r=-1,n=e.length;for(t||(t=Array(n));++r<n;)t[r]=e[r];return t}(e,u)}else{var d=$r(e),p=d==mi||d==wi;if(H(e))return function(e,t){if(t)return e.slice();var r=e.length,n=Do?Do(r):new e.constructor(r);return e.copy(n),n}(e,l);if(d==ji||d==bi||p&&!o){if(u=s||p?{}:function(e){return"function"!=typeof e.constructor||le(e)?{}:ci(Mo(e))}(e),!l)return s?function(e,t){return ko(e,Co(e),t)}(e,function(e,t){return e&&ko(t,_o(t),e)}(u,e)):function(e,t){return ko(e,In(e),t)}(e,function(e,t){return e&&ko(t,me(t),e)}(u,e))}else{if(!Oi[d])return o?e:{};u=ui(e,d,l)}}i||(i=new Qr);var h=i.get(e);if(h)return h;i.set(e,u),hi(e)?e.forEach((function(n){u.add($i(n,t,r,n,e,i))})):di(e)&&e.forEach((function(n,o){u.set(o,$i(n,t,r,o,e,i))}));var g=f?void 0:(c?s?Fo:Dn:s?_o:me)(e);return D(g||e,(function(n,o){g&&(n=e[o=n]),xo(u,o,$i(n,t,r,o,e,i))})),u}Oi[bi]=Oi["[object Array]"]=Oi["[object ArrayBuffer]"]=Oi["[object DataView]"]=Oi["[object Boolean]"]=Oi["[object Date]"]=Oi["[object Float32Array]"]=Oi["[object Float64Array]"]=Oi["[object Int8Array]"]=Oi["[object Int16Array]"]=Oi["[object Int32Array]"]=Oi["[object Map]"]=Oi["[object Number]"]=Oi[ji]=Oi["[object RegExp]"]=Oi["[object Set]"]=Oi["[object String]"]=Oi["[object Symbol]"]=Oi["[object Uint8Array]"]=Oi["[object Uint8ClampedArray]"]=Oi["[object Uint16Array]"]=Oi["[object Uint32Array]"]=!0,Oi["[object Error]"]=Oi[mi]=Oi["[object WeakMap]"]=!1;var xi=1,ki=4;var Si={},Ai={get exports(){return Si},set exports(e){Si=e}},_i={},Pi={},Ei={get exports(){return Pi},set exports(e){Pi=e}},Ii={};function Di(){var e={"align-content":!1,"align-items":!1,"align-self":!1,"alignment-adjust":!1,"alignment-baseline":!1,all:!1,"anchor-point":!1,animation:!1,"animation-delay":!1,"animation-direction":!1,"animation-duration":!1,"animation-fill-mode":!1,"animation-iteration-count":!1,"animation-name":!1,"animation-play-state":!1,"animation-timing-function":!1,azimuth:!1,"backface-visibility":!1,background:!0,"background-attachment":!0,"background-clip":!0,"background-color":!0,"background-image":!0,"background-origin":!0,"background-position":!0,"background-repeat":!0,"background-size":!0,"baseline-shift":!1,binding:!1,bleed:!1,"bookmark-label":!1,"bookmark-level":!1,"bookmark-state":!1,border:!0,"border-bottom":!0,"border-bottom-color":!0,"border-bottom-left-radius":!0,"border-bottom-right-radius":!0,"border-bottom-style":!0,"border-bottom-width":!0,"border-collapse":!0,"border-color":!0,"border-image":!0,"border-image-outset":!0,"border-image-repeat":!0,"border-image-slice":!0,"border-image-source":!0,"border-image-width":!0,"border-left":!0,"border-left-color":!0,"border-left-style":!0,"border-left-width":!0,"border-radius":!0,"border-right":!0,"border-right-color":!0,"border-right-style":!0,"border-right-width":!0,"border-spacing":!0,"border-style":!0,"border-top":!0,"border-top-color":!0,"border-top-left-radius":!0,"border-top-right-radius":!0,"border-top-style":!0,"border-top-width":!0,"border-width":!0,bottom:!1,"box-decoration-break":!0,"box-shadow":!0,"box-sizing":!0,"box-snap":!0,"box-suppress":!0,"break-after":!0,"break-before":!0,"break-inside":!0,"caption-side":!1,chains:!1,clear:!0,clip:!1,"clip-path":!1,"clip-rule":!1,color:!0,"color-interpolation-filters":!0,"column-count":!1,"column-fill":!1,"column-gap":!1,"column-rule":!1,"column-rule-color":!1,"column-rule-style":!1,"column-rule-width":!1,"column-span":!1,"column-width":!1,columns:!1,contain:!1,content:!1,"counter-increment":!1,"counter-reset":!1,"counter-set":!1,crop:!1,cue:!1,"cue-after":!1,"cue-before":!1,cursor:!1,direction:!1,display:!0,"display-inside":!0,"display-list":!0,"display-outside":!0,"dominant-baseline":!1,elevation:!1,"empty-cells":!1,filter:!1,flex:!1,"flex-basis":!1,"flex-direction":!1,"flex-flow":!1,"flex-grow":!1,"flex-shrink":!1,"flex-wrap":!1,float:!1,"float-offset":!1,"flood-color":!1,"flood-opacity":!1,"flow-from":!1,"flow-into":!1,font:!0,"font-family":!0,"font-feature-settings":!0,"font-kerning":!0,"font-language-override":!0,"font-size":!0,"font-size-adjust":!0,"font-stretch":!0,"font-style":!0,"font-synthesis":!0,"font-variant":!0,"font-variant-alternates":!0,"font-variant-caps":!0,"font-variant-east-asian":!0,"font-variant-ligatures":!0,"font-variant-numeric":!0,"font-variant-position":!0,"font-weight":!0,grid:!1,"grid-area":!1,"grid-auto-columns":!1,"grid-auto-flow":!1,"grid-auto-rows":!1,"grid-column":!1,"grid-column-end":!1,"grid-column-start":!1,"grid-row":!1,"grid-row-end":!1,"grid-row-start":!1,"grid-template":!1,"grid-template-areas":!1,"grid-template-columns":!1,"grid-template-rows":!1,"hanging-punctuation":!1,height:!0,hyphens:!1,icon:!1,"image-orientation":!1,"image-resolution":!1,"ime-mode":!1,"initial-letters":!1,"inline-box-align":!1,"justify-content":!1,"justify-items":!1,"justify-self":!1,left:!1,"letter-spacing":!0,"lighting-color":!0,"line-box-contain":!1,"line-break":!1,"line-grid":!1,"line-height":!1,"line-snap":!1,"line-stacking":!1,"line-stacking-ruby":!1,"line-stacking-shift":!1,"line-stacking-strategy":!1,"list-style":!0,"list-style-image":!0,"list-style-position":!0,"list-style-type":!0,margin:!0,"margin-bottom":!0,"margin-left":!0,"margin-right":!0,"margin-top":!0,"marker-offset":!1,"marker-side":!1,marks:!1,mask:!1,"mask-box":!1,"mask-box-outset":!1,"mask-box-repeat":!1,"mask-box-slice":!1,"mask-box-source":!1,"mask-box-width":!1,"mask-clip":!1,"mask-image":!1,"mask-origin":!1,"mask-position":!1,"mask-repeat":!1,"mask-size":!1,"mask-source-type":!1,"mask-type":!1,"max-height":!0,"max-lines":!1,"max-width":!0,"min-height":!0,"min-width":!0,"move-to":!1,"nav-down":!1,"nav-index":!1,"nav-left":!1,"nav-right":!1,"nav-up":!1,"object-fit":!1,"object-position":!1,opacity:!1,order:!1,orphans:!1,outline:!1,"outline-color":!1,"outline-offset":!1,"outline-style":!1,"outline-width":!1,overflow:!1,"overflow-wrap":!1,"overflow-x":!1,"overflow-y":!1,padding:!0,"padding-bottom":!0,"padding-left":!0,"padding-right":!0,"padding-top":!0,page:!1,"page-break-after":!1,"page-break-before":!1,"page-break-inside":!1,"page-policy":!1,pause:!1,"pause-after":!1,"pause-before":!1,perspective:!1,"perspective-origin":!1,pitch:!1,"pitch-range":!1,"play-during":!1,position:!1,"presentation-level":!1,quotes:!1,"region-fragment":!1,resize:!1,rest:!1,"rest-after":!1,"rest-before":!1,richness:!1,right:!1,rotation:!1,"rotation-point":!1,"ruby-align":!1,"ruby-merge":!1,"ruby-position":!1,"shape-image-threshold":!1,"shape-outside":!1,"shape-margin":!1,size:!1,speak:!1,"speak-as":!1,"speak-header":!1,"speak-numeral":!1,"speak-punctuation":!1,"speech-rate":!1,stress:!1,"string-set":!1,"tab-size":!1,"table-layout":!1,"text-align":!0,"text-align-last":!0,"text-combine-upright":!0,"text-decoration":!0,"text-decoration-color":!0,"text-decoration-line":!0,"text-decoration-skip":!0,"text-decoration-style":!0,"text-emphasis":!0,"text-emphasis-color":!0,"text-emphasis-position":!0,"text-emphasis-style":!0,"text-height":!0,"text-indent":!0,"text-justify":!0,"text-orientation":!0,"text-overflow":!0,"text-shadow":!0,"text-space-collapse":!0,"text-transform":!0,"text-underline-position":!0,"text-wrap":!0,top:!1,transform:!1,"transform-origin":!1,"transform-style":!1,transition:!1,"transition-delay":!1,"transition-duration":!1,"transition-property":!1,"transition-timing-function":!1,"unicode-bidi":!1,"vertical-align":!1,visibility:!1,"voice-balance":!1,"voice-duration":!1,"voice-family":!1,"voice-pitch":!1,"voice-range":!1,"voice-rate":!1,"voice-stress":!1,"voice-volume":!1,volume:!1,"white-space":!1,widows:!1,width:!0,"will-change":!1,"word-break":!0,"word-spacing":!0,"word-wrap":!0,"wrap-flow":!1,"wrap-through":!1,"writing-mode":!1,"z-index":!1};return e}var Mi=/javascript\s*\:/gim;Ii.whiteList=Di(),Ii.getDefaultWhiteList=Di,Ii.onAttr=function(e,t,r){},Ii.onIgnoreAttr=function(e,t,r){},Ii.safeAttrValue=function(e,t){return Mi.test(t)?"":t};var Ti={indexOf:function(e,t){var r,n;if(Array.prototype.indexOf)return e.indexOf(t);for(r=0,n=e.length;r<n;r++)if(e[r]===t)return r;return-1},forEach:function(e,t,r){var n,o;if(Array.prototype.forEach)return e.forEach(t,r);for(n=0,o=e.length;n<o;n++)t.call(r,e[n],n,e)},trim:function(e){return String.prototype.trim?e.trim():e.replace(/(^\s*)|(\s*$)/g,"")},trimRight:function(e){return String.prototype.trimRight?e.trimRight():e.replace(/(\s*$)/g,"")}};var Ci=function(e,t){";"!==(e=Ti.trimRight(e))[e.length-1]&&(e+=";");var r=e.length,n=!1,o=0,i=0,a="";function u(){if(!n){var r=Ti.trim(e.slice(o,i)),u=r.indexOf(":");if(-1!==u){var l=Ti.trim(r.slice(0,u)),s=Ti.trim(r.slice(u+1));if(l){var c=t(o,a.length,l,s,r);c&&(a+=c+"; ")}}}o=i+1}for(;i<r;i++){var l=e[i];if("/"===l&&"*"===e[i+1]){var s=e.indexOf("*/",i+2);if(-1===s)break;o=(i=s+1)+1,n=!1}else"("===l?n=!0:")"===l?n=!1:";"===l?n||u():"\n"===l&&u()}return Ti.trim(a)},Fi=Ii,zi=Ci;function Ni(e){return null==e}function Ui(e){(e=function(e){var t={};for(var r in e)t[r]=e[r];return t}(e||{})).whiteList=e.whiteList||Fi.whiteList,e.onAttr=e.onAttr||Fi.onAttr,e.onIgnoreAttr=e.onIgnoreAttr||Fi.onIgnoreAttr,e.safeAttrValue=e.safeAttrValue||Fi.safeAttrValue,this.options=e}Ui.prototype.process=function(e){if(!(e=(e=e||"").toString()))return"";var t=this.options,r=t.whiteList,n=t.onAttr,o=t.onIgnoreAttr,i=t.safeAttrValue;return zi(e,(function(e,t,a,u,l){var s=r[a],c=!1;if(!0===s?c=s:"function"==typeof s?c=s(u):s instanceof RegExp&&(c=s.test(u)),!0!==c&&(c=!1),u=i(a,u)){var f,d={position:t,sourcePosition:e,source:l,isWhite:c};return c?Ni(f=n(a,u,d))?a+":"+u:f:Ni(f=o(a,u,d))?void 0:f}}))};var Li=Ui;!function(e,t){var r=Ii,n=Li;for(var o in(t=e.exports=function(e,t){return new n(t).process(e)}).FilterCSS=n,r)t[o]=r[o];"undefined"!=typeof window&&(window.filterCSS=e.exports)}(Ei,Pi);var Wi={indexOf:function(e,t){var r,n;if(Array.prototype.indexOf)return e.indexOf(t);for(r=0,n=e.length;r<n;r++)if(e[r]===t)return r;return-1},forEach:function(e,t,r){var n,o;if(Array.prototype.forEach)return e.forEach(t,r);for(n=0,o=e.length;n<o;n++)t.call(r,e[n],n,e)},trim:function(e){return String.prototype.trim?e.trim():e.replace(/(^\s*)|(\s*$)/g,"")},spaceIndex:function(e){var t=/\s|\n|\t/.exec(e);return t?t.index:-1}},Ri=Pi.FilterCSS,Bi=Pi.getDefaultWhiteList,Vi=Wi;function Hi(){return{a:["target","href","title"],abbr:["title"],address:[],area:["shape","coords","href","alt"],article:[],aside:[],audio:["autoplay","controls","crossorigin","loop","muted","preload","src"],b:[],bdi:["dir"],bdo:["dir"],big:[],blockquote:["cite"],br:[],caption:[],center:[],cite:[],code:[],col:["align","valign","span","width"],colgroup:["align","valign","span","width"],dd:[],del:["datetime"],details:["open"],div:[],dl:[],dt:[],em:[],figcaption:[],figure:[],font:["color","size","face"],footer:[],h1:[],h2:[],h3:[],h4:[],h5:[],h6:[],header:[],hr:[],i:[],img:["src","alt","title","width","height","loading"],ins:["datetime"],kbd:[],li:[],mark:[],nav:[],ol:[],p:[],pre:[],s:[],section:[],small:[],span:[],sub:[],summary:[],sup:[],strong:[],strike:[],table:["width","border","align","valign"],tbody:["align","valign"],td:["width","rowspan","colspan","align","valign"],tfoot:["align","valign"],th:["width","rowspan","colspan","align","valign"],thead:["align","valign"],tr:["rowspan","align","valign"],tt:[],u:[],ul:[],video:["autoplay","controls","crossorigin","loop","muted","playsinline","poster","preload","src","height","width"]}}var Ki=new Ri;function Yi(e){return e.replace(qi,"<").replace(Xi,">")}var qi=/</g,Xi=/>/g,Ji=/"/g,Zi=/"/g,Gi=/&#([a-zA-Z0-9]*);?/gim,Qi=/:?/gim,ea=/&newline;?/gim,ta=/((j\s*a\s*v\s*a|v\s*b|l\s*i\s*v\s*e)\s*s\s*c\s*r\s*i\s*p\s*t\s*|m\s*o\s*c\s*h\s*a):/gi,ra=/e\s*x\s*p\s*r\s*e\s*s\s*s\s*i\s*o\s*n\s*\(.*/gi,na=/u\s*r\s*l\s*\(.*/gi;function oa(e){return e.replace(Ji,""")}function ia(e){return e.replace(Zi,'"')}function aa(e){return e.replace(Gi,(function(e,t){return"x"===t[0]||"X"===t[0]?String.fromCharCode(parseInt(t.substr(1),16)):String.fromCharCode(parseInt(t,10))}))}function ua(e){return e.replace(Qi,":").replace(ea," ")}function la(e){for(var t="",r=0,n=e.length;r<n;r++)t+=e.charCodeAt(r)<32?" ":e.charAt(r);return Vi.trim(t)}function sa(e){return e=la(e=ua(e=aa(e=ia(e))))}function ca(e){return e=Yi(e=oa(e))}_i.whiteList={a:["target","href","title"],abbr:["title"],address:[],area:["shape","coords","href","alt"],article:[],aside:[],audio:["autoplay","controls","crossorigin","loop","muted","preload","src"],b:[],bdi:["dir"],bdo:["dir"],big:[],blockquote:["cite"],br:[],caption:[],center:[],cite:[],code:[],col:["align","valign","span","width"],colgroup:["align","valign","span","width"],dd:[],del:["datetime"],details:["open"],div:[],dl:[],dt:[],em:[],figcaption:[],figure:[],font:["color","size","face"],footer:[],h1:[],h2:[],h3:[],h4:[],h5:[],h6:[],header:[],hr:[],i:[],img:["src","alt","title","width","height","loading"],ins:["datetime"],kbd:[],li:[],mark:[],nav:[],ol:[],p:[],pre:[],s:[],section:[],small:[],span:[],sub:[],summary:[],sup:[],strong:[],strike:[],table:["width","border","align","valign"],tbody:["align","valign"],td:["width","rowspan","colspan","align","valign"],tfoot:["align","valign"],th:["width","rowspan","colspan","align","valign"],thead:["align","valign"],tr:["rowspan","align","valign"],tt:[],u:[],ul:[],video:["autoplay","controls","crossorigin","loop","muted","playsinline","poster","preload","src","height","width"]},_i.getDefaultWhiteList=Hi,_i.onTag=function(e,t,r){},_i.onIgnoreTag=function(e,t,r){},_i.onTagAttr=function(e,t,r){},_i.onIgnoreTagAttr=function(e,t,r){},_i.safeAttrValue=function(e,t,r,n){if(r=sa(r),"href"===t||"src"===t){if("#"===(r=Vi.trim(r)))return"#";if("http://"!==r.substr(0,7)&&"https://"!==r.substr(0,8)&&"mailto:"!==r.substr(0,7)&&"tel:"!==r.substr(0,4)&&"data:image/"!==r.substr(0,11)&&"ftp://"!==r.substr(0,6)&&"./"!==r.substr(0,2)&&"../"!==r.substr(0,3)&&"#"!==r[0]&&"/"!==r[0])return""}else if("background"===t){if(ta.lastIndex=0,ta.test(r))return""}else if("style"===t){if(ra.lastIndex=0,ra.test(r))return"";if(na.lastIndex=0,na.test(r)&&(ta.lastIndex=0,ta.test(r)))return"";!1!==n&&(r=(n=n||Ki).process(r))}return r=ca(r)},_i.escapeHtml=Yi,_i.escapeQuote=oa,_i.unescapeQuote=ia,_i.escapeHtmlEntities=aa,_i.escapeDangerHtml5Entities=ua,_i.clearNonPrintableCharacter=la,_i.friendlyAttrValue=sa,_i.escapeAttrValue=ca,_i.onIgnoreTagStripAll=function(){return""},_i.StripTagBody=function(e,t){"function"!=typeof t&&(t=function(){});var r=!Array.isArray(e),n=[],o=!1;return{onIgnoreTag:function(i,a,u){if(function(t){return!!r||-1!==Vi.indexOf(e,t)}(i)){if(u.isClosing){var l="[/removed]",s=u.position+l.length;return n.push([!1!==o?o:u.position,s]),o=!1,l}return o||(o=u.position),"[removed]"}return t(i,a,u)},remove:function(e){var t="",r=0;return Vi.forEach(n,(function(n){t+=e.slice(r,n[0]),r=n[1]})),t+=e.slice(r)}}},_i.stripCommentTag=function(e){for(var t="",r=0;r<e.length;){var n=e.indexOf("\x3c!--",r);if(-1===n){t+=e.slice(r);break}t+=e.slice(r,n);var o=e.indexOf("--\x3e",n);if(-1===o)break;r=o+3}return t},_i.stripBlankChar=function(e){var t=e.split("");return(t=t.filter((function(e){var t=e.charCodeAt(0);return 127!==t&&(!(t<=31)||(10===t||13===t))}))).join("")},_i.attributeWrapSign='"',_i.cssFilter=Ki,_i.getDefaultCSSWhiteList=Bi;var fa={},da=Wi;function pa(e){var t,r=da.spaceIndex(e);return t=-1===r?e.slice(1,-1):e.slice(1,r+1),"/"===(t=da.trim(t).toLowerCase()).slice(0,1)&&(t=t.slice(1)),"/"===t.slice(-1)&&(t=t.slice(0,-1)),t}function ha(e){return"</"===e.slice(0,2)}var ga=/[^a-zA-Z0-9\\_:.-]/gim;function ya(e,t){for(;t<e.length;t++){var r=e[t];if(" "!==r)return"="===r?t:-1}}function va(e,t){for(;t<e.length;t++){var r=e[t];if(" "!==r)return"'"===r||'"'===r?t:-1}}function ba(e,t){for(;t>0;t--){var r=e[t];if(" "!==r)return"="===r?t:-1}}function ma(e){return function(e){return'"'===e[0]&&'"'===e[e.length-1]||"'"===e[0]&&"'"===e[e.length-1]}(e)?e.substr(1,e.length-2):e}fa.parseTag=function(e,t,r){var n="",o=0,i=!1,a=!1,u=0,l=e.length,s="",c="";e:for(u=0;u<l;u++){var f=e.charAt(u);if(!1===i){if("<"===f){i=u;continue}}else if(!1===a){if("<"===f){n+=r(e.slice(o,u)),i=u,o=u;continue}if(">"===f||u===l-1){n+=r(e.slice(o,i)),s=pa(c=e.slice(i,u+1)),n+=t(i,n.length,s,c,ha(c)),o=u+1,i=!1;continue}if('"'===f||"'"===f)for(var d=1,p=e.charAt(u-d);""===p.trim()||"="===p;){if("="===p){a=f;continue e}p=e.charAt(u-++d)}}else if(f===a){a=!1;continue}}return o<l&&(n+=r(e.substr(o))),n},fa.parseAttr=function(e,t){var r=0,n=0,o=[],i=!1,a=e.length;function u(e,r){if(!((e=(e=da.trim(e)).replace(ga,"").toLowerCase()).length<1)){var n=t(e,r||"");n&&o.push(n)}}for(var l=0;l<a;l++){var s,c=e.charAt(l);if(!1!==i||"="!==c)if(!1===i||l!==n)if(/\s|\n|\t/.test(c)){if(e=e.replace(/\s|\n|\t/g," "),!1===i){if(-1===(s=ya(e,l))){u(da.trim(e.slice(r,l))),i=!1,r=l+1;continue}l=s-1;continue}if(-1===(s=ba(e,l-1))){u(i,ma(da.trim(e.slice(r,l)))),i=!1,r=l+1;continue}}else;else{if(-1===(s=e.indexOf(c,l+1)))break;u(i,da.trim(e.slice(n+1,s))),i=!1,r=(l=s)+1}else i=e.slice(r,l),r=l+1,n='"'===e.charAt(r)||"'"===e.charAt(r)?r:va(e,l+1)}return r<e.length&&(!1===i?u(e.slice(r)):u(i,ma(da.trim(e.slice(r))))),da.trim(o.join(" "))};var wa=Pi.FilterCSS,ja=_i,Oa=fa,$a=Oa.parseTag,xa=Oa.parseAttr,ka=Wi;function Sa(e){return null==e}function Aa(e){(e=function(e){var t={};for(var r in e)t[r]=e[r];return t}(e||{})).stripIgnoreTag&&(e.onIgnoreTag&&console.error('Notes: cannot use these two options "stripIgnoreTag" and "onIgnoreTag" at the same time'),e.onIgnoreTag=ja.onIgnoreTagStripAll),e.whiteList||e.allowList?e.whiteList=function(e){var t={};for(var r in e)Array.isArray(e[r])?t[r.toLowerCase()]=e[r].map((function(e){return e.toLowerCase()})):t[r.toLowerCase()]=e[r];return t}(e.whiteList||e.allowList):e.whiteList=ja.whiteList,this.attributeWrapSign=!0===e.singleQuotedAttributeValue?"'":ja.attributeWrapSign,e.onTag=e.onTag||ja.onTag,e.onTagAttr=e.onTagAttr||ja.onTagAttr,e.onIgnoreTag=e.onIgnoreTag||ja.onIgnoreTag,e.onIgnoreTagAttr=e.onIgnoreTagAttr||ja.onIgnoreTagAttr,e.safeAttrValue=e.safeAttrValue||ja.safeAttrValue,e.escapeHtml=e.escapeHtml||ja.escapeHtml,this.options=e,!1===e.css?this.cssFilter=!1:(e.css=e.css||{},this.cssFilter=new wa(e.css))}Aa.prototype.process=function(e){if(!(e=(e=e||"").toString()))return"";var t=this,r=t.options,n=r.whiteList,o=r.onTag,i=r.onIgnoreTag,a=r.onTagAttr,u=r.onIgnoreTagAttr,l=r.safeAttrValue,s=r.escapeHtml,c=t.attributeWrapSign,f=t.cssFilter;r.stripBlankChar&&(e=ja.stripBlankChar(e)),r.allowCommentTag||(e=ja.stripCommentTag(e));var d=!1;r.stripIgnoreTagBody&&(d=ja.StripTagBody(r.stripIgnoreTagBody,i),i=d.onIgnoreTag);var p=$a(e,(function(e,t,r,d,p){var h={sourcePosition:e,position:t,isClosing:p,isWhite:Object.prototype.hasOwnProperty.call(n,r)},g=o(r,d,h);if(!Sa(g))return g;if(h.isWhite){if(h.isClosing)return"</"+r+">";var y=function(e){var t=ka.spaceIndex(e);if(-1===t)return{html:"",closing:"/"===e[e.length-2]};var r="/"===(e=ka.trim(e.slice(t+1,-1)))[e.length-1];return r&&(e=ka.trim(e.slice(0,-1))),{html:e,closing:r}}(d),v=n[r],b=xa(y.html,(function(e,t){var n=-1!==ka.indexOf(v,e),o=a(r,e,t,n);return Sa(o)?n?(t=l(r,e,t,f))?e+"="+c+t+c:e:Sa(o=u(r,e,t,n))?void 0:o:o}));return d="<"+r,b&&(d+=" "+b),y.closing&&(d+=" /"),d+=">"}return Sa(g=i(r,d,h))?s(d):g}),s);return d&&(p=d.remove(p)),p};var _a=Aa;!function(e,t){var r=_i,n=fa,o=_a;function i(e,t){return new o(t).process(e)}(t=e.exports=i).filterXSS=i,t.FilterXSS=o,function(){for(var e in r)t[e]=r[e];for(var o in n)t[o]=n[o]}(),"undefined"!=typeof window&&(window.filterXSS=e.exports),"undefined"!=typeof self&&"undefined"!=typeof DedicatedWorkerGlobalScope&&self instanceof DedicatedWorkerGlobalScope&&(self.filterXSS=e.exports)}(Ai,Si);var Pa=Si;function Ea(){return"undefined"!=typeof self?self:"undefined"!=typeof window&&void 0!==window.document?window:"undefined"!=typeof global?global:null}let Ia=/<(?=[A-Za-z!/?]|$)/g;function Da(e){return e.replace(Ia,"<")}let Ma={getFilterXSS:function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Pa;if(xe(e))return e;let t=Ea(),r=jt(t,"filterXSS",null);if(xe(r))return r;let n=jt(t,"xss",null);if(xe(n))return n;throw new Error("invalid filterXSS, g.filterXSS, use script for import")},getOpt:function(e){return{escapeHtml:Da,onIgnoreTagAttr:function(t,r,n,o){if("style"===r)return r+'="'+e.escapeAttrValue(n)+'"'}}}};function Ta(e){let t=null,r=null;let n=function e(n){if(Array.isArray(n)){for(let t=0;t<n.length;t++)n[t]=e(n[t]);return n}if(Ae(n)||Se(n)){for(let t of Object.keys(n))n[t]=e(n[t]);return n}return Xr(n)?(o=n,null===t&&(t=Ma.getFilterXSS(),r=Ma.getOpt(t)),t(o,r)):n;var o}($i(e,xi|ki));return n}function Ca(e,t){if(!Se(e))return[];Se(t)||(t=[t]);let r=[];return $e(e,((e,n)=>{0===jt(e,"ok")&&r.push({k:n,id:jt(t,[n,"id"]),err:jt(e,"err","")})})),r}function Fa(e,t){var n,o,i;let a=`${e}: ${ro(eo((o=10,(n=t)&&n.length?r(n,0,(o=i||void 0===o?1:I(o))<0?0:o):[]),(e=>Xr(e.ref)?e.ref:Xr(e.id)||mo(e.id)?`id[${lo(String(e.id),{length:100,omission:"…"})}]`:`data[${e.k}]`)),", ")}`;return Rr(t)>10&&(a+=`, ... (${Rr(t)} in total)`),a}function za(e,t){if(t.indexOf("id")<0)return!1;let r=jt(e,"settings",null);if(Vr(r)&&!0!==jt(r,"id.pk"))return!1;let n=jt(r,"id.type","")||jt(e,"kpType.id","");return!(Xr(n)&&["STRING","TEXT","CHAR","UUID","CITEXT"].indexOf(n.split("(")[0].trim().toUpperCase())<0)}function Na(e,t){return null!==e&&"object"==typeof e&&"string"==typeof t&&Object.prototype.hasOwnProperty.call(e,t)?void 0===e[t]?null:e[t]:null}function Ua(e){try{return Array.isArray(e)}catch(e){return!1}}function La(e){return!Object.prototype.hasOwnProperty.call(e,"value")}function Wa(e){return"number"==typeof e&&Number.isFinite(e)}function Ra(e){return Wa(e)?String(e):e}function Ba(e,t){return Object.fromEntries(Object.keys(e).map((r=>[r,t(e[r],r)])))}const Va=Object.freeze({proto:"unsupported key[__proto__]",accessor:"unsupported accessor property",unreadable:"unreadable value",deep:"too deep",large:"too large",sparse:"unsupported sparse array",hidden:"unsupported symbol key or non-enumerable property",irregular:"unsupported irregular object or array"}),Ha=64,Ka=64,Ya=1e5,qa=4e6,Xa=200,Ja=8,Za=50,Ga=200,Qa="function"==typeof WeakRef?Function.prototype.call.bind(WeakRef.prototype.deref):null,eu="function"==typeof FinalizationRegistry?Function.prototype.call.bind(FinalizationRegistry.prototype.unregister):null,tu={};function ru(e){let r=0;for(let n=e;null!==n;n=Object.getPrototypeOf(n))if(r++>Ka||t.types.isProxy(n)||Object.prototype.hasOwnProperty.call(n,Symbol.toStringTag))return!1;return!0}function nu(e){return t.types.isMap(e)||t.types.isSet(e)||t.types.isWeakMap(e)||t.types.isWeakSet(e)||t.types.isPromise(e)||t.types.isAnyArrayBuffer(e)||t.types.isArrayBufferView(e)||t.types.isBoxedPrimitive(e)||t.types.isRegExp(e)||t.types.isNativeError(e)||t.types.isGeneratorObject(e)||t.types.isMapIterator(e)||t.types.isSetIterator(e)||t.types.isModuleNamespaceObject(e)}function ou(e){if("object"!=typeof e||null===e||!ru(e)||!Ae(e))return!1;let r=Object.getPrototypeOf(e);return null===r||r===Object.prototype||function(e){if(null!==Object.getPrototypeOf(e))return!1;let r=Reflect.ownKeys(Object.prototype);if(Reflect.ownKeys(e).length!==r.length)return!1;for(let t of r)if(!Object.prototype.hasOwnProperty.call(e,t))return!1;let n=Object.getOwnPropertyDescriptor(e,"constructor");if(void 0===n||"function"!=typeof n.value||t.types.isProxy(n.value))return!1;if(Function.prototype.toString.call(n.value)!==Function.prototype.toString.call(Object))return!1;let o=Object.getOwnPropertyDescriptor(n.value,"prototype");return void 0!==o&&o.value===e}(r)}function iu(e){return"object"!=typeof e||null===e||!ru(e)||nu(e)?null:Array.isArray(e)?"arr":Ae(e)?"obj":null}function au(e){if(null!==Qa)try{return Qa(e),!0}catch(e){}if(null!==eu)try{return eu(e,tu),!0}catch(e){}return!1}function uu(e){try{for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];console.log(e,...r)}catch(t){try{console.log(e,"(unprintable)")}catch(e){}}}function lu(e){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{n:0},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(r.n>=Xa)return"[...]";if(r.n++,"string"==typeof e)return lo(e,{length:Ga});if("function"==typeof e)return"[Function]";if("symbol"==typeof e)return"[Symbol]";if("object"!=typeof e||null===e)return e;if(t.types.isProxy(e))return"[Proxy]";if(t.types.isDate(e))return"[Date]";if(nu(e))return"[Object]";if(n>=Ja)return"[...]";let o=e=>void 0===e?"[empty]":La(e)?"[Getter/Setter]":lu(e.value,r,n+1);if(Array.isArray(e)){let t=Math.min(e.length,Za),r=[];for(let n=0;n<t;n++)r.push(o(Object.getOwnPropertyDescriptor(e,n)));return e.length>t&&r.push(`[${e.length-t} more]`),r}let i=Reflect.ownKeys(e),a={};for(let t of i.slice(0,Za)){let r=Object.getOwnPropertyDescriptor(e,t),n="symbol"==typeof t?String(t):t;Object.defineProperty(a,r.enumerable?n:`${n} (non-enumerable)`,{value:o(r),enumerable:!0,writable:!0,configurable:!0})}return i.length>Za&&Object.defineProperty(a,"[more]",{value:i.length-Za,enumerable:!0,writable:!0,configurable:!0}),a}function su(e,t){let r;try{r=lu(t)}catch(e){r="(unprintable)"}uu(e,r)}function cu(e){if("object"!=typeof e||null===e)return;let t=Object.getOwnPropertyDescriptor(e,"id");return void 0!==t&&t.enumerable&&!La(t)?t.value:void 0}const fu=["mustExist","keepUserId"],du=1e3;function pu(e,t){let r=e=>({err:e,mustExist:!1,keepUserId:!1});if(null==t)return{err:null,mustExist:!1,keepUserId:!1};if(!ou(t))return r("invalid opt of procOrm, need an object");for(let e of Reflect.ownKeys(t))if(fu.indexOf(e)<0)return r("invalid opt of procOrm, unsupported key");let n={mustExist:!1,keepUserId:!1};for(let e of fu){let o=Object.getOwnPropertyDescriptor(t,e);if(void 0!==o){if(La(o)||"boolean"!=typeof o.value)return r(`invalid opt of procOrm, ${e} needs a boolean`);n[e]=o.value}}return n.mustExist&&"save"!==e&&"del"!==e?r("invalid opt of procOrm, mustExist supports only save and del"):n.keepUserId&&"insert"!==e?r("invalid opt of procOrm, keepUserId supports only insert"):{err:null,mustExist:n.mustExist,keepUserId:n.keepUserId}}async function hu(e,t){let r=[],n=new Set;for(let e of Ua(t)?t:[t]){let t=cu(e);if(!("string"==typeof t&&""!==t||Wa(t)))return!0;n.has(String(t))||(n.add(String(t)),r.push(t))}for(let t=0;t<r.length;t+=du){let n=r.slice(t,t+du),o=await e.select({id:{$in:n}}),i=new Set(eo(Ua(o)?o:[],(e=>String(jt(e,"id")))));if(n.some((e=>!i.has(String(e)))))return!0}return!1}function gu(e,t){return(Ua(e)?e:[e]).some((e=>null!==e&&"object"==typeof e&&0!==e.ok&&(0===e.n||null!==t&&0===e[t])))}function yu(e){let t=[],r=Array.isArray(e)?null:Object.keys(e),n=null===r?e.length:r.length;for(let o=0;o<n;o++){let n=Object.getOwnPropertyDescriptor(e,null===r?o:r[o]).value;null!==iu(n)&&t.push(n)}return t}function vu(e){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1/0,n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];try{let o=new Set,i=[e,1],a=0,u=[];for(;i.length>0;){let e,l=i.pop(),s=i.pop();if(o.has(s))continue;if(n){if("object"==typeof s&&null!==s){if(!ru(s)||nu(s))return"irregular";if(t.types.isDate(s)){if(Reflect.ownKeys(s).length>0)return"irregular";continue}}e=iu(s)}else e=Array.isArray(s)?"arr":Ae(s)?"obj":null;if(null===e)continue;let c="arr"===e;if(l>r)return"deep";if(o.add(s),Object.prototype.hasOwnProperty.call(s,"__proto__"))return"proto";let f=c?null:Object.keys(s);if(n&&!c){if(!ou(s))return"irregular";if(Reflect.ownKeys(s).length!==f.length)return"hidden";u.push(s)}let d=c?s.length:f.length;for(let e=0;e<d;e++){let t=Object.getOwnPropertyDescriptor(s,c?e:f[e]);if(void 0===t)return n?"irregular":"sparse";if(La(t))return"accessor";if(n&&c&&!t.enumerable)return"irregular";n&&(a+=c?0:f[e].length,"string"==typeof t.value&&(a+=t.value.length)),"object"==typeof t.value&&null!==t.value&&i.push(t.value,l+1)}if(n&&c&&Reflect.ownKeys(s).length!==d+1)return"irregular"}if(n&&"object"==typeof e&&null!==e){let t=function(e,t,r){let n=new Map,o=new Map,i=[{o:e,kids:yu(e),i:0,d:0,n:Array.isArray(e)?0:1}];for(n.set(e,-1);i.length>0;){let e=i[i.length-1];if(i.length>t)return"deep";if(e.i<e.kids.length){let a=e.kids[e.i++],u=n.get(a);if(void 0===u)n.set(a,-1),i.push({o:a,kids:yu(a),i:0,d:0,n:Array.isArray(a)?0:1});else{if(-1===u)return"deep";if(e.n+=u,e.d=Math.max(e.d,o.get(a)),e.n>r)return"large";if(i.length+o.get(a)>t)return"deep"}}else if(i.pop(),n.set(e.o,e.n),o.set(e.o,e.d+1),i.length>0){let n=i[i.length-1];if(n.n+=e.n,n.d=Math.max(n.d,e.d+1),n.n>r)return"large";if(i.length+o.get(e.o)>t)return"deep"}}return null}(e,r,Ya);if(null!==t)return t;if(a<=qa&&"function"==typeof structuredClone){if(function(e){if("function"!=typeof structuredClone)return!1;let t;try{t=structuredClone(e)}catch(e){return!0}let r=new Set,n=[t];for(;n.length>0;){let e=n.pop();if("object"!=typeof e||null===e||r.has(e))continue;r.add(e);let t=Object.getPrototypeOf(e);if(t!==Date.prototype){if(t!==Object.prototype&&t!==Array.prototype)return!0;for(let t of Object.keys(e))n.push(e[t])}}return!1}(e))return"irregular"}else for(let e=0;e<u.length;e++)if(au(u[e]))return"irregular"}return null}catch(e){return"unreadable"}}function bu(e,r){try{if(void 0!==r&&"object"==typeof r&&null!==r&&t.types.isProxy(r))return`invalid find of ${e}, ${Va.irregular}`;if(void 0!==r&&!ou(r))return`invalid find of ${e}, need an object`;let n=vu(r,Ha,!0);return null!==n?`invalid find of ${e}, ${Va[n]}`:null}catch(t){return`invalid find of ${e}, ${Va.unreadable}`}}function mu(e){return"function"==typeof e?!ru(e):"object"==typeof e&&null!==e&&(!ru(e)||nu(e))}function wu(e,t){let r;try{r=Array.isArray(t)}catch(t){return`${e}, ${Va.irregular}`}if(!r)return null;if(!ru(t))return`${e}, ${Va.irregular}`;let n=function(e){for(let t=0;t<e.length;t++){let r=Object.getOwnPropertyDescriptor(e,t);if(void 0===r)return[t,"sparse"];if(La(r))return[t,"accessor"]}return null}(t);return null!==n?Fa(`${e}, ${Va[n[1]]}`,[{k:n[0]}]):null}function ju(e,t){let r=new Map,n=(e,t)=>{r.has(e)||r.set(e,[]),r.get(e).push({k:t})};if(Ua(t))for(let e=0;e<t.length;e++)try{let r=Object.getOwnPropertyDescriptor(t,e);if(void 0===r)continue;if(La(r)){n("accessor",e);continue}let o=mu(r.value)?"irregular":vu(r.value);null!==o&&n(o,e)}catch(t){n("unreadable",e)}else{let e=mu(t)?"irregular":vu(t);null!==e&&n(e,0)}return eo([...r],(t=>{let[r,n]=t;return Fa(`${e}, ${Va[r]}`,n)}))}function Ou(e){let t=!Ua(e),r=eo(t?[e]:e,(e=>{let t=cu(e);return Wa(t)&&Ae(e)?function(e,t){let r={};for(let n of Reflect.ownKeys(e)){let o=Object.getOwnPropertyDescriptor(e,n);o.enumerable&&Object.defineProperty(r,n,"id"===n?{value:t,writable:!0,enumerable:!0,configurable:!0}:o)}return r}(e,Ra(t)):e}));return t?r[0]:r}function $u(e){return"obj"!==iu(e)?e:Ba(e,((e,t)=>{return"id"===t?"obj"!==iu(r=e)?Ra(r):Ba(r,((e,t)=>["$eq","$ne","$gt","$gte","$lt","$lte","$in","$nin"].indexOf(t)>=0?"arr"===iu(e)?eo(e,Ra):Ra(e):e)):["$and","$or"].indexOf(t)>=0&&"arr"===iu(e)?eo(e,$u):e;var r}))}function xu(e){let t=[];return $e(Ua(e)?e:[e],((e,r)=>{mu(e)||Ae(e)||t.push({k:r})})),t}function ku(e){let t=Ra(cu(e));return Xr(t)?t:null}function Su(e){let t=[];return $e(Ua(e)?e:[e],((e,r)=>{let n=cu(e);Xr(n)&&Ta(n)!==n&&t.push({k:r,id:n})})),t}function Au(e,t){return Fa(`${e}, id contains HTML markup`,eo(t,(e=>({k:e.k}))))}function _u(e,t,r){Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0})}function Pu(e,t,r,n){let o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"save",i=arguments.length>5&&void 0!==arguments[5]&&arguments[5];if(!Vr(e))throw console.log("ds",e),new Error("invalid ds");let a=e[t].keys,u=!1;Se(n)||(u=!0,n=[n]);let l=function(){if(!xe(co))throw new Error("invalid dayjs");return co().format("YYYY-MM-DDTHH:mm:ss.SSSZ")}();if(o.indexOf("insert")>=0&&(a.indexOf("userId")>=0&&$e(n,((e,t)=>{i&&function(e){if("object"!=typeof e||null===e)return!1;let t=Object.getOwnPropertyDescriptor(e,"userId");return void 0!==t&&t.enumerable&&!La(t)&&"string"==typeof t.value&&""!==t.value}(n[t])||_u(n[t],"userId",r)})),a.indexOf("timeCreate")>=0&&$e(n,((e,t)=>{_u(n[t],"timeCreate",l)})),a.indexOf("userIdUpdate")>=0&&$e(n,((e,t)=>{_u(n[t],"userIdUpdate",r)})),a.indexOf("timeUpdate")>=0&&$e(n,((e,t)=>{_u(n[t],"timeUpdate",l)}))),(o.indexOf("insert")>=0||o.indexOf("save")>=0)&&(a.indexOf("userIdUpdate")>=0&&$e(n,((e,t)=>{_u(n[t],"userIdUpdate",r)})),a.indexOf("timeUpdate")>=0&&$e(n,((e,t)=>{_u(n[t],"timeUpdate",l)}))),n=eo(n,(e=>Ba(e,(e=>Ta(e))))),za(e[t],a)){(u?Vr(n[0]):qr(n))&&$e(n,(e=>{Xr(e.id)||(e.id=yo())}))}return n=u?n[0]:n}async function Eu(e,t,r,n,o,i,a){try{return await async function(e,t,r,n,o,i,a){let u,l=null;if(!Vr(t))return Promise.reject("invalid woItems");let s=Na(t,n);if(null===s)return Promise.reject(`can not find table[${"string"==typeof n?n:""}] in ORM`);let c=function(e,t){let r=Na(e,t),n=jt(r,"keys",null);return!!Se(n)&&za(r,n)}(e,n),f=pu(o,a);if(null!==f.err)return Promise.reject(f.err);if("select"===o){let e=bu("select",i);if(null!==e)return su(`${n}.select invalid find`,i),Promise.reject(e);if(u=await s.select(c?$u(i):i).catch((e=>{console.log(`${n}.select catch`,e),l="failed to select data"})),Xr(l))return Promise.reject(l)}else if("insert"===o||"save"===o){let t=i,a="insert"===o?"failed to insert data":"failed to save data",d=wu(a,i);if(null!==d)return console.log(`${n}.${o} invalid batch container`),Promise.reject(d);let p=xu(i);if(Rr(p)>0)return console.log(`${n}.${o} data is not an object`,p),Promise.reject(Fa(`${a}, not an object`,p));let h=ju(a,i);if(Rr(h)>0)return console.log(`${n}.${o} data has unsupported key`,h),Promise.reject(ro(h,"; "));c&&(i=Ou(i));let g=Su(i);if(Rr(g)>0)return console.log(`${n}.${o} id changed by clearXSS`,g),Promise.reject(Au(a,g));try{i=Pu(e,n,r,i,o,f.keepUserId)}catch(e){return console.log(`${n}.adjustData catch`,e.toString()),l="failed to adjust data",Promise.reject(l)}if("save"===o&&f.mustExist){let e=await hu(s,i).catch((e=>{console.log(`${n}.save exist check catch`,e),l="failed to save data"}));if(Xr(l))return Promise.reject(l);if(e)return console.log(`${n}.save row not found`),Promise.reject("rowNotFound")}if("insert"===o?u=await s.insert(i).catch((e=>{console.log(`${n}.insert catch`,e),l="failed to insert data"})):"save"===o&&(u=await(f.mustExist?s.save(i,{autoInsert:!1}):s.save(i)).catch((e=>{console.log(`${n}.save catch`,e),l="failed to save data"}))),Xr(l))return Promise.reject(l);if("save"===o){let e=Ca(u,i);if(Rr(e)>0)return console.log(`${n}.save fail`,e),Promise.reject(Fa("failed to save data",Ca(u,t)));if(f.mustExist&&gu(u,null))return console.log(`${n}.save row not found after check`),Promise.reject("rowNotFound")}u=Se(i)?eo(i,(e=>({id:e.id}))):{id:i.id}}else if("del"===o){let e=wu("failed to delete data",i);if(null!==e)return console.log(`${n}.del invalid batch container`),Promise.reject(e);if(c&&(i=Ou(i)),f.mustExist){let e=function(e){let t=new Set,r=[],n=Ua(e)?e:[e];for(let e=0;e<n.length;e++){let o=cu(n[e]);if(!("string"==typeof o&&""!==o||Wa(o)))continue;let i=String(o);t.has(i)?r.push({k:e}):t.add(i)}return r}(i);if(Rr(e)>0)return console.log(`${n}.del duplicate id`,e),Promise.reject(Fa("invalid input of del, duplicate id",e));let t=await hu(s,i).catch((e=>{console.log(`${n}.del exist check catch`,e),l="failed to delete data"}));if(Xr(l))return Promise.reject(l);if(t)return console.log(`${n}.del row not found`),Promise.reject("rowNotFound")}if(u=await s.del(i).catch((e=>{console.log(`${n}.del catch`,e),l="failed to delete data"})),!Xr(l)){let e=Ca(u,i);Rr(e)>0&&(console.log(`${n}.del fail`,e),l=Fa("failed to delete data",e))}!Xr(l)&&f.mustExist&&gu(u,"nDeleted")&&(console.log(`${n}.del row not found after check`),l="rowNotFound")}else if("delAll"===o){let e=bu("delAll",i);if(null!==e)return su(`${n}.delAll invalid find`,i),Promise.reject(e);u=await s.delAll(c?$u(i):i).catch((e=>{console.log(`${n}.delAll catch`,e),l="failed to delete data"}))}else if("mix"===o){if("object"!=typeof i||null===i||!ru(i)||!Vr(i))return Promise.reject("invalid input of mix, need the result object of ltdtDiffByKey");let t={};for(let e of["add","del","diff"]){let r=Object.getOwnPropertyDescriptor(i,e);if(void 0!==r&&La(r))return Promise.reject(`invalid input of mix, ${Va.accessor}`);t[e]=void 0===r?void 0:r.value}i=t;for(let e of["add","del","diff"])if(void 0!==i[e]&&!Ua(i[e]))return Promise.reject("invalid input of mix, need the result object of ltdtDiffByKey");let o=[];for(let[e,t]of[["add","failed to insert data"],["del","failed to delete data"],["diff","failed to update data"]]){let r=wu(t,i[e]);null!==r&&o.push(r)}if(Rr(o)>0)return console.log(`${n}.mix invalid batch container`),Promise.reject(ro(o,"; "));let a=[];for(let[e,t]of[["add","failed to insert data"],["diff","failed to update data"]]){let r=xu(jt(i,e,[]));Rr(r)>0&&(console.log(`${n}.mix ${e} data is not an object`,r),a.push(Fa(`${t}, not an object`,r)))}if(Rr(a)>0)return Promise.reject(ro(a,"; "));let f=[];for(let[e,t]of[["add","failed to insert data"],["diff","failed to update data"]])f.push(...ju(t,jt(i,e,[])));if(Rr(f)>0)return console.log(`${n}.mix data has unsupported key`,f),Promise.reject(ro(f,"; "));let d=function(e){let t=[];return $e(e,((e,r)=>{if("object"==typeof e&&null!==e||"function"==typeof e)if(ru(e)){if("function"!=typeof e)for(let n=e;null!==n;n=Object.getPrototypeOf(n)){let o=Object.getOwnPropertyDescriptor(n,"id");if(void 0!==o)return void(n===e&&!La(o)&&o.enumerable||t.push({k:r}))}}else t.push({k:r})})),t}(jt(i,"del",[]));if(Rr(d)>0)return console.log(`${n}.mix del id is not an own data property`,d),Promise.reject(Fa(`failed to delete data, ${Va.irregular}`,d));if(c){i={...i};for(let e of["add","del","diff"])Se(i[e])&&(i[e]=Ou(i[e]))}let p=[];for(let[e,t]of[["add","failed to insert data"],["diff","failed to update data"]]){let r=Su(jt(i,e,[]));Rr(r)>0&&(console.log(`${n}.mix ${e} id changed by clearXSS`,r),p.push(Au(t,r)))}if(Rr(p)>0)return Promise.reject(ro(p,"; "));let h,g=function(e){let t=[];for(let[r,n]of[["add","del"],["del","diff"]]){let o=new Map;$e(jt(e,r,[]),((e,t)=>{let r=ku(e);null!==r&&o.set(r,[...o.get(r)||[],t])}));let i=[],a=[];if($e(jt(e,n,[]),((e,t)=>{let r=ku(e);null!==r&&o.has(r)&&(i=[...i,...o.get(r)],a.push(t))})),Rr(a)>0){let e=[...eo([...new Set(i)].sort(((e,t)=>e-t)),(e=>({ref:`${r}[${e}]`}))),...eo(a,(e=>({ref:`${n}[${e}]`})))];t.push(Fa(`invalid input of mix, same id in ${r} and ${n}`,e))}}return t}(i);if(Rr(g)>0)return console.log(`${n}.mix same id across steps`,g),Promise.reject(ro(g,"; "));u=[];let y=[],v=null;if(Rr(jt(i,"diff",[]))>0)try{v=Pu(e,n,r,jt(i,"diff",[]))}catch(e){return console.log(`${n}.adjustData catch`,e.toString()),l="failed to adjust data",Promise.reject(l)}let b=jt(i,"add",[]);if(Rr(b)>0){try{b=Pu(e,n,r,b,"insert+save")}catch(e){return console.log(`${n}.adjustData catch`,e.toString()),l="failed to adjust data",Promise.reject(l)}if(await s.insert(b).catch((e=>{console.log(`${n}.insert catch`,e),l="failed to insert data"})),Xr(l))return Promise.reject(l);h=eo(b,(e=>({id:e.id}))),u=[...u,...h]}let m=jt(i,"del",[]);if(Rr(m)>0){let e=await s.del(m).catch((e=>{console.log(`${n}.del catch`,e),l="failed to delete data"}));if(Xr(l))return Promise.reject(l);let t=Ca(e,m);Rr(t)>0&&(console.log(`${n}.del fail`,t),y.push(Fa("failed to delete data",t))),h=eo(m,(e=>({id:e.id}))),u=[...u,...h]}let w=jt(i,"diff",[]);if(Rr(w)>0){let e=w;w=v;let t=await s.save(w).catch((e=>{console.log(`${n}.save catch`,e),l="failed to update data"}));if(Xr(l))return Promise.reject(l);let r=Ca(t,w);Rr(r)>0&&(console.log(`${n}.save fail`,r),y.push(Fa("failed to update data",Ca(t,e)))),h=eo(w,(e=>({id:e.id}))),u=[...u,...h]}if(Rr(y)>0)return Promise.reject(ro(y,"; "))}else l=`invalid mode: ${o}`;if(Xr(l))return Promise.reject(l);return u}(e,t,r,n,o,i,a)}catch(e){return"string"==typeof e?Promise.reject(e):(uu(`${"string"==typeof n?n:""}.${"string"==typeof o?o:""} mapOrm catch`,e),Promise.reject("failed to process input"))}}function Iu(e,t){return async(r,n,o,i,a)=>Eu(e,t,r,n,o,i,a)}function Du(e,t,r){let n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(!xe(t)){let o=`${r} needs a function, but got ${typeof t}`;throw n&&e.push((()=>Promise.reject(o))),new Error(o)}setTimeout((()=>{e.push(t)}),1)}function Mu(e){if(Ot(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}),!xe(e))throw new Error("invalid mapOrm");let t={funChecks:[],funPreProcessing:[],funPostProcessing:[],mapOrm:e};return{addFunCheck:e=>{Du(t.funChecks,e,"addFunCheck",!0)},addFunPreProcessing:e=>{Du(t.funPreProcessing,e,"addFunPreProcessing")},addFunPostProcessing:e=>{Du(t.funPostProcessing,e,"addFunPostProcessing")},procOrm:async(e,r,n,o,i)=>async function(e,t,r,n,o,i){let a=pu(n,i);if(null!==a.err)return Promise.reject(a.err);await _e(e.funChecks,(e=>e({woName:r,userId:t,mode:n,input:o})));for(let i of[...e.funPreProcessing]){let e=await i({woName:r,userId:t,mode:n,input:o});if(!Vr(e)||void 0===e.input)return Promise.reject("invalid return of pre-processing, need an object with input");o=e.input}let u=await e.mapOrm(t,r,n,o,i);for(let i of[...e.funPostProcessing])u=await i({woName:r,userId:t,mode:n,input:o,output:u});return u}(t,e,r,n,o,i)}}return function(e,t,r,n){let o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};Ot(o);let i=function(e,t,r,n){if(!Vr(e))throw console.log("ds",e),new Error("invalid ds");if(!xe(t))throw console.log("WOrm",t),new Error("invalid WOrm");if(!Xr(r))throw console.log("url",r),new Error("invalid url");if(!Xr(n))throw console.log("db",n),new Error("invalid db");let o={};return $e(me(e),(e=>{let i=new t({url:r,db:n,cl:e});Object.defineProperty(o,e,{value:i,enumerable:!0,writable:!0,configurable:!0})})),o}(e,t,r,n),a=Mu(Iu(e,i),o),u=new function(){let e=new Map,t=new Map;return async(r,n)=>{let o=(e.get(r)||Promise.resolve()).then((async()=>await n()),(async()=>await n()));e.set(r,o.catch((()=>{}))),t.set(r,(t.get(r)||0)+1);try{return await o}finally{let n=t.get(r)-1;n<=0?(t.delete(r),e.delete(r)):t.set(r,n)}}},l=async(e,t)=>{let r=function(e,t,r){if(!Array.isArray(t)||0===t.length)throw new Error("invalid tableNames of withTabLocks, need a non-empty array of table names");for(let r of t)if("string"!=typeof r||!Object.prototype.hasOwnProperty.call(e,r))throw new Error("invalid tableNames of withTabLocks, need own table names of this instance");if(!xe(r))throw new Error("invalid fn of withTabLocks, need a function");return[...new Set(t)].sort()}(i,e,t),n=t;for(let e=r.length-1;e>=0;e--){let t=n,o=r[e];n=()=>u(o,t)}return n()};return{...Gr,woItems:i,closeAll:async()=>{await _e(i,(async e=>{e&&xe(e.close)&&await e.close()}))},withTabLocks:l,guardWrite:async e=>{if(null===e||"object"!=typeof e)throw new Error("invalid input of guardWrite, need an object");let{tables:t,read:r,baseline:n,contract:o,write:i}=e;if(!xe(r))throw new Error("invalid read of guardWrite, need a function");if(!xe(i))throw new Error("invalid write of guardWrite, need a function");let a=void 0!==n;if((a||void 0!==o)&&(Ct(o),"string"==typeof o.table&&!(Array.isArray(t)&&t.indexOf(o.table)>=0)))throw new Error("invalid tables of guardWrite, need to contain contract.table");return l(t,(async()=>{let e=await r();if(!Array.isArray(e))throw new Error("invalid rows of guardWrite, read needs to resolve an array");if(a){let t=Rt(e,n,o);if(!t.ok)throw function(e){let t=new Error(e.reason);return t.key=e.reason,t.added=e.added,t.removed=e.removed,t.changed=e.changed,t.reordered=e.reordered,t}(t)}return await i(e)}))},...a}}}));
|
|
7
7
|
//# sourceMappingURL=w-serv-orm.umd.js.map
|