buckyos 0.7.192 → 0.7.193
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/cli/dist/cli.mjs +1 -1
- package/cli/dist/cli.mjs.map +1 -1
- package/cli/version.ts +1 -1
- package/dist/aiws_bind-1a26e3e6.js +2 -0
- package/dist/aiws_bind-1a26e3e6.js.map +1 -0
- package/dist/{aiws_bind-1316a842.mjs → aiws_bind-ec6fe2d5.mjs} +510 -48
- package/dist/aiws_bind-ec6fe2d5.mjs.map +1 -0
- package/dist/aiws_bind.d.ts +2 -2
- package/dist/aiws_bind.d.ts.map +1 -1
- package/dist/aiws_ext.cjs +1 -1
- package/dist/aiws_ext.mjs +1 -1
- package/dist/aiws_rrule.d.ts +3 -1
- package/dist/aiws_rrule.d.ts.map +1 -1
- package/dist/aiws_schedule.d.ts +3 -1
- package/dist/aiws_schedule.d.ts.map +1 -1
- package/dist/{aiws_write-38628168.mjs → aiws_write-07562abc.mjs} +2 -2
- package/dist/{aiws_write-38628168.mjs.map → aiws_write-07562abc.mjs.map} +1 -1
- package/dist/{aiws_write-e8fe62de.js → aiws_write-1f179e1c.js} +2 -2
- package/dist/{aiws_write-e8fe62de.js.map → aiws_write-1f179e1c.js.map} +1 -1
- package/dist/browser.cjs +1 -1
- package/dist/browser.mjs +4 -4
- package/dist/{content_objid-5cb7c7ec.js → content_objid-17daaa69.js} +2 -2
- package/dist/{content_objid-5cb7c7ec.js.map → content_objid-17daaa69.js.map} +1 -1
- package/dist/{content_objid-2977da18.mjs → content_objid-7605d166.mjs} +2 -2
- package/dist/{content_objid-2977da18.mjs.map → content_objid-7605d166.mjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +4 -4
- package/dist/node.cjs +1 -1
- package/dist/node.mjs +3 -3
- package/package.json +1 -1
- package/dist/aiws_bind-1316a842.mjs.map +0 -1
- package/dist/aiws_bind-7045442e.js +0 -2
- package/dist/aiws_bind-7045442e.js.map +0 -1
package/cli/version.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Generated by scripts/generate-cli-version.mjs. Do not edit.
|
|
2
|
-
export const PACKAGE_VERSION = '0.7.
|
|
2
|
+
export const PACKAGE_VERSION = '0.7.193'
|
|
3
3
|
export const TOOL_VERSION = PACKAGE_VERSION
|
|
4
4
|
export const SDK_VERSION = PACKAGE_VERSION
|
|
5
5
|
export const PROTOCOL_VERSION = '1'
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const e=require("./object_url-88047ee2.js");class t extends Error{constructor(e){super(`${e.code}${e.sub_code?`/${e.sub_code}`:""}: ${e.detail}`),this.name="AiwsFailure",this.code=e.code,this.subCode=e.sub_code,this.data=e.data}}function n(e){return e.startsWith("/")||e.startsWith("~")?{path:e}:{entity_id:e}}const r=6291456,o=33554432,a=5e4,i=new TextEncoder;function s(e){const t=JSON.stringify(e);return t.length+(/[^\x00-\x7f]/.test(t)?i.encode(t).length-t.length:0)}function l(e,t=6291456){const n=[];let r=[],o=2;for(const a of e){const e=s(a)+1;r.length>0&&o+e>t&&(n.push(r),r=[],o=2),r.push(a),o+=e}return(r.length>0||0===n.length)&&n.push(r),n}async function d(e,t,n={}){var o,a;const i=n.method??"doc.commit",s=l(Array.isArray(t.operations)?t.operations:[],n.partBytes??r);if(s.length<=1)return await e(i,t);const{workspace_id:d,epoch:c,idempotency_key:u}=t;for(let r=0;;r++){const l=[];for(let t=0;t<s.length-1;t++){null==(o=n.onPart)||o.call(n,t+1,s.length);const r=await e("doc.stage",{workspace_id:d,epoch:c,idempotency_key:u,part:t,operations:s[t]});if(!r||!1===r.ok||"string"!=typeof r.digest){const e=(null==r?void 0:r.error)??{code:"STORAGE_IO_ERROR",retryable:!0,detail:"doc.stage returned no digest"};return{status:"rejected",code:e.code,retryable:e.retryable,detail:e.detail,...e.sub_code?{sub_code:e.sub_code}:{},errors:[e]}}l.push(r.digest)}null==(a=n.onPart)||a.call(n,s.length,s.length);const y=await e(i,{...t,staged:l,operations:s[s.length-1]});if(0!==r||"rejected"!==(null==y?void 0:y.status)||"STAGED_PARTS_MISSING"!==y.sub_code)return y}}const c=["MO","TU","WE","TH","FR","SA","SU"];class u extends Error{constructor(e){super(e),this.name="RRuleError"}}const y=["DAILY","WEEKLY","MONTHLY","YEARLY"];function h(e,t,n,r,o=!1){if(!/^[+-]?\d{1,3}$/.test(t))throw new u(`${e}: ${t} is not a number`);const a=Number(t);if(a<n||a>r||!o&&0===a)throw new u(`${e}: ${t} is out of range`);return a}function p(e,t,n){const r=t.split(",");if(0===r.length||r.length>n||r.some((e=>""===e)))throw new u(`${e}: at most ${n} comma-separated values`);return r}function f(e){const t=e.startsWith("RRULE:")?e.slice(6):e;if(""===t.trim())throw new u("empty rule");const n=new Set,r={};for(const i of t.split(";")){const e=i.indexOf("=");if(e<=0)throw new u(`${i||"(empty)"}: expected NAME=VALUE`);const t=i.slice(0,e),o=i.slice(e+1);if(t!==t.toUpperCase()||o!==o.toUpperCase())throw new u(`${i}: write the rule in upper case`);if(n.has(t))throw new u(`${t}: given twice`);if(n.add(t),!["FREQ","INTERVAL","COUNT","UNTIL","BYDAY","BYMONTHDAY","BYMONTH","BYSETPOS","WKST"].includes(t))throw new u(`${t}: not supported (supported: FREQ, INTERVAL, COUNT, UNTIL, BYDAY, BYMONTHDAY, BYMONTH, BYSETPOS, WKST)`);if(""===o)throw new u(`${t}: empty value`);r[t]=o}if(!r.FREQ)throw new u("FREQ is required");if(!y.includes(r.FREQ))throw new u(`FREQ: ${r.FREQ} is not supported (DAILY, WEEKLY, MONTHLY, YEARLY)`);const o=r.FREQ,a={freq:o,interval:1,wkst:0};if(void 0!==r.INTERVAL&&(a.interval=h("INTERVAL",r.INTERVAL,1,999)),void 0!==r.COUNT&&void 0!==r.UNTIL)throw new u("COUNT and UNTIL cannot both be given");if(void 0!==r.COUNT&&(a.count=h("COUNT",r.COUNT,1,1e3)),void 0!==r.UNTIL&&(a.until=function(e){let t=/^(\d{4})(\d{2})(\d{2})$/.exec(e);if(t){const n=`${t[1]}-${t[2]}-${t[3]}`;if(!_(n))throw new u(`UNTIL: ${e} is not a date`);return n}if(t=/^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z$/.exec(e),t){const n=Date.UTC(+t[1],+t[2]-1,+t[3],+t[4],+t[5],+t[6]);if(!_(`${t[1]}-${t[2]}-${t[3]}`)||+t[4]>23||+t[5]>59||+t[6]>59)throw new u(`UNTIL: ${e} is not a UTC time`);return new Date(n).toISOString()}throw new u(`UNTIL: ${e} must be YYYYMMDD or YYYYMMDDTHHMMSSZ`)}(r.UNTIL)),void 0!==r.BYDAY){a.byDay=p("BYDAY",r.BYDAY,7).map((e=>{const t=/^([+-]?\d)?(MO|TU|WE|TH|FR|SA|SU)$/.exec(e);if(!t)throw new u(`BYDAY: ${e} is not a weekday`);const n=c.indexOf(t[2]);if(void 0===t[1])return{weekday:n};if("MONTHLY"!==o&&"YEARLY"!==o)throw new u(`BYDAY: ${e}: an ordinal needs FREQ=MONTHLY or YEARLY`);return{weekday:n,ordinal:h("BYDAY",t[1],-5,5)}}));const e=a.byDay.map((e=>`${e.ordinal??""}${e.weekday}`));if(new Set(e).size!==e.length)throw new u("BYDAY: repeated day")}if(void 0!==r.BYMONTHDAY){if("MONTHLY"!==o&&"YEARLY"!==o)throw new u("BYMONTHDAY needs FREQ=MONTHLY or YEARLY");if(a.byMonthDay=p("BYMONTHDAY",r.BYMONTHDAY,31).map((e=>h("BYMONTHDAY",e,-1,31))),new Set(a.byMonthDay).size!==a.byMonthDay.length)throw new u("BYMONTHDAY: repeated day")}if(void 0!==r.BYMONTH){if("YEARLY"!==o)throw new u("BYMONTH needs FREQ=YEARLY");if(a.byMonth=p("BYMONTH",r.BYMONTH,12).map((e=>h("BYMONTH",e,1,12))),new Set(a.byMonth).size!==a.byMonth.length)throw new u("BYMONTH: repeated month")}if(void 0!==r.BYSETPOS){if("MONTHLY"!==o||!a.byDay)throw new u("BYSETPOS needs FREQ=MONTHLY and BYDAY");a.bySetPos=h("BYSETPOS",r.BYSETPOS,-5,5)}if(void 0!==r.WKST){const e=c.indexOf(r.WKST);if(e<0)throw new u(`WKST: ${r.WKST} is not a weekday`);a.wkst=e}return a}function m(e){var t,n,r;const o=[`FREQ=${e.freq}`];return e.interval>1&&o.push(`INTERVAL=${e.interval}`),(null==(t=e.byMonth)?void 0:t.length)&&o.push(`BYMONTH=${e.byMonth.join(",")}`),(null==(n=e.byMonthDay)?void 0:n.length)&&o.push(`BYMONTHDAY=${e.byMonthDay.join(",")}`),(null==(r=e.byDay)?void 0:r.length)&&o.push(`BYDAY=${e.byDay.map((e=>`${e.ordinal??""}${c[e.weekday]}`)).join(",")}`),void 0!==e.bySetPos&&o.push(`BYSETPOS=${e.bySetPos}`),void 0!==e.count&&o.push(`COUNT=${e.count}`),void 0!==e.until&&o.push(`UNTIL=${10===e.until.length?e.until.replace(/-/g,""):e.until.replace(/[-:]/g,"").replace(/\.\d{3}/,"")}`),0!==e.wkst&&o.push(`WKST=${c[e.wkst]}`),o.join(";")}function _(e){const t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!t)return!1;const n=+t[1],r=+t[2],o=+t[3];return n>=1&&r>=1&&r<=12&&o>=1&&o<=g(n,r)}const w=e=>e%4==0&&e%100!=0||e%400==0;function g(e,t){return[31,w(e)?29:28,31,30,31,30,31,31,30,31,30,31][t-1]}const $=(e,t,n)=>Math.floor(Date.UTC(e,t-1,n)/864e5);function b(e){return $(+e.slice(0,4),+e.slice(5,7),+e.slice(8,10))}function D(e){return new Date(864e5*e).toISOString().slice(0,10)}function v(e){const t=new Date(864e5*e);return{y:t.getUTCFullYear(),m:t.getUTCMonth()+1,d:t.getUTCDate()}}const k=e=>((e+3)%7+7)%7,x=new Map;function O(e){let t=x.get(e);return t||(t=new Intl.DateTimeFormat("en-US",{timeZone:e,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}),x.set(e,t)),t}function M(e){try{return O(e),!0}catch{return!1}}function T(e,t){const n={};for(const r of O(t).formatToParts(new Date(e)))"literal"!==r.type&&(n[r.type]=Number(r.value));return{y:n.year,m:n.month,d:n.day,h:24===n.hour?0:n.hour,mi:n.minute,s:n.second}}function S(e,t){const n=T(e,t);return Date.UTC(n.y,n.m-1,n.d,n.h,n.mi,n.s)-1e3*Math.floor(e/1e3)}function E(e,t,n,r){const o=864e5*e+6e4*t+1e3*n,a=o-S(o,r);return o-S(a,r)}function A(e,t){const n=T(e,t);return $(n.y,n.m,n.d)}function Y(e,t,n){const r=v(n),o=[],a=(e,t,n)=>{for(let r=0;r<t;r++)n.some((t=>void 0===t.ordinal&&t.weekday===k(e+r)))&&o.push(e+r)},i=(e,t,n)=>{const r=[];for(let o=0;o<t;o++)k(e+o)===n.weekday&&r.push(e+o);const a=n.ordinal>0?n.ordinal-1:r.length+n.ordinal;a>=0&&a<r.length&&o.push(r[a])},s=(e,t,n)=>{const r=g(e,t);for(const a of n){const n=a>0?a:r+a+1;n>=1&&n<=r&&o.push($(e,t,n))}};switch(e.freq){case"DAILY":{const r=n+t*e.interval,{m:a,d:i}=v(r);if(e.byMonth&&!e.byMonth.includes(a))break;if(e.byMonthDay&&!e.byMonthDay.some((e=>e>0?e===i:g(v(r).y,a)+e+1===i)))break;if(e.byDay&&!e.byDay.some((e=>e.weekday===k(r))))break;o.push(r);break}case"WEEKLY":if(a(n-(k(n)-e.wkst+7)%7+t*e.interval*7,7,e.byDay??[{weekday:k(n)}]),e.byMonth)return o.filter((t=>e.byMonth.includes(v(t).m))).sort(((e,t)=>e-t));break;case"MONTHLY":{const n=12*r.y+(r.m-1)+t*e.interval,l=Math.floor(n/12),d=n%12+1,c=$(l,d,1),u=g(l,d);if(e.byMonthDay){if(s(l,d,e.byMonthDay),e.byDay){const t=o.filter((t=>e.byDay.some((e=>e.weekday===k(t)))));o.length=0,o.push(...t)}}else if(e.byDay){a(c,u,e.byDay);for(const t of e.byDay)void 0!==t.ordinal&&i(c,u,t)}else r.d<=u&&o.push($(l,d,r.d));break}case"YEARLY":{const n=r.y+t*e.interval;if(e.byDay&&!e.byMonth&&!e.byMonthDay){const t=$(n,1,1),r=w(n)?366:365;a(t,r,e.byDay);for(const n of e.byDay)void 0!==n.ordinal&&i(t,r,n);break}const l=e.byMonth??[r.m];for(const t of l)if(e.byMonthDay)s(n,t,e.byMonthDay);else if(e.byDay){const r=$(n,t,1),o=g(n,t);a(r,o,e.byDay);for(const t of e.byDay)void 0!==t.ordinal&&i(r,o,t)}else r.d<=g(n,t)&&o.push($(n,t,r.d));if(e.byMonthDay&&e.byDay){const t=o.filter((t=>e.byDay.some((e=>e.weekday===k(t)))));o.length=0,o.push(...t)}break}}const l=[...new Set(o)].sort(((e,t)=>e-t));if(void 0!==e.bySetPos){const t=e.bySetPos>0?e.bySetPos-1:l.length+e.bySetPos;return t>=0&&t<l.length?[l[t]]:[]}return l}function j(e,t,n){const r=v(n);switch(e.freq){case"DAILY":return n+t*e.interval;case"WEEKLY":return n-(k(n)-e.wkst+7)%7+t*e.interval*7;case"MONTHLY":{const n=12*r.y+(r.m-1)+t*e.interval;return $(Math.floor(n/12),n%12+1,1)}case"YEARLY":return $(r.y+t*e.interval,1,1)}}function N(e,t,n,r={}){var o;const a=r.limit??2e3,i=new Set(r.exdate??[]),s=[];let l,d,c,u=0,y=0,h="UTC";const p=r.viewerTz??"UTC";if("date"===t.kind)l=b(t.date),d=A(n.fromMs,p)-(r.durationDays??0),c=A(n.toMs-1,p);else{h=t.tz;const e=T(Date.parse(t.utc),h);l=$(e.y,e.m,e.d),u=60*e.h+e.mi,y=e.s,d=A(n.fromMs-(r.durationMs??0),h)-1,c=A(n.toMs,h)+1}const f=10===(null==(o=e.until)?void 0:o.length)?b(e.until):void 0,m=e.until&&e.until.length>10?Date.parse(e.until):void 0;let _=0;const w=o=>{if(void 0!==e.count&&_>=e.count)return!1;if(void 0!==f&&o>f)return!1;let a;if("date"===t.kind){if(void 0!==m&&864e5*o>m)return!1;const e=D(o);a={original:e,date:e}}else{const e=E(o,u,y,h);if(void 0!==m&&e>m)return!1;a={original:new Date(e).toISOString(),startMs:e}}return _+=1,i.has(a.original)||("date"===t.kind?o>=d&&o<=c&&s.push(a):a.startMs+(r.durationMs??0)>n.fromMs&&a.startMs<n.toMs&&s.push(a)),!0};if(l>c||!w(l))return s;let g=void 0===e.count?function(e,t,n){const r=v(t),o=v(n);let a;switch(e.freq){case"DAILY":a=Math.floor((n-t)/e.interval);break;case"WEEKLY":a=Math.floor((n-j(e,0,t))/(7*e.interval));break;case"MONTHLY":a=Math.floor((12*o.y+o.m-(12*r.y+r.m))/e.interval);break;case"YEARLY":a=Math.floor((o.y-r.y)/e.interval)}return Math.max(-1,a-1)}(e,l,d)+1:0;for(let $=0;$<2e5&&s.length<a&&!(j(e,g,l)>c);$++,g++)for(const t of Y(e,g,l))if(!(t<=l)){if(t>c)return s;if(!w(t)||s.length>=a)return s}return s}function I(e,t,n="UTC"){return!0===e.all_day?"string"==typeof e.start_date?{kind:"date",date:e.start_date}:null:"string"==typeof e.start?{kind:"datetime",utc:e.start,tz:t&&M(t)?t:n}:null}function L(e,t){return`${e}@${t}`}const C=e=>t=>t.length>1?`${t.slice(0,-1).join(", ")} ${e} ${t[t.length-1]}`:t.join(""),R=(e,t,n,r)=>{const o=e%10,a=e%100;return 1===o&&11!==a?t:o>=2&&o<=4&&(a<12||a>14)?n:r},B={1:"第一个",2:"第二个",3:"第三个",4:"第四个",5:"第五个",[-1]:"最后一个",[-2]:"倒数第二个",[-3]:"倒数第三个",[-4]:"倒数第四个",[-5]:"倒数第五个"},U=["周一","周二","周三","周四","周五","周六","周日"],F={day:e=>U[e],nth:(e,t)=>`${B[e]}${U[t]}`,nthWorkday:e=>`${B[e]}工作日`,nthOf:(e,t)=>`${B[e]}${t.map((e=>U[e])).join("、")}`,monthlyDays:e=>e.join("、"),monthDay:e=>-1===e?"最后一天":`${e} 日`,join:e=>e.join("、"),daily:e=>1===e?"每天":`每 ${e} 天`,workdays:"每个工作日",weekly:(e,t)=>`${1===e?"每周":`每 ${e} 周的`}${t}`,monthly:(e,t)=>`${1===e?"每月":`每 ${e} 个月的`}${t}`,yearly:(e,t,n,r)=>`${1===e?"每年":`每 ${e} 年的`}${t?t.map((e=>`${e} 月`)).join("、"):""}${n?n.map(F.monthDay).join("、"):r?r.join("、"):""}`,count:e=>`,共 ${e} 次`,until:e=>`,到 ${e} 为止`,preset:{none:"不重复",daily:"每天",weekdays:"每个工作日(周一至周五)",weekly:e=>`每周的${U[e]}`,monthlyDay:e=>`每月 ${e} 日`,monthlyNth:(e,t)=>`每月${B[e]}${U[t]}`,monthlyLast:e=>`每月最后一个${U[e]}`,yearly:(e,t)=>`每年 ${e} 月 ${t} 日`}},W={1:"第一個",2:"第二個",3:"第三個",4:"第四個",5:"第五個",[-1]:"最後一個",[-2]:"倒數第二個",[-3]:"倒數第三個",[-4]:"倒數第四個",[-5]:"倒數第五個"},H=["週一","週二","週三","週四","週五","週六","週日"],q={day:e=>H[e],nth:(e,t)=>`${W[e]}${H[t]}`,nthWorkday:e=>`${W[e]}工作日`,nthOf:(e,t)=>`${W[e]}${t.map((e=>H[e])).join("、")}`,monthlyDays:e=>e.join("、"),monthDay:e=>-1===e?"最後一天":`${e} 日`,join:e=>e.join("、"),daily:e=>1===e?"每天":`每 ${e} 天`,workdays:"每個工作日",weekly:(e,t)=>`${1===e?"每週":`每 ${e} 週的`}${t}`,monthly:(e,t)=>`${1===e?"每月":`每 ${e} 個月的`}${t}`,yearly:(e,t,n,r)=>`${1===e?"每年":`每 ${e} 年的`}${t?t.map((e=>`${e} 月`)).join("、"):""}${n?n.map(q.monthDay).join("、"):r?r.join("、"):""}`,count:e=>`,共 ${e} 次`,until:e=>`,到 ${e} 為止`,preset:{none:"不重複",daily:"每天",weekdays:"每個工作日(週一至週五)",weekly:e=>`每週的${H[e]}`,monthlyDay:e=>`每月 ${e} 日`,monthlyNth:(e,t)=>`每月${W[e]}${H[t]}`,monthlyLast:e=>`每月最後一個${H[e]}`,yearly:(e,t)=>`每年 ${e} 月 ${t} 日`}},z={1:"first",2:"second",3:"third",4:"fourth",5:"fifth",[-1]:"last",[-2]:"second to last",[-3]:"third to last",[-4]:"fourth to last",[-5]:"fifth to last"},P=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],K=["January","February","March","April","May","June","July","August","September","October","November","December"],Q={day:e=>P[e],nth:(e,t)=>`${z[e]} ${P[t]}`,nthWorkday:e=>`the ${z[e]} weekday`,nthOf:(e,t)=>1===t.length?`the ${z[e]} ${P[t[0]]}`:`the ${z[e]} of ${C("and")(t.map((e=>P[e])))}`,monthlyDays:e=>`the ${C("and")(e)}`,monthDay:e=>-1===e?"the last day":`day ${e}`,join:C("and"),daily:e=>1===e?"every day":`every ${e} days`,workdays:"every weekday",weekly:(e,t)=>`${1===e?"every week":`every ${e} weeks`}${t?` on ${t}`:""}`,monthly:(e,t)=>`${1===e?"every month":`every ${e} months`}${t?` on ${t}`:""}`,yearly:(e,t,n,r)=>{let o=t?C("and")(t.map((e=>K[e-1]))):"";return n?o+=` ${C("and")(n.map((e=>-1===e?"last day":String(e))))}`:r&&(o+=` on the ${C("and")(r)}`),`${1===e?"every year":`every ${e} years`}${o.trim()?` in ${o.trim()}`:""}`},count:e=>`, ${e} times`,until:e=>`, until ${e}`,preset:{none:"Does not repeat",daily:"Daily",weekdays:"Every weekday (Monday to Friday)",weekly:e=>`Weekly on ${P[e]}`,monthlyDay:e=>`Monthly on day ${e}`,monthlyNth:(e,t)=>`Monthly on the ${z[e]} ${P[t]}`,monthlyLast:e=>`Monthly on the last ${P[e]}`,yearly:(e,t)=>`Annually on ${K[e-1]} ${t}`}},J=["月曜日","火曜日","水曜日","木曜日","金曜日","土曜日","日曜日"],V=e=>e>0?`第${e}`:-1===e?"最終":`最後から${-e}番目の`,Z={day:e=>J[e],nth:(e,t)=>`${V(e)}${J[t]}`,nthWorkday:e=>`${V(e)}平日`,nthOf:(e,t)=>`${V(e)}${t.map((e=>J[e])).join("・")}`,monthlyDays:e=>e.join("、"),monthDay:e=>-1===e?"最終日":`${e}日`,join:e=>e.join("、"),daily:e=>1===e?"毎日":`${e}日ごと`,workdays:"毎週平日",weekly:(e,t)=>1===e?`毎週${t}`:`${e}週間ごと${t?`の${t}`:""}`,monthly:(e,t)=>1===e?`毎月${t}`:`${e}か月ごと${t?`の${t}`:""}`,yearly:(e,t,n,r)=>{const o=`${t?t.map((e=>`${e}月`)).join("、"):""}${n?n.map(Z.monthDay).join("、"):r?r.join("、"):""}`;return 1===e?`毎年${o}`:`${e}年ごと${o?`の${o}`:""}`},count:e=>`、${e}回`,until:e=>`、${e}まで`,preset:{none:"繰り返さない",daily:"毎日",weekdays:"毎週平日(月曜日~金曜日)",weekly:e=>`毎週${J[e]}`,monthlyDay:e=>`毎月${e}日`,monthlyNth:(e,t)=>`毎月第${e}${J[t]}`,monthlyLast:e=>`毎月最終${J[e]}`,yearly:(e,t)=>`毎年${e}月${t}日`}},G=["월요일","화요일","수요일","목요일","금요일","토요일","일요일"],X={1:"첫째",2:"둘째",3:"셋째",4:"넷째",5:"다섯째",[-1]:"마지막",[-2]:"끝에서 둘째",[-3]:"끝에서 셋째",[-4]:"끝에서 넷째",[-5]:"끝에서 다섯째"},ee=(e,t)=>t?`${e} ${t}`:e,te={day:e=>G[e],nth:(e,t)=>`${X[e]} ${G[t]}`,nthWorkday:e=>`${X[e]} 평일`,nthOf:(e,t)=>`${X[e]} ${t.map((e=>G[e])).join("·")}`,monthlyDays:e=>e.join(", "),monthDay:e=>-1===e?"마지막 날":`${e}일`,join:e=>e.join(", "),daily:e=>1===e?"매일":`${e}일마다`,workdays:"매주 평일",weekly:(e,t)=>ee(1===e?"매주":`${e}주마다`,t),monthly:(e,t)=>ee(1===e?"매월":`${e}개월마다`,t),yearly:(e,t,n,r)=>{const o=[t?t.map((e=>`${e}월`)).join(", "):"",n?n.map(te.monthDay).join(", "):r?r.join(", "):""].filter(Boolean).join(" ");return ee(1===e?"매년":`${e}년마다`,o)},count:e=>`, ${e}회`,until:e=>`, ${e}까지`,preset:{none:"반복 안 함",daily:"매일",weekdays:"매주 평일(월요일~금요일)",weekly:e=>`매주 ${G[e]}`,monthlyDay:e=>`매월 ${e}일`,monthlyNth:(e,t)=>`매월 ${X[e]} ${G[t]}`,monthlyLast:e=>`매월 마지막 ${G[e]}`,yearly:(e,t)=>`매년 ${e}월 ${t}일`}},ne=["lundi","mardi","mercredi","jeudi","vendredi","samedi","dimanche"],re=["janvier","février","mars","avril","mai","juin","juillet","août","septembre","octobre","novembre","décembre"],oe={1:"premier",2:"deuxième",3:"troisième",4:"quatrième",5:"cinquième"},ae=(e,t)=>e>0?`le ${oe[e]} ${t}`:-1===e?`le dernier ${t}`:-2===e?`l'avant-dernier ${t}`:`le ${oe[-e]} ${t} avant la fin`,ie=e=>1===e?"1er":String(e),se=(e,t)=>t?`${e} ${t}`:e,le={day:e=>`le ${ne[e]}`,nth:(e,t)=>ae(e,ne[t]),nthWorkday:e=>ae(e,"jour ouvrable"),nthOf:(e,t)=>ae(e,1===t.length?ne[t[0]]:`jour parmi ${C("et")(t.map((e=>ne[e])))}`),monthlyDays:e=>C("et")(e),monthDay:e=>-1===e?"le dernier jour":`le ${ie(e)}`,join:C("et"),daily:e=>1===e?"tous les jours":`tous les ${e} jours`,workdays:"tous les jours ouvrables",weekly:(e,t)=>se(1===e?"toutes les semaines":`toutes les ${e} semaines`,t),monthly:(e,t)=>se(1===e?"tous les mois":`tous les ${e} mois`,t),yearly:(e,t,n,r)=>{let o;return o=1===(null==t?void 0:t.length)&&1===(null==n?void 0:n.length)?-1===n[0]?`le dernier jour de ${re[t[0]-1]}`:`le ${ie(n[0])} ${re[t[0]-1]}`:[n?C("et")(n.map(le.monthDay)):r?C("et")(r):"",t?`en ${C("et")(t.map((e=>re[e-1])))}`:""].filter(Boolean).join(" "),se(1===e?"tous les ans":`tous les ${e} ans`,o)},count:e=>`, ${e} fois`,until:e=>`, jusqu’au ${e}`,preset:{none:"Ne se répète pas",daily:"Tous les jours",weekdays:"Tous les jours ouvrables (du lundi au vendredi)",weekly:e=>`Toutes les semaines le ${ne[e]}`,monthlyDay:e=>`Tous les mois le ${ie(e)}`,monthlyNth:(e,t)=>`Tous les mois ${ae(e,ne[t])}`,monthlyLast:e=>`Tous les mois le dernier ${ne[e]}`,yearly:(e,t)=>`Tous les ans le ${ie(t)} ${re[e-1]}`}},de=["Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag","Sonntag"],ce=["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"],ue={1:"ersten",2:"zweiten",3:"dritten",4:"vierten",5:"fünften",[-1]:"letzten",[-2]:"vorletzten",[-3]:"drittletzten",[-4]:"viertletzten",[-5]:"fünftletzten"},ye=(e,t)=>t?`${e} ${t}`:e,he={day:e=>`am ${de[e]}`,nth:(e,t)=>`am ${ue[e]} ${de[t]}`,nthWorkday:e=>`am ${ue[e]} Werktag`,nthOf:(e,t)=>1===t.length?`am ${ue[e]} ${de[t[0]]}`:`am ${ue[e]} Tag aus ${C("und")(t.map((e=>de[e])))}`,monthlyDays:e=>C("und")(e),monthDay:e=>-1===e?"am letzten Tag":`am ${e}.`,join:C("und"),daily:e=>1===e?"täglich":`alle ${e} Tage`,workdays:"an jedem Werktag",weekly:(e,t)=>ye(1===e?"wöchentlich":`alle ${e} Wochen`,t),monthly:(e,t)=>ye(1===e?"monatlich":`alle ${e} Monate`,t),yearly:(e,t,n,r)=>{let o;return o=1===(null==t?void 0:t.length)&&1===(null==n?void 0:n.length)?-1===n[0]?`am letzten Tag im ${ce[t[0]-1]}`:`am ${n[0]}. ${ce[t[0]-1]}`:[n?C("und")(n.map(he.monthDay)):r?C("und")(r):"",t?`im ${C("und")(t.map((e=>ce[e-1])))}`:""].filter(Boolean).join(" "),ye(1===e?"jährlich":`alle ${e} Jahre`,o)},count:e=>`, ${e}-mal`,until:e=>`, bis ${e}`,preset:{none:"Wiederholt sich nicht",daily:"Täglich",weekdays:"Jeden Werktag (Montag bis Freitag)",weekly:e=>`Wöchentlich am ${de[e]}`,monthlyDay:e=>`Monatlich am ${e}.`,monthlyNth:(e,t)=>`Monatlich am ${ue[e]} ${de[t]}`,monthlyLast:e=>`Monatlich am letzten ${de[e]}`,yearly:(e,t)=>`Jährlich am ${t}. ${ce[e-1]}`}},pe=["lunes","martes","miércoles","jueves","viernes","sábado","domingo"],fe=["enero","febrero","marzo","abril","mayo","junio","julio","agosto","septiembre","octubre","noviembre","diciembre"],me={1:"primer",2:"segundo",3:"tercer",4:"cuarto",5:"quinto",[-1]:"último",[-2]:"penúltimo",[-3]:"antepenúltimo",[-4]:"cuarto desde el final",[-5]:"quinto desde el final"},_e=(e,t)=>e<-3?`el ${me[-e]} ${t} desde el final`:`el ${me[e]} ${t}`,we=(e,t)=>t?`${e} ${t}`:e,ge={day:e=>`el ${pe[e]}`,nth:(e,t)=>_e(e,pe[t]),nthWorkday:e=>_e(e,"día laborable"),nthOf:(e,t)=>_e(e,1===t.length?pe[t[0]]:`día entre ${C("y")(t.map((e=>pe[e])))}`),monthlyDays:e=>C("y")(e),monthDay:e=>-1===e?"el último día":`el día ${e}`,join:C("y"),daily:e=>1===e?"todos los días":`cada ${e} días`,workdays:"todos los días laborables",weekly:(e,t)=>we(1===e?"cada semana":`cada ${e} semanas`,t),monthly:(e,t)=>we(1===e?"cada mes":`cada ${e} meses`,t),yearly:(e,t,n,r)=>{let o;return o=1===(null==t?void 0:t.length)&&1===(null==n?void 0:n.length)?-1===n[0]?`el último día de ${fe[t[0]-1]}`:`el ${n[0]} de ${fe[t[0]-1]}`:[n?C("y")(n.map(ge.monthDay)):r?C("y")(r):"",t?`de ${C("y")(t.map((e=>fe[e-1])))}`:""].filter(Boolean).join(" "),we(1===e?"cada año":`cada ${e} años`,o)},count:e=>`, ${e} veces`,until:e=>`, hasta el ${e}`,preset:{none:"No se repite",daily:"Todos los días",weekdays:"Todos los días laborables (de lunes a viernes)",weekly:e=>`Cada semana el ${pe[e]}`,monthlyDay:e=>`Cada mes el día ${e}`,monthlyNth:(e,t)=>`Cada mes ${_e(e,pe[t])}`,monthlyLast:e=>`Cada mes el último ${pe[e]}`,yearly:(e,t)=>`Cada año el ${t} de ${fe[e-1]}`}},$e=["понедельник","вторник","среду","четверг","пятницу","субботу","воскресенье"],be=[0,0,1,0,1,1,2],De={1:["первый","первую","первое"],2:["второй","вторую","второе"],3:["третий","третью","третье"],4:["четвёртый","четвёртую","четвёртое"],5:["пятый","пятую","пятое"],[-1]:["последний","последнюю","последнее"],[-2]:["предпоследний","предпоследнюю","предпоследнее"]},ve=["января","февраля","марта","апреля","мая","июня","июля","августа","сентября","октября","ноября","декабря"],ke=["январе","феврале","марте","апреле","мае","июне","июле","августе","сентябре","октябре","ноябре","декабре"],xe=e=>`${/^вт/.test(e)?"во":"в"} ${e}`,Oe=(e,t)=>De[e]?De[e][t]:`${De[-e][t]} с конца`,Me=(e,t)=>t?`${e} ${t}`:e,Te={day:e=>xe($e[e]),nth:(e,t)=>xe(`${Oe(e,be[t])} ${$e[t]}`),nthWorkday:e=>xe(`${Oe(e,0)} рабочий день`),nthOf:(e,t)=>1===t.length?xe(`${Oe(e,be[t[0]])} ${$e[t[0]]}`):xe(`${Oe(e,0)} из дней: ${t.map((e=>$e[e])).join(", ")}`),monthlyDays:e=>C("и")(e),monthDay:e=>-1===e?"в последний день":`${e}-го числа`,join:C("и"),daily:e=>1===e?"каждый день":`раз в ${e} ${R(e,"день","дня","дней")}`,workdays:"по будням",weekly:(e,t)=>Me(1===e?"каждую неделю":`раз в ${e} ${R(e,"неделю","недели","недель")}`,t),monthly:(e,t)=>Me(1===e?"каждый месяц":`раз в ${e} ${R(e,"месяц","месяца","месяцев")}`,t),yearly:(e,t,n,r)=>{let o;return o=1===(null==t?void 0:t.length)&&1===(null==n?void 0:n.length)?-1===n[0]?`в последний день ${ve[t[0]-1]}`:`${n[0]} ${ve[t[0]-1]}`:[n?C("и")(n.map(Te.monthDay)):r?C("и")(r):"",t?xe(C("и")(t.map((e=>ke[e-1])))):""].filter(Boolean).join(" "),Me(1===e?"каждый год":`раз в ${e} ${R(e,"год","года","лет")}`,o)},count:e=>`, ${e} ${R(e,"раз","раза","раз")}`,until:e=>`, до ${e}`,preset:{none:"Не повторяется",daily:"Каждый день",weekdays:"По будням (с понедельника по пятницу)",weekly:e=>`Каждую неделю ${xe($e[e])}`,monthlyDay:e=>`Каждый месяц ${e}-го числа`,monthlyNth:(e,t)=>`Каждый месяц ${xe(`${Oe(e,be[t])} ${$e[t]}`)}`,monthlyLast:e=>`Каждый месяц ${xe(`${Oe(-1,be[e])} ${$e[e]}`)}`,yearly:(e,t)=>`Каждый год ${t} ${ve[e-1]}`}},Se={zh:F,"zh-TW":q,en:Q,ja:Z,ko:te,fr:le,de:he,es:ge,ru:Te},Ee=e=>Se[e]??Q,Ae=e=>!!e&&5===e.length&&e.every((e=>void 0===e.ordinal))&&[0,1,2,3,4].every((t=>e.some((e=>e.weekday===t))));const Ye="buckyos.todo@1",je="buckyos.calendar@1",Ne="schedule",Ie="todo",Le="calendar",Ce="schedule-board",Re="done",Be={zh:{title:"标题",status:"状态",due:"截止",order:"顺序",done_at:"完成时间",ext:"扩展",todo:"待办",doing:"进行中",done:"已完成",all_day:"全天",start:"开始",end:"结束",start_date:"开始日期",end_date:"结束日期",confirmed:"已确认",tentative:"暂定",cancelled:"已取消",todo_table:"待办",calendar_table:"日程",workspace:"我的日程",board:"日程"},en:{title:"Title",status:"Status",due:"Due",order:"Order",done_at:"Completed",ext:"Extension",todo:"To do",doing:"In progress",done:"Done",all_day:"All day",start:"Start",end:"End",start_date:"Start date",end_date:"End date",confirmed:"Confirmed",tentative:"Tentative",cancelled:"Cancelled",todo_table:"To-do",calendar_table:"Calendar",workspace:"My schedule",board:"Schedule"},"zh-TW":{title:"標題",status:"狀態",due:"截止",order:"順序",done_at:"完成時間",ext:"擴充",todo:"待辦",doing:"進行中",done:"已完成",all_day:"全天",start:"開始",end:"結束",start_date:"開始日期",end_date:"結束日期",confirmed:"已確認",tentative:"暫定",cancelled:"已取消",todo_table:"待辦事項",calendar_table:"行程",workspace:"我的行程",board:"行程"},ja:{title:"タイトル",status:"ステータス",due:"期限",order:"順序",done_at:"完了日時",ext:"拡張",todo:"未着手",doing:"進行中",done:"完了",all_day:"終日",start:"開始",end:"終了",start_date:"開始日",end_date:"終了日",confirmed:"確定",tentative:"仮",cancelled:"キャンセル",todo_table:"ToDo",calendar_table:"予定",workspace:"マイスケジュール",board:"スケジュール"},ko:{title:"제목",status:"상태",due:"마감",order:"순서",done_at:"완료 시각",ext:"확장",todo:"할 일",doing:"진행 중",done:"완료",all_day:"종일",start:"시작",end:"종료",start_date:"시작일",end_date:"종료일",confirmed:"확정",tentative:"미정",cancelled:"취소됨",todo_table:"할 일",calendar_table:"일정",workspace:"내 일정",board:"일정"},fr:{title:"Titre",status:"Statut",due:"Échéance",order:"Ordre",done_at:"Terminé le",ext:"Extension",todo:"À faire",doing:"En cours",done:"Terminé",all_day:"Toute la journée",start:"Début",end:"Fin",start_date:"Date de début",end_date:"Date de fin",confirmed:"Confirmé",tentative:"Provisoire",cancelled:"Annulé",todo_table:"Tâches",calendar_table:"Calendrier",workspace:"Mon agenda",board:"Agenda"},de:{title:"Titel",status:"Status",due:"Fällig",order:"Reihenfolge",done_at:"Erledigt am",ext:"Erweiterung",todo:"Offen",doing:"In Arbeit",done:"Erledigt",all_day:"Ganztägig",start:"Beginn",end:"Ende",start_date:"Startdatum",end_date:"Enddatum",confirmed:"Bestätigt",tentative:"Vorläufig",cancelled:"Abgesagt",todo_table:"Aufgaben",calendar_table:"Kalender",workspace:"Mein Terminplan",board:"Terminplan"},es:{title:"Título",status:"Estado",due:"Vencimiento",order:"Orden",done_at:"Completado el",ext:"Extensión",todo:"Pendiente",doing:"En curso",done:"Hecho",all_day:"Todo el día",start:"Inicio",end:"Fin",start_date:"Fecha de inicio",end_date:"Fecha de fin",confirmed:"Confirmado",tentative:"Provisional",cancelled:"Cancelado",todo_table:"Tareas",calendar_table:"Calendario",workspace:"Mi agenda",board:"Agenda"},ru:{title:"Название",status:"Статус",due:"Срок",order:"Порядок",done_at:"Выполнено",ext:"Расширение",todo:"К выполнению",doing:"В работе",done:"Готово",all_day:"Весь день",start:"Начало",end:"Конец",start_date:"Дата начала",end_date:"Дата окончания",confirmed:"Подтверждено",tentative:"Предварительно",cancelled:"Отменено",todo_table:"Задачи",calendar_table:"Календарь",workspace:"Моё расписание",board:"Расписание"}};function Ue(e,t){var n;return(null==(n=Be[e])?void 0:n[t])??Be.en[t]??t}function Fe(e="zh"){const t=t=>Ue(e,t);return[{field_id:"title",name:t("title"),type:"text",required:!0},{field_id:"status",name:t("status"),type:"select",required:!0,options:["todo","doing","done"].map((e=>({option_id:e,label:t(e)})))},{field_id:"due",name:t("due"),type:"date",nullable:!0},{field_id:"order",name:t("order"),type:"text",nullable:!0},{field_id:"done_at",name:t("done_at"),type:"datetime",nullable:!0},{field_id:"ext",name:t("ext"),type:"json",nullable:!0}]}function We(e="zh"){const t=t=>Ue(e,t);return[{field_id:"title",name:t("title"),type:"text",required:!0},{field_id:"all_day",name:t("all_day"),type:"boolean",nullable:!0},{field_id:"start",name:t("start"),type:"datetime",nullable:!0},{field_id:"end",name:t("end"),type:"datetime",nullable:!0},{field_id:"start_date",name:t("start_date"),type:"date",nullable:!0},{field_id:"end_date",name:t("end_date"),type:"date",nullable:!0},{field_id:"status",name:t("status"),type:"select",nullable:!0,options:["confirmed","tentative","cancelled"].map((e=>({option_id:e,label:t(e)})))},{field_id:"ext",name:t("ext"),type:"json",nullable:!0}]}function He(e,t){const n=t.locale??"zh";return{op:"entity.create",entity_id:t.entity_id,type_id:"buckyos.table-source",parent_id:t.parent_id,order_key:t.order_key,schema_id:"todo"===e?Ye:je,name:t.name??Ue(n,"todo"===e?"todo_table":"calendar_table"),payload:{title_field_id:"title",fields:"todo"===e?Fe(n):We(n)}}}const qe="0123456789abcdefghijklmnopqrstuvwxyz";function ze(e){return"string"==typeof e&&e.length>0&&e.length<=64&&/^[0-9a-z]+$/.test(e)&&!e.endsWith("0")}function Pe(e,t){if(null!==t){let n=0;for(;n<t.length&&(e[n]??"0")===t[n];)n++;if(n>0)return t.slice(0,n)+Pe(e.length>n?e.slice(n):"",t.slice(n))}const n=e.length?qe.indexOf(e[0]):0,r=null!==t?qe.indexOf(t[0]):36;return r-n>1?qe[Math.floor((n+r+1)/2)]:null!==t&&t.length>1?t[0]:qe[n]+Pe(e.length>1?e.slice(1):"",null)}function Ke(e,t){const n=e??null,r=t??null;if(null!==n&&null!==r&&n>=r)throw new Error("orderKeyBetween requires a < b");const o=null!==n&&null===r?function(e){const t=e.padEnd(Math.max(e.length,8),"0").split("");let n=t.length-1;for(;n>=0&&"z"===t[n];)n--;if(n>=0){t[n]=qe[qe.indexOf(t[n])+1];for(let e=n+1;e<t.length;e++)t[e]="0";return"0"===t[t.length-1]&&(t[t.length-1]="1"),t.join("")}if(t.length>=64)throw new Error("order key space exhausted; rebalance");return t.join("").padEnd(Math.min(t.length+8,64),"0").slice(0,-1)+"1"}(n):Pe(n??"",r);if(!ze(o))throw new Error("order key space exhausted; rebalance");return o}let Qe=0;function Je(e="r"){Qe=(Qe+1)%1296;const t=Math.floor(Math.random()*36**6).toString(36).padStart(6,"0");return`${e}${Date.now().toString(36)}${Qe.toString(36).padStart(2,"0")}${t}`}function Ve(e,t,n){var r;const o=[],a=[];for(const[s,l]of Object.entries(n)){const e={record_id:t.record_id,field_id:s,expect:{rev:(null==(r=t.revs)?void 0:r[s])??0}};null==l?void 0!==t.values[s]&&null!==t.values[s]&&a.push(e):o.push({...e,value:l})}const i=[];return o.length&&i.push({op:"table.set_values",source_id:e,values:o}),a.length&&i.push({op:"table.unset_values",source_id:e,values:a}),i}function Ze(e,t){return{op:"table.insert_records",source_id:e,records:t.map((e=>({record_id:e.record_id,values:Object.fromEntries(Object.entries(e.values).filter((([,e])=>null!=e)))})))}}function Ge(e,t){return{op:"table.delete_records",source_id:e,records:t.map((e=>({record_id:e.record_id,expect:{rev:e.rev??0}})))}}function Xe(e){if(_(e))return e;const t=Date.parse(e);return Number.isFinite(t)?new Date(t).toISOString():e}const et=e=>Array.isArray(e)?e.filter((e=>"string"==typeof e)).map(Xe):[],tt=e=>{const t=null==e?void 0:e.values.ext;return t&&"object"==typeof t&&!Array.isArray(t)?{...t}:{}};function nt(e){const t=e.values,n="string"==typeof t.status?t.status:"todo";return{record_id:e.record_id,rev:e.rev,revs:e.revs,values:e.values,title:"string"==typeof t.title?t.title:"",status:n,due:"string"==typeof t.due?t.due:null,order:ze(t.order)?t.order:null,done:n===Re,done_at:"string"==typeof t.done_at?t.done_at:null,ext:tt(e)}}function rt(e){return[...e].sort(((e,t)=>e.order===t.order?e.record_id.localeCompare(t.record_id):null===e.order?1:null===t.order||e.order<t.order?-1:1))}function ot(e,t,n={}){const r=t.record_id??Je("t");let o=t.order??null;if(!o)if(void 0!==n.after||void 0!==n.before)o=Ke(n.after??null,n.before??null);else{o=Ke((n.items??[]).map((e=>e.order)).filter(ze).sort().pop()??null,null)}const a=t.status??"todo";return{record_id:r,order:o,ops:[Ze(e,[{record_id:r,values:{title:t.title,status:a,order:o,due:t.due??void 0,ext:t.ext&&Object.keys(t.ext).length?t.ext:void 0,done_at:a===Re?t.done_at??(new Date).toISOString():void 0}}])]}}function at(e,t,n,r={}){return Ve(e,t,n?{status:Re,done_at:r.now??(new Date).toISOString()}:{status:r.reopenStatus??"todo",done_at:null})}function it(e,t,n,r={}){const o={},a="string"==typeof t.values.status?t.values.status:void 0;return void 0!==n.status&&n.status!==a&&(o.status=n.status,n.status===Re?o.done_at=r.now??(new Date).toISOString():a===Re&&(o.done_at=null)),void 0!==n.order&&n.order!==t.values.order&&(o.order=n.order),Object.keys(o).length?Ve(e,t,o):[]}function st(e,t,n){const r={};for(const o of["title","status","due","order","done_at"])void 0!==n[o]&&(r[o]=n[o]);if(void 0!==n.ext&&(r.ext=n.ext&&Object.keys(n.ext).length?n.ext:null),n.ext_merge){const e=tt(t);for(const[t,r]of Object.entries(n.ext_merge))null===r?delete e[t]:e[t]=r;r.ext=Object.keys(e).length?e:null}return void 0!==r.status&&r.status!==t.values.status&&void 0===r.done_at&&(r.status===Re?r.done_at=(new Date).toISOString():t.values.status===Re&&(r.done_at=null)),Ve(e,t,r)}function lt(e,t){const n=e.map((e=>e.order)),r=t>0?n[t-1]:null,o=t<n.length?n[t]:null;return null===r||ze(r)?null!==o&&ze(o)&&(null===r||r<o)?Ke(r,o):Ke(r,null):Ke(null,null)}function dt(e){const t=e.values;if(!0===t.all_day){if("string"!=typeof t.start_date||!_(t.start_date))return null;const e="string"==typeof t.end_date&&_(t.end_date)&&t.end_date>=t.start_date?t.end_date:t.start_date;return{allDay:!0,startDate:t.start_date,endDate:e}}if("string"!=typeof t.start)return null;const n=Date.parse(t.start);if(!Number.isFinite(n))return null;const r="string"==typeof t.end?Date.parse(t.end):NaN;return{allDay:!1,startMs:n,endMs:Number.isFinite(r)&&r>=n?r:n+36e5}}function ct(e,t){return D(b(e)+t)}const ut=(e,t)=>b(t)-b(e);function yt(e,t,n){const r=tt(e);return{id:e.record_id,row:e,title:"string"==typeof e.values.title?e.values.title:"",allDay:t.allDay,startMs:t.startMs,endMs:t.endMs,startDate:t.startDate,endDate:t.endDate,status:"string"==typeof e.values.status?e.values.status:null,ext:r,recurring:!1,override:!1,agentWritten:!1,...n}}function ht(e,t,n){if(!e.allDay)return e.startMs<t.toMs&&Math.max(e.endMs,e.startMs+1)>t.fromMs;const r=pt(t.fromMs,n),o=pt(t.toMs-1,n);return e.startDate<=o&&e.endDate>=r}function pt(e,t){return new Intl.DateTimeFormat("en-CA",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit"}).format(new Date(e))}function ft(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch{return"UTC"}}function mt(e,t,n={}){const r=n.viewerTz??ft(),o=[],a=new Map;for(const s of e){const e=tt(s).recurrence_id;e&&"object"==typeof e&&!Array.isArray(e)&&"string"==typeof e.master&&"string"==typeof e.original&&a.set(`${e.master}@${Xe(e.original)}`,s)}const i=new Map(e.map((e=>[e.record_id,e])));for(const s of e){const e=dt(s);if(!e)continue;const l=tt(s),d=l.recurrence_id;if(d&&"object"==typeof d){const n="string"==typeof d.master?i.get(d.master):void 0,a="string"==typeof d.original?Xe(d.original):void 0,l=yt(s,e,{id:n&&a?L(n.record_id,a):s.record_id,master:n,original:a,recurring:Boolean(n),override:!0});ht(l,t,r)&&o.push(l);continue}const c=e.allDay?ut(e.startDate,e.endDate):e.endMs-e.startMs,u=t=>{const n=`${s.record_id}@${t.original}`;return a.has(n)?null:e.allDay?yt(s,{allDay:!0,startDate:t.date,endDate:ct(t.date,c)},{id:n,master:s,original:t.original,recurring:!0}):yt(s,{allDay:!1,startMs:t.startMs,endMs:t.startMs+c},{id:n,master:s,original:t.original,recurring:!0})};let y=null;if("string"==typeof l.rrule)try{y=f(l.rrule)}catch{y=null}if(y){const a=I(s.values,"string"==typeof l.tz?l.tz:void 0,r);if(!a)continue;const i=N(y,a,t,{exdate:et(l.exdate),viewerTz:r,durationMs:e.allDay?void 0:c,durationDays:e.allDay?c:void 0,limit:n.limit});for(const e of i){const t=u(e);t&&o.push(t)}continue}if(Array.isArray(l.occurrences)&&l.occurrences.length>0){const n=new Set(et(l.exdate));for(const a of l.occurrences){if("string"!=typeof a)continue;const i=Xe(a);if(n.has(i))continue;const s=e.allDay?{original:i,date:i}:{original:i,startMs:Date.parse(i)};if(!e.allDay&&!Number.isFinite(s.startMs))continue;if(e.allDay&&!_(i))continue;const l=u(s);l&&ht(l,t,r)&&o.push({...l,agentWritten:!0})}continue}const h=yt(s,e,{});ht(h,t,r)&&o.push(h)}return o.sort(((e,t)=>_t(e)-_t(t)||e.id.localeCompare(t.id)))}const _t=e=>e.allDay?Date.parse(`${e.startDate}T00:00:00Z`):e.startMs;function wt(e,t){const n=t.record_id??Je("e"),r={title:t.title,status:t.status??void 0,ext:t.ext&&Object.keys(t.ext).length?t.ext:void 0};return t.all_day?(r.all_day=!0,r.start_date=t.start_date??void 0,r.end_date=t.end_date&&t.end_date!==t.start_date?t.end_date:void 0):(r.start=t.start??void 0,r.end=t.end??void 0),{record_id:n,ops:[Ze(e,[{record_id:n,values:r}])]}}function gt(e){return e.allDay?{all_day:!0,start_date:e.startDate,end_date:e.endDate!==e.startDate?e.endDate:null,start:null,end:null}:{all_day:null,start:e.start,end:e.end,start_date:null,end_date:null}}function $t(e,t){return e.filter((e=>{const n=tt(e).recurrence_id;return n&&"object"==typeof n&&n.master===t}))}function bt(e,t,n,r){return t?ct(e,r):((e,t)=>new Date(Date.parse(e)+t).toISOString())(e,n)}function Dt(e,t,n,r,o){const a=o.newRecordId??(()=>Je("e")),i=e=>{const t={...n.values};if(n.ext_merge){const r=tt(e);for(const[e,t]of Object.entries(n.ext_merge))null===t?delete r[e]:r[e]=t;t.ext=Object.keys(r).length?r:null}return t},s=t.master;if(!s||t.row!==s&&"one"===r){const r=t.row,o={...i(r),...n.times?gt(n.times):{}};if(void 0!==n.rrule&&!s){const e={...o.ext??tt(r)??{}};null===n.rrule?delete e.rrule:e.rrule=m(f(n.rrule)),null===n.rrule&&delete e.exdate,o.ext=Object.keys(e).length?e:null}return{ops:Ve(e,r,o),record_id:r.record_id}}const l=t.original,d=dt(s),c=tt(s);if("one"===r){const r=a(),o={...c,recurrence_id:{master:s.record_id,original:l}};delete o.rrule,delete o.exdate,delete o.occurrences,delete o.rule_text,delete o.covered_until,delete o.maintenance;const u={title:s.values.title,status:s.values.status,ext:o},y=n.times??(t.allDay?{allDay:!0,startDate:t.startDate,endDate:ct(t.startDate,ut(d.startDate,d.endDate))}:{allDay:!1,start:new Date(t.startMs).toISOString(),end:new Date(t.startMs+(d.endMs-d.startMs)).toISOString()}),h={...u,...i({record_id:r,values:{ext:o}}),...gt(y)};return h.ext||(h.ext=o),{ops:[Ze(e,[{record_id:r,values:h}])],record_id:r}}let u=0,y=0,h=d.allDay?0:d.endMs-d.startMs,p=d.allDay?ut(d.startDate,d.endDate):0;if(n.times){if(n.times.allDay!==d.allDay)throw new Error("changing a series between all-day and timed: edit the series itself (scope all) with new times");n.times.allDay?(y=ut(l,n.times.startDate),p=ut(n.times.startDate,n.times.endDate)):(u=Date.parse(n.times.start)-Date.parse(l),y=Math.round(u/864e5),h=Date.parse(n.times.end)-Date.parse(n.times.start))}const _="string"==typeof c.rrule?f(c.rrule):null,w=$t(o.rows,s.record_id),g=et(c.exdate),$=d.allDay?l===d.startDate:l===new Date(d.startMs).toISOString(),b=(e,t)=>d.allDay?{allDay:!0,startDate:ct(t,y),endDate:ct(ct(t,y),p)}:{allDay:!1,start:new Date(e+u).toISOString(),end:new Date(e+u+h).toISOString()},D=e=>void 0!==n.rrule?null===n.rrule?null:m(f(n.rrule)):e?m(function(e,t){if(!t)return e;const n={...e};if(e.byDay&&e.byDay.every((e=>void 0===e.ordinal))&&("WEEKLY"===e.freq||"DAILY"===e.freq))n.byDay=e.byDay.map((e=>({weekday:((e.weekday+t)%7+7)%7})));else if(e.byDay&&"MONTHLY"===e.freq&&1===e.byDay.length&&void 0===e.bySetPos&&Math.abs(t)<7)n.byDay=[{...e.byDay[0],weekday:((e.byDay[0].weekday+t)%7+7)%7}];else if(e.byMonthDay&&1===e.byMonthDay.length&&e.byMonthDay[0]>0){const r=e.byMonthDay[0]+t;r>=1&&r<=28&&(n.byMonthDay=[r])}return n}(e,y)):null,v=[];if("all"===r||$){const t=b(d.startMs,d.startDate),n={...c},r=D(_);r?n.rrule=r:(delete n.rrule,delete n.exdate),r&&g.length&&(n.exdate=g.map((e=>bt(e,d.allDay,u,y))));const o=i({record_id:s.record_id,values:{ext:n}}),a=void 0!==o.ext?o.ext:n;v.push(...Ve(e,s,{...o,...gt(t),ext:a&&Object.keys(a).length?a:null}));for(const i of w){const t=tt(i),n=t.recurrence_id;r?(u||y)&&v.push(...Ve(e,i,{ext:{...t,recurrence_id:{...n,original:bt(String(n.original),d.allDay,u,y)}}})):v.push(Ge(e,[i]))}return{ops:v,record_id:s.record_id}}if(!_)throw new Error("not a repeating event");const k=a(),x=e=>d.allDay?e<l:Date.parse(e)<Date.parse(l);let O={..._},M={..._};if(void 0!==_.count){const e=N(_,I(s.values,"string"==typeof c.tz?c.tz:void 0),{fromMs:d.allDay?Date.parse(`${d.startDate}T00:00:00Z`)-1728e5:d.startMs,toMs:d.allDay?Date.parse(`${l}T00:00:00Z`):Date.parse(l)},{viewerTz:"UTC"}).filter((e=>x(e.original))).length;O={..._,count:Math.max(1,e)},M={..._,count:Math.max(1,_.count-e)}}else O={..._,until:d.allDay?ct(l,-1):new Date(Date.parse(l)-1e3).toISOString().replace(/\.\d{3}Z$/,".000Z")};const T={...c,rrule:m(O)},S=g.filter(x);S.length?T.exdate=S:delete T.exdate,v.push(...Ve(e,s,{ext:T}));const E={...c},A=D(M);A?E.rrule=A:delete E.rrule;const Y=g.filter((e=>!x(e))).map((e=>bt(e,d.allDay,u,y)));Y.length&&A?E.exdate=Y:delete E.exdate;const j=b(d.allDay?void 0:Date.parse(l),d.allDay?l:void 0),L=i({record_id:k,values:{ext:E}}),C={title:s.values.title,status:s.values.status,...L,...gt(j)};C.ext=(void 0!==L.ext?L.ext:E)??void 0,v.push(Ze(e,[{record_id:k,values:C}]));for(const f of w){const t=tt(f),n=t.recurrence_id;x(String(n.original))||(A?v.push(...Ve(e,f,{ext:{...t,recurrence_id:{master:k,original:bt(String(n.original),d.allDay,u,y)}}})):v.push(Ge(e,[f])))}return{ops:v,record_id:k}}function vt(e,t,n,r){const o=t.master;if(!o)return[Ge(e,[t.row])];const a=t.original,i=tt(o),s=dt(o),l=$t(r.rows,o.record_id),d=s.allDay?a===s.startDate:a===new Date(s.startMs).toISOString();if("all"===n||"following"===n&&d)return[Ge(e,[o,...l])];const c=[];if("one"===n){const t=et(i.exdate);t.includes(a)||c.push(...Ve(e,o,{ext:{...i,exdate:[...t,a].sort()}}));const n=l.filter((e=>Xe(String(tt(e).recurrence_id.original))===a));return n.length&&c.push(Ge(e,n)),c}const u="string"==typeof i.rrule?f(i.rrule):null;if(!u)return[Ge(e,[t.row])];const y=e=>s.allDay?e<a:Date.parse(e)<Date.parse(a),h={...u,count:void 0,until:s.allDay?ct(a,-1):new Date(Date.parse(a)-1e3).toISOString()},p={...i,rrule:m(h)};if(Array.isArray(i.exdate)){const e=et(i.exdate).filter(y);e.length?p.exdate=e:delete p.exdate}c.push(...Ve(e,o,{ext:p}));const _=l.filter((e=>!y(String(tt(e).recurrence_id.original))));return _.length&&c.push(Ge(e,_)),c}const kt=1e3;function xt(e){var n,r,o,a;const i=null==(n=e.errors)?void 0:n[0];if("conflict"===e.status){const n=null==(r=e.conflicts)?void 0:r[0];return new t({code:e.code??"REVISION_CONFLICT",retryable:!0,detail:"changed meanwhile, read it again"+(n?`: ${JSON.stringify(n.selector??n)}`:"")})}return new t({code:e.code??(null==(o=e.error)?void 0:o.code)??"REJECTED",sub_code:e.sub_code??(null==i?void 0:i.sub_code),retryable:!1,detail:(null==i?void 0:i.detail)??e.detail??(null==(a=e.error)?void 0:a.detail)??"refused"})}function Ot(e,n){const r=n.indexOf("@"),o=r<0?n:n.slice(0,r),a=r<0?null:Xe(n.slice(r+1)),i=e.find((e=>e.record_id===o));if(!i)throw new t({code:"NOT_FOUND",retryable:!1,detail:`event ${o} not found`});if(null===a){const n=dt(i);if(!n)throw new t({code:"INVALID_OPERATION",retryable:!1,detail:`event ${o} has no time`});const r=tt(i),a=r.recurrence_id,s=a&&"string"==typeof a.master?e.find((e=>e.record_id===a.master)):void 0;return yt(i,n,s?{master:s,original:String(a.original),recurring:!0,override:!0}:{recurring:"string"==typeof r.rrule,master:"string"==typeof r.rrule?i:void 0,original:"string"==typeof r.rrule?n.allDay?n.startDate:new Date(n.startMs).toISOString():void 0})}const s=e.find((e=>{const t=tt(e).recurrence_id;return t&&t.master===o&&"string"==typeof t.original&&Xe(t.original)===Xe(a)})),l=dt(i);if(!l)throw new t({code:"INVALID_OPERATION",retryable:!1,detail:`event ${o} has no time`});if(s)return yt(s,dt(s),{id:n,master:i,original:a,recurring:!0,override:!0});const d=l.allDay,c=d?0:l.endMs-l.startMs,u=d?ut(l.startDate,l.endDate):0;return yt(i,d?{allDay:!0,startDate:a,endDate:ct(a,u)}:{allDay:!1,startMs:Date.parse(a),endMs:Date.parse(a)+c},{id:n,master:i,original:a,recurring:!0})}function Mt(e="zh"){const t=`${Ce}-content`,n=Ue(e,"board");return[{op:"entity.create",entity_id:t,type_id:"buckyos.container",parent_id:"canvas-content",order_key:"u",name:n,payload:{kind:"folder",title:n,system:"surface_content",surface_id:Ce}},{op:"entity.create",entity_id:Ce,type_id:"buckyos.container",parent_id:"surfaces",order_key:"a",name:n,payload:{kind:"surface",layout:{mode:"free"},title:n,content_folder_id:t}},{op:"entity.create",entity_id:`${Ce}-calendar`,type_id:"buckyos.container",parent_id:Ce,order_key:"a",placement:{x:40,y:40,w:880,h:640},payload:{kind:"calendar",layout:{mode:"data"},title:Ue(e,"calendar_table"),bindings:{events:[{entity_id:Le}],todo:[{entity_id:Ie}]},config:{view:"week"}}},{op:"entity.create",entity_id:`${Ce}-todo`,type_id:"buckyos.container",parent_id:Ce,order_key:"b",placement:{x:960,y:40,w:420,h:640},payload:{kind:"todo",layout:{mode:"data"},title:Ue(e,"todo_table"),bindings:{items:{entity_id:Ie}},config:{mode:"list"}}}]}class Tt extends Error{constructor(e,t,n,r){super(e),this.code=t,this.node=n,this.binding=r}}const St=[Ye,je],Et=e=>void 0===e?[]:Array.isArray(e)?e:[e],At=(e,t)=>t.title??e;function Yt(e,t){return!(e.accepts&&e.accepts.length>0&&!e.accepts.includes(t.type_id))&&(!e.schema_id||t.schema_id===e.schema_id)}const jt=e=>{var t;return{...(null==(t=e.accepts)?void 0:t.length)?{accepts:e.accepts}:{},...e.schema_id?{schema_id:e.schema_id}:{}}};function Nt(){const e=e=>{throw new Tt(`needs a choice: ${e}`,"NEEDS_UI")};return{pickOne:async t=>e(t.title),pickMany:async t=>e(t.title),confirm:async t=>e(t.title)}}let It=0;const Lt=()=>"ref:"+ ++It;function Ct(e,t,n){const r=e=>{throw new Tt(`on_bind result: ${e}`,"INVALID",n)},o=e=>"object"==typeof e&&null!==e&&!Array.isArray(e);if(!o(e)||!o(e.bindings))return r("{ bindings, create? } (or null to cancel)");const a=void 0===e.create?[]:e.create;if(!Array.isArray(a)||a.length>16)return r("create: a list of at most 16");const i=new Map,s=a.map(((e,t)=>{const n=`create[${t}]`;if(!o(e)||"string"!=typeof e.ref||!e.ref)return r(`${n}: { ref, kind, … }`);if(i.has(e.ref))return r(`${n}: ref ${e.ref} twice`);const a=Lt();i.set(e.ref,a);const s="string"==typeof e.name&&e.name.trim()&&e.name.length<=128?e.name.trim():null;return"standard"===e.kind?"string"!=typeof e.schema_id?r(`${n}: a standard table names its schema_id`):{ref:a,kind:"standard",schema_id:e.schema_id,name:s??e.schema_id}:s?"table"===e.kind?Array.isArray(e.fields)&&0!==e.fields.length?void 0!==e.title_field_id&&"string"!=typeof e.title_field_id?r(`${n}: title_field_id is a field id`):{ref:a,kind:"table",name:s,fields:e.fields,...e.title_field_id?{title_field_id:e.title_field_id}:{}}:r(`${n}: a table lists its fields`):"dir"===e.kind?{ref:a,kind:"dir",name:s}:r(`${n}: kind standard, table or dir`):r(`${n}: a name (at most 128 characters)`)})),l={},d=new Set;for(const[u,y]of Object.entries(e.bindings)){const e=t[u];if(!e)return r(`${u} is not a declared binding`);if(null==y)continue;const n="string"==typeof y?[y]:Array.isArray(y)&&y.every((e=>"string"==typeof e&&e))?y:r(`${u}: an id, or a list of ids`);if(!e.many&&(Array.isArray(y)||1!==n.length))return r(`${u} takes one`);if(n.length>32||new Set(n).size!==n.length)return r(`${u}: at most 32, each once`);const o=n.map((e=>(i.has(e)&&d.add(e),i.get(e)??e)));e.many?o.length>0&&(l[u]=o):l[u]=o[0]}const c=[...i.keys()].filter((e=>!d.has(e)));return c.length>0?r(`created but not bound: ${c.join(", ")}`):{bindings:l,create:s}}const Rt=async e=>{const t={},n=[],r=e.parent?Object.values(e.parent.bound).flatMap(Et):[],o=new Map(e.find({}).map((e=>[e.entity_id,e])));for(const[a,i]of Object.entries(e.decls)){const s=(t,n)=>new Tt(t,n,e.node,a);if("rebind"===e.reason){if(void 0!==e.given[a]&&e.no_ui){t[a]=e.given[a];continue}const r=Et(e.given[a]);if(i.many){const o=await Ut(a,(()=>e.dialogs.pickMany({title:At(a,i),query:jt(i),preselect:r,allow_new:e.canCreate(i)})));if(null===o)return null;t[a]=o.map((t=>{if("string"==typeof t)return t;const r=Lt();return n.push(Bt(r,i,e.title)),r}))}else{const o=await Ut(a,(()=>e.dialogs.pickOne({title:At(a,i),query:jt(i),allow_new:e.canCreate(i),current:r[0]??null})));if(null===o)return null;if("string"==typeof o)t[a]=o;else{const r=Lt();n.push(Bt(r,i,e.title)),t[a]=r}}continue}if(void 0!==e.given[a]){t[a]=i.many?Et(e.given[a]):Et(e.given[a])[0];continue}const l=r.filter((e=>{const t=o.get(e);return void 0!==t&&Yt(i,t)}));if(i.many&&l.length>0){t[a]=l;continue}if(!i.many&&1===l.length){t[a]=l[0];continue}const d=e.find(jt(i)).filter((e=>Yt(i,e)));if(0===d.length){if(!i.required)continue;if(!e.canCreate(i))throw s(`no ${At(a,i)} in this Workspace yet`,"NO_DATA");const r=Lt();n.push(Bt(r,i,e.title)),t[a]=i.many?[r]:r}else if(i.many)t[a]=d.map((e=>e.entity_id));else if(1===d.length)t[a]=d[0].entity_id;else if(i.required){const r=await Ut(a,(()=>e.dialogs.pickOne({title:At(a,i),query:jt(i),allow_new:e.canCreate(i)})));if(null===r)return null;if("string"==typeof r)t[a]=r;else{const r=Lt();n.push(Bt(r,i,e.title)),t[a]=r}}}return{bindings:t,create:n}};function Bt(e,t,n){return{ref:e,kind:"standard",schema_id:t.schema_id,name:n||t.title||"Table"}}async function Ut(e,t){try{return await t()}catch(n){if(n instanceof Tt&&"NEEDS_UI"===n.code)throw new Tt(`binding ${e} needs a choice: give it`,"NEEDS_UI",void 0,e);throw n}}function Ft(e){return async t=>{var n;const r={},o=[];for(const i of e){const e=t.decls[i.binding]??{};if(void 0===t.given[i.binding]||"insert"!==t.reason)if("from_parent"in i){const o=null==(n=t.parent)?void 0:n.bound[i.from_parent];void 0!==o&&(r[i.binding]=e.many?Et(o):Et(o)[0])}else if("pick"in i){const n=jt(e),a=i.title??At(i.binding,e),s=!1!==i.allow_new&&t.canCreate(e),l=Et(t.given[i.binding]);if("all"===i.pick)r[i.binding]=t.find(n).filter((t=>Yt(e,t))).map((e=>e.entity_id));else if("many"===i.pick){const d=await Ut(i.binding,(()=>t.dialogs.pickMany({title:a,query:n,preselect:l.length?l:"none",allow_new:s})));if(null===d)return null;r[i.binding]=d.map((n=>{if("string"==typeof n)return n;const r=Lt();return o.push(Bt(r,e,t.title)),r}))}else{const d=await Ut(i.binding,(()=>t.dialogs.pickOne({title:a,query:n,allow_new:s,current:l[0]??null})));if(null===d)return null;if("string"==typeof d)r[i.binding]=e.many?[d]:d;else{const n=Lt();o.push(Bt(n,e,t.title)),r[i.binding]=e.many?[n]:n}}}else{const n=0===t.find(jt(e)).filter((t=>Yt(e,t))).length;if("missing"===(i.when??"missing")&&!n)continue;const a=Lt(),s=i.create;o.push("standard"in s?{ref:a,kind:"standard",schema_id:s.standard,name:At(i.binding,e)}:"table"in s?{ref:a,kind:"table",name:s.table.name,title_field_id:s.table.title_field_id,fields:s.table.fields}:{ref:a,kind:"dir",name:s.dir.name}),r[i.binding]=e.many?[a]:a}else r[i.binding]=t.given[i.binding]}const a=Object.fromEntries(Object.entries(t.decls).filter((([e])=>void 0===r[e])));if(Object.keys(a).length>0){const e=await Rt({...t,decls:a});if(null===e)return null;Object.assign(r,e.bindings),o.push(...e.create)}return{bindings:r,create:o}}}const Wt=async e=>{const t=(n=e.decls,r=e.bound,Object.entries(n).filter((([e,t])=>t.required&&0===Et(r[e]).length)).map((([e,t])=>At(e,t))));var n,r;if(t.length>0)return`${e.title}: ${t.join(", ")} not bound`;const o=e.children.filter((e=>!e.ready));return!(o.length>0)||`not ready: ${o.map((e=>`${e.title} (${e.missing.join(", ")})`)).join("; ")}`};exports.AIWORKSPACE_SERVICE_NAME="aiworkspace",exports.AIWS_COMMIT_MAX_BYTES=o,exports.AIWS_COMMIT_MAX_OPERATIONS=a,exports.AIWS_COMMIT_PART_BYTES=r,exports.AIWS_PROTOCOL_VERSION="1.2",exports.AiWorkspaceClient=class{constructor(e){this.rpcClient=e,this.raw=(e,t)=>this.rpcClient.call(e,t)}async call(e,n){const r=await this.rpcClient.call(e,n);if(r&&"object"==typeof r&&!1===r.ok)throw new t(r.error);return r}create(e,t={}){return this.call("ws.create",{title:e,...t})}ensure(e,t){return this.call("ws.ensure",{name:e,...void 0===t?{}:{title:t}})}time(){return this.call("ws.time",{})}list(){return this.call("ws.list",{})}info(e){return this.call("ws.get_info",{workspace_id:e})}getUserState(e){return this.call("ws.get_user_state",{workspace_id:e})}setUserState(e,t,n){return this.call("ws.set_user_state",{workspace_id:e,entries:t,...n?{expect:n}:{}})}resolve(e,t){return this.call("doc.resolve",{workspace_id:e,reference:t})}resolvePath(e,t){return this.call("doc.resolve",{workspace_id:e,path:t})}read(e,t,r){return this.call("doc.read",{workspace_id:e,...n(t),...r?{selector:r}:{}})}readMeta(e,t){return this.call("doc.read",{workspace_id:e,...n(t),as:"meta"})}readBody(e,t,r={}){return this.call("doc.read",{workspace_id:e,...n(t),as:"body",...r})}listEntities(e,t={}){return this.call("doc.list",{workspace_id:e,...t})}findEntities(e,t={}){return this.call("doc.find",{workspace_id:e,...t})}textQuery(e,t,n={}){return this.call("doc.query",{workspace_id:e,text:t,...n})}sql(e,t,n={}){return this.call("doc.query",{workspace_id:e,sql:t,...n})}sourceQuery(e,t,n){return this.call("doc.source_query",{workspace_id:e,source_id:t,...n})}outline(e){return this.call("doc.outline",{workspace_id:e})}prepare(e,t){return d(this.raw,{workspace_id:e,...t},{method:"doc.prepare"})}commit(e,t,n={}){return d(this.raw,{workspace_id:e,...t},n)}getSubmission(e,t,n){return this.call("doc.get_submission",{workspace_id:e,epoch:t,idempotency_key:n})}getChanges(e,t,n,r={}){return this.call("doc.get_changes",{workspace_id:e,epoch:t,after_seq:n,...r.limit?{limit:r.limit}:{},...r.touchedOnly?{filter:{detail:"touched"}}:{}})}waitChanges(e,t,n={}){return this.call("doc.wait_changes",{workspace_id:e,after_seq:t,...n})}exportDoc(e,t,n,r){return this.call("doc.export",{workspace_id:e,mode:t,self_contained:n,...void 0===r?{}:{include_notes:r}})}assetImportObject(e,t){return this.call("asset.import_object",{workspace_id:e,...t})}controlsList(){return this.call("control.list",{})}controlsDescribe(e){return this.call("control.describe",{kind:e})}controlsImport(e,t){return this.call("control.import",{workspace_id:e,...t})}controlsExport(e,t,n){return this.call("control.export",{workspace_id:e,entity_id:t,...n?{format:n}:{}})}extBuild(e,t){return this.call("ext.build",{workspace_id:e,...t})}extExport(e,t,n="package"){return this.call("ext.export",{workspace_id:e,entity_ids:t,purpose:n})}extInstall(e){return this.call("ext.install",e)}extPack(e,t,n,r){return this.call("ext.pack",{workspace_id:e,entity_ids:t,package:n,...r?{templates:r}:{}})}extUpgrade(e){return this.call("ext.upgrade",{...e})}extExportTemplate(e){return this.call("ext.export_template",{...e})}extCreateFromTemplate(e){return this.call("ext.create_from_template",e)}extListLibrary(){return this.call("ext.list_library",{})}extUninstall(e){return this.call("ext.uninstall",{pkg_id:e})}extLibraryBundle(e,t){return this.call("ext.library_bundle",{pkg_id:e,...t?{idents:t}:{}})}extImport(e,t,n={}){return this.call("ext.import",{workspace_id:e,items:t,...n})}runStart(e,t,n,r){return this.call("proc.start",{workspace_id:e,program:t,params:n,idempotency_key:r})}runGet(e,t){return this.call("proc.get",{workspace_id:e,run_id:t})}runList(e,t,n){return this.call("proc.list",{workspace_id:e,...t?{wish_id:t}:{},...n?{limit:n}:{}})}runClaim(e,t,n,r){return this.call("proc.claim",{workspace_id:e,run_id:t,claim_token:n,...r?{executor:r}:{}})}runHeartbeat(e,t,n,r){return this.call("proc.heartbeat",{workspace_id:e,run_id:t,attempt:n,...r?{progress:r}:{}})}runReport(e,t){return this.call("proc.report",{workspace_id:e,...t})}runRollback(e,t,n={}){return this.call("proc.rollback",{workspace_id:e,run_id:t,...n.confirm?{confirm:!0}:{},...n.session_id?{session_id:n.session_id}:{}})}runCancel(e,t){return this.call("proc.cancel",{workspace_id:e,run_id:t})}},exports.AiwsFailure=t,exports.BindFailure=Tt,exports.CALENDAR_SCHEMA_ID=je,exports.RRuleError=u,exports.SCHEDULE_CALENDAR_ID=Le,exports.SCHEDULE_SURFACE_ID=Ce,exports.SCHEDULE_TODO_ID=Ie,exports.SCHEDULE_WORKSPACE_NAME=Ne,exports.STANDARD_SCHEMAS=St,exports.ScheduleClient=class{constructor(e,t={}){this.aiws=e,this.handle=null,this.locale=t.locale??"zh"}async ensure(){var e,t,n;if(this.handle)return this.handle;const r=await this.aiws.call("ws.ensure",{name:Ne,title:Ue(this.locale,"workspace")}),o={workspace_id:r.workspace_id,epoch:r.epoch,created:r.created,todo:Ie,calendar:Le},a=new Set;for(const l of[Ie,Le,Ce])try{(await this.aiws.call("doc.read",{workspace_id:r.workspace_id,entity_id:l})).deleted||a.add(l)}catch(s){const e=null==s?void 0:s.code;if("NOT_FOUND"!==e&&"TARGET_DELETED"!==e)throw s}const i=[];if(a.has(Ie)||i.push(He("todo",{entity_id:Ie,parent_id:"data",order_key:"u",locale:this.locale})),a.has(Le)||i.push(He("calendar",{entity_id:Le,parent_id:"data",order_key:"v",locale:this.locale})),a.has(Ce)||i.push(...Mt(this.locale)),i.length){const r=await this.commitTo(o,i,"create the schedule","system"),a="ID_CONFLICT"===(r.sub_code??(null==(t=null==(e=r.errors)?void 0:e[0])?void 0:t.sub_code)??(null==(n=r.error)?void 0:n.sub_code));if("accepted"!==r.status&&("rejected"!==r.status||!a))throw xt(r)}return this.handle=o,o}async commitTo(e,t,n,r="agent"){var o;const a=`sched-${Je("k")}`,i=o=>({protocol_version:"1.2",workspace_id:e.workspace_id,epoch:o,idempotency_key:a,origin:r,message:n,operations:t});let s=await this.aiws.call("doc.commit",i(e.epoch));if("rejected"===s.status&&"EPOCH_MISMATCH"===(s.code??(null==(o=s.error)?void 0:o.code))){const t=await this.aiws.call("ws.get_info",{workspace_id:e.workspace_id});e.epoch=t.epoch,s=await this.aiws.call("doc.commit",i(e.epoch))}return s}async commit(e,t){const n=await this.ensure(),r=await this.commitTo(n,e,t);if("accepted"!==r.status)throw xt(r);return r}async rows(e){const t=await this.ensure(),n=[];for(let r=0;r<100;r++){const o=await this.aiws.call("doc.query",{workspace_id:t.workspace_id,sql:'SELECT "_record" FROM t ORDER BY "_id" LIMIT ? OFFSET ?',params:[kt,r*kt],tables:{t:e},max_rows:kt});for(const[e]of o.rows)n.push("string"==typeof e?JSON.parse(e):e);if(o.rows.length<kt)break}return n}async row(e,n){const r=await this.ensure(),o=(await this.aiws.call("doc.read",{workspace_id:r.workspace_id,entity_id:e,selector:{kind:"table_record",record_id:n}})).content;if(!(null==o?void 0:o.record_id))throw new t({code:"NOT_FOUND",retryable:!1,detail:`record ${n} not found`});return o}async todos(e={}){const t=rt((await this.rows(Ie)).map(nt));return e.includeDone?t:t.filter((e=>!e.done))}async addTodo(e,t={}){var n,r,o,a;const i=rt((await this.rows(Ie)).map(nt)),s=e=>i.find((t=>t.record_id===e));let l={items:i};if(t.after){const e=i.findIndex((e=>e.record_id===t.after));l={after:(null==(n=s(t.after))?void 0:n.order)??null,before:(null==(r=i[e+1])?void 0:r.order)??null}}else if(t.before){const e=i.findIndex((e=>e.record_id===t.before));l={after:(null==(o=i[e-1])?void 0:o.order)??null,before:(null==(a=s(t.before))?void 0:a.order)??null}}const{record_id:d,ops:c}=ot(Ie,e,l);return await this.commit(c,`add to-do: ${e.title}`),nt(await this.row(Ie,d))}async completeTodo(e,t=!0){const n=await this.row(Ie,e),r=at(Ie,n,t);r.length&&await this.commit(r,`${t?"complete":"reopen"} to-do ${e}`)}async updateTodo(e,t){const n=await this.row(Ie,e),r=st(Ie,n,t);r.length&&await this.commit(r,`update to-do ${e}`)}async moveTodo(e,n){const r=rt((await this.rows(Ie)).map(nt)),o=r.find((t=>t.record_id===e));if(!o)throw new t({code:"NOT_FOUND",retryable:!1,detail:`to-do ${e} not found`});const a=r.filter((t=>t.record_id!==e));let i;if(n.before||n.after){const e=a.findIndex((e=>e.record_id===(n.before??n.after)));if(e<0)throw new t({code:"NOT_FOUND",retryable:!1,detail:`to-do ${n.before??n.after} not found`});i=lt(a,n.before?e:e+1)}const s=it(Ie,o,{status:n.status,order:i});s.length&&await this.commit(s,`move to-do ${e}`)}async removeTodos(e){const t=await Promise.all(e.map((e=>this.row(Ie,e))));await this.commit([Ge(Ie,t)],`delete to-do ${e.join(", ")}`)}async events(e,t={}){return mt(await this.rows(Le),e,t)}async addEvent(e){var t;void 0!==(null==(t=e.ext)?void 0:t.rrule)&&"string"==typeof e.ext.rrule&&(e={...e,ext:{...e.ext,rrule:m(f(e.ext.rrule))}});const{record_id:n,ops:r}=wt(Le,e);return await this.commit(r,`add event: ${e.title}`),n}async occurrence(e){const t=await this.rows(Le);return{occ:Ot(t,e),rows:t}}async editEvent(e,t,n="one"){const{occ:r,rows:o}=await this.occurrence(e),{ops:a,record_id:i}=Dt(Le,r,t,n,{rows:o});return a.length&&await this.commit(a,`edit event ${e} (${n})`),i}async deleteEvent(e,t="one"){const{occ:n,rows:r}=await this.occurrence(e);await this.commit(vt(Le,n,t,{rows:r}),`delete event ${e} (${t})`)}},exports.TODO_DONE=Re,exports.TODO_SCHEMA_ID=Ye,exports.WEEKDAYS=c,exports.aiwsReferenceUrl=function(t,n){const r=t.workspace_id??n;if(!r)throw new Error("reference names no workspace");const o=[];"fixed"===t.mode&&o.push("mode=fixed"),null!=t.selector&&o.push(`selector=${e.encodeObjQueryComponent(e.canonicalJson(t.selector))}`),null!=t.version&&o.push(`version=${e.encodeObjQueryComponent(e.canonicalJson(t.version))}`);const a=e.objServiceUrl("aiworkspace",[r,"entities",t.entity_id]);return e.normalizeObjectUrl(o.length?`${a}?${o.join("&")}`:a)},exports.aiwsTarget=n,exports.bindingAccepts=Yt,exports.bindingsPayload=function(e,t,n){var r;const o={};for(const[a,i]of Object.entries(e)){const e=Et(i).map((e=>({entity_id:n[e]??e})));(null==(r=t[a])?void 0:r.many)||Array.isArray(i)?e.length>0&&(o[a]=e):e[0]&&(o[a]=e[0])}return o},exports.boundIds=function(e){return null==e?[]:Array.isArray(e)?e:[e]},exports.calendarFields=We,exports.calendarOccurrences=mt,exports.canonicalOriginal=Xe,exports.checkBindResult=Ct,exports.checkBindSteps=function(e,t,n,r){var o,a,i,s;const l=[];if(void 0!==e)if(!Array.isArray(e)||e.length>16)l.push("on_bind: at most 16 steps");else for(const[d,c]of e.entries()){const e=c,t=`on_bind[${d}]`;if(!e||"object"!=typeof e||"string"!=typeof e.binding){l.push(`${t}: names a binding`);continue}const r=n[e.binding];if(!r){l.push(`${t}: ${e.binding} is not a declared binding`);continue}if(1===["pick","from_parent","create"].filter((t=>t in e)).length){if("pick"in e&&!["one","many","all"].includes(String(e.pick))&&l.push(`${t}: pick is one, many or all`),"pick"in e&&"one"!==e.pick&&!r.many&&l.push(`${t}: ${e.binding} takes one`),"from_parent"in e&&"string"!=typeof e.from_parent&&l.push(`${t}: from_parent names a binding of the parent`),"create"in e){const n=e.create,r=n&&"object"==typeof n?["standard","table","dir"].filter((e=>e in n)):[];1!==r.length?l.push(`${t}: create one of standard, table, dir`):"standard"!==r[0]||St.includes(String(n.standard))?"table"!==r[0]||Array.isArray(null==(o=n.table)?void 0:o.fields)&&"string"==typeof(null==(a=n.table)?void 0:a.name)?"dir"===r[0]&&"string"!=typeof(null==(i=n.dir)?void 0:i.name)&&l.push(`${t}: create.dir needs name`):l.push(`${t}: create.table needs name and fields`):l.push(`${t}: no standard table ${String(n.standard)}`),void 0!==e.when&&"missing"!==e.when&&"always"!==e.when&&l.push(`${t}: when is missing or always`)}}else l.push(`${t}: one of pick, from_parent, create`)}if(void 0!==t)if(!Array.isArray(t)||t.length>16)l.push("on_init_control: at most 16 steps");else for(const[d,c]of t.entries()){const e=c,t=`on_init_control[${d}]`;if("children"===(null==e?void 0:e.require))continue;const n=null==(s=null==e?void 0:e.then)?void 0:s.action;"string"!=typeof n?l.push(`${t}: { require: "children" } or { then: { action } }`):r.includes(n)||l.push(`${t}: ${n} is not a declared action`)}return l},exports.commitOverLimit=function(e){if(e.length>a)return{limit:"operations",value:e.length,max:a};let t=2;for(const n of e)t+=s(n)+1;return t+4096>o?{limit:"bytes",value:t,max:o}:null},exports.commitWithParts=d,exports.createOps=function(e,t){const n=[],r={};for(const o of e.values())for(const e of o.create){const o=t.newId();r[e.ref]=o;const a={entity_id:o,parent_id:t.folderId,order_key:t.orderKey(),name:t.freeName(e.name)};if("standard"===e.kind){const r=e.schema_id===Ye?"todo":e.schema_id===je?"calendar":null;if(!r)throw new Tt(`cannot create a table of ${e.schema_id}`,"INVALID");n.push(He(r,{...a,locale:t.locale}))}else"table"===e.kind?n.push({op:"entity.create",type_id:"buckyos.table-source",...a,payload:{fields:e.fields,...e.title_field_id?{title_field_id:e.title_field_id}:{}}}):n.push({op:"entity.create",type_id:"buckyos.dir",...a,payload:{members:{}}})}return{ops:n,ids:r}},exports.dateOf=D,exports.dayNumber=$,exports.dayOf=b,exports.daysInMonth=g,exports.defaultOnBind=Rt,exports.defaultOnInit=Wt,exports.deleteRecordsOp=Ge,exports.describeRRule=function(e,t="zh"){const n=Ee(t),r=e.interval,o=e=>e.map((e=>void 0===e.ordinal?n.day(e.weekday):n.nth(e.ordinal,e.weekday)));let a;switch(e.freq){case"DAILY":a=n.daily(r);break;case"WEEKLY":a=Ae(e.byDay)&&1===r?n.workdays:n.weekly(r,e.byDay?n.join(o(e.byDay)):"");break;case"MONTHLY":{let t="";e.byMonthDay?t=n.join(e.byMonthDay.map(n.monthDay)):e.byDay&&void 0!==e.bySetPos?t=Ae(e.byDay)?n.nthWorkday(e.bySetPos):n.nthOf(e.bySetPos,e.byDay.map((e=>e.weekday))):e.byDay&&(t=n.monthlyDays(o(e.byDay))),a=n.monthly(r,t);break}case"YEARLY":a=n.yearly(r,e.byMonth,e.byMonthDay,e.byMonthDay?void 0:e.byDay?o(e.byDay):void 0)}return void 0!==e.count&&(a+=n.count(e.count)),void 0!==e.until&&(a+=n.until(e.until.slice(0,10))),a},exports.eventAddOps=wt,exports.eventDeleteOps=vt,exports.eventEditOps=Dt,exports.eventPostponeOps=function(e,t,n,r){return Dt(e,t,{times:t.allDay?{allDay:!0,startDate:ct(t.startDate,Math.max(1,Math.round(n/1440))),endDate:ct(t.endDate,Math.max(1,Math.round(n/1440)))}:{allDay:!1,start:new Date(t.startMs+6e4*n).toISOString(),end:new Date(t.endMs+6e4*n).toISOString()}},"one",r)},exports.eventSkipOps=(e,t,n)=>vt(e,t,"one",n),exports.expandSeries=N,exports.findOccurrence=Ot,exports.formatRRule=m,exports.insertRecordOp=Ze,exports.isDate=_,exports.isLeap=w,exports.isOrderKey=ze,exports.isTimeZone=M,exports.localDate=pt,exports.localDay=A,exports.newRecordId=Je,exports.noUiDialogs=Nt,exports.occurrenceId=L,exports.orderAt=lt,exports.orderKeyBetween=Ke,exports.orderKeysBetween=function(e,t,n){const r=[];let o=e;for(let a=0;a<n;a++)o=Ke(o,t),r.push(o);return r},exports.originalOf=function(e){return e.date??new Date(e.startMs).toISOString()},exports.parseAiwsReferenceUrl=function(t){const n=e.parseObjectUrl(t),r=e.objectSegments(n);if("obj"!==n.kind||"aiworkspace"!==n.host.name||3!==r.length||"entities"!==r[1])throw new Error(`${t} is not an AI Workspace entity url`);const o={workspace_id:r[0],entity_id:r[2],mode:"fixed"===n.query.mode?"fixed":"live"};return void 0!==n.query.selector&&(o.selector=JSON.parse(n.query.selector)),void 0!==n.query.version&&(o.version=JSON.parse(n.query.version)),o},exports.parseOccurrenceId=function(e){const t=e.indexOf("@");return t<0?{recordId:e,original:null}:{recordId:e.slice(0,t),original:e.slice(t+1)}},exports.parseRRule=f,exports.recurrencePresets=function(e,t="zh"){const n=b(e),{y:r,m:o,d:a}=v(n),i=k(n),s=Math.floor((a-1)/7)+1,l=a+7>g(r,o),d=Ee(t).preset,u=c[i],y=[{id:"none",label:d.none,rrule:null},{id:"daily",label:d.daily,rrule:"FREQ=DAILY"},{id:"weekdays",label:d.weekdays,rrule:"FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR"},{id:"weekly",label:d.weekly(i),rrule:`FREQ=WEEKLY;BYDAY=${u}`},{id:"monthly_day",label:d.monthlyDay(a),rrule:`FREQ=MONTHLY;BYMONTHDAY=${a}`}];return s<=4&&y.push({id:"monthly_nth",label:d.monthlyNth(s,i),rrule:`FREQ=MONTHLY;BYDAY=${s}${u}`}),l&&y.push({id:"monthly_last",label:d.monthlyLast(i),rrule:`FREQ=MONTHLY;BYDAY=-1${u}`}),y.push({id:"yearly",label:d.yearly(o,a),rrule:`FREQ=YEARLY;BYMONTH=${o};BYMONTHDAY=${a}`}),y},exports.resolveBindings=async function(e,t){const n=t.standardSchemas??St,r=t.no_ui?Nt():t.dialogs,o=new Map,a=[],i=async(e,s)=>{const l={reason:t.reason,no_ui:t.no_ui,node:e.id,title:e.title,decls:e.decls,given:e.given??{},parent:s,find:t.find,canCreate:e=>Boolean(e.schema_id&&n.includes(e.schema_id)),dialogs:r},d="function"==typeof e.onBind?e.onBind:Array.isArray(e.onBind)?Ft(e.onBind):Rt;let c;try{c=await d(l)}catch(f){if(f instanceof Tt)throw new Tt(f.message,f.code,f.node??e.id,f.binding);throw f}if(null===c)throw new Tt(`${e.title}: cancelled`,"CANCELLED",e.id);c=Ct(c,e.decls,e.id),o.set(e.id,c);const u=[];for(const t of e.children)u.push(await i(t,{decls:e.decls,bound:c.bindings}));const y="function"==typeof e.onInit?e.onInit:Wt,h=Array.isArray(e.onInit)?e.onInit:[],p=await y({reason:t.reason,no_ui:t.no_ui,node:e.id,title:e.title,decls:e.decls,bound:c.bindings,children:u,dialogs:r});if(!0!==p)throw new Tt(p,"NOT_READY",e.id);for(const t of h)"then"in t&&a.push({node:e.id,action:t.then.action});return{node:e.id,title:e.title,ready:!0,missing:[]}};try{return await i(e,t.parent??null),{ok:!0,results:o,then:a}}catch(s){if(s instanceof Tt)return{ok:!1,error:s};throw s}},exports.scheduleBoardOps=Mt,exports.scheduleLabel=Ue,exports.seriesStartOf=I,exports.setValuesOps=Ve,exports.sortTodos=rt,exports.splitCommitOperations=l,exports.standardTableOp=He,exports.stepsOnBind=Ft,exports.todoAddOps=ot,exports.todoCompleteOps=at,exports.todoFields=Fe,exports.todoItem=nt,exports.todoMoveOps=it,exports.todoUpdateOps=st,exports.viewerTimeZone=ft,exports.weekdayOf=k,exports.ymdOf=v,exports.zonedParts=T,exports.zonedToUtc=E;
|
|
2
|
+
//# sourceMappingURL=aiws_bind-1a26e3e6.js.map
|