@heyo-sh/heyo-cms 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai.js +1 -1
- package/dist/auth.js +1 -1
- package/dist/cli.js +2 -2
- package/dist/config.js +1 -1
- package/dist/content.js +1 -1
- package/dist/db/d1.js +1 -1
- package/dist/db/mongodb.d.ts +2 -1
- package/dist/db/mongodb.d.ts.map +1 -1
- package/dist/db/mongodb.js +2 -2
- package/dist/db/postgres.js +1 -1
- package/dist/db/sql/adapter.d.ts.map +1 -1
- package/dist/db/sql/dialect.d.ts +3 -0
- package/dist/db/sql/dialect.d.ts.map +1 -1
- package/dist/db/sqlite.js +1 -1
- package/dist/db/unique.d.ts +46 -0
- package/dist/db/unique.d.ts.map +1 -0
- package/dist/editor.js +1 -1
- package/dist/fields.js +1 -1
- package/dist/http.js +1 -1
- package/dist/{index-b79c3k6g.js → index-0fe3ngv2.js} +2 -2
- package/dist/{index-1xz3pmtk.js → index-1xwmw8vb.js} +2 -2
- package/dist/{index-mpkhjgvk.js → index-2djaxtj8.js} +4 -4
- package/dist/{index-63x90ejh.js → index-2j6d79fk.js} +6 -6
- package/dist/{index-zyg6bfdq.js → index-2zpnecrk.js} +2 -2
- package/dist/{index-761dec5z.js → index-344y6q4n.js} +2 -2
- package/dist/index-4j1kkeg2.js +2 -0
- package/dist/{index-eqfcxn71.js → index-5j0cqm43.js} +2 -2
- package/dist/{index-wbc2xh4h.js → index-5yt6r97r.js} +6 -6
- package/dist/{index-a8jcwqsf.js → index-78f0ghve.js} +2 -2
- package/dist/{index-szaq03qq.js → index-8j4p950b.js} +2 -2
- package/dist/{index-466cwb0b.js → index-cakys3fy.js} +2 -2
- package/dist/{index-p2cqsmvw.js → index-cnzt9x9x.js} +2 -2
- package/dist/{index-abfzb1ve.js → index-e3yknwyr.js} +2 -2
- package/dist/{index-vf163r10.js → index-fy8r8e53.js} +2 -2
- package/dist/index-gv8j76x3.js +26 -0
- package/dist/{index-dtwe2z69.js → index-mzxsxzkd.js} +4 -4
- package/dist/{index-91fa1gzf.js → index-n09v6gx3.js} +2 -2
- package/dist/{index-axpzy2hj.js → index-pkxgzw6e.js} +2 -2
- package/dist/{index-vzhxn50e.js → index-q6ak9ph4.js} +2 -2
- package/dist/{index-6m1kjq9g.js → index-q6jkbsjp.js} +2 -2
- package/dist/{index-8nzmqy0f.js → index-qgtvymh2.js} +2 -2
- package/dist/{index-s9x07zb3.js → index-qkqtxr65.js} +2 -2
- package/dist/{index-ypcmns0v.js → index-rb9fxtyn.js} +2 -2
- package/dist/{index-a1jv6396.js → index-rpdkj3qk.js} +11 -11
- package/dist/{index-ptttzgtp.js → index-twqpdtfh.js} +3 -3
- package/dist/index.js +1 -1
- package/dist/jobs.js +1 -1
- package/dist/migrations.js +1 -1
- package/dist/query.js +1 -1
- package/dist/{run-rqmtv3cn.js → run-mtgvmy5x.js} +2 -2
- package/dist/schema.js +1 -1
- package/dist/telemetry.js +1 -1
- package/dist/uploads.js +3 -3
- package/dist/webhooks.js +1 -1
- package/package.json +1 -1
- package/dist/index-4qrep5f0.js +0 -26
package/dist/ai.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./index-
|
|
1
|
+
import"./index-rpdkj3qk.js";import{pe,Z,Le,me,Ot,To,Co,Oo,lo,co,uo}from"./index-2j6d79fk.js";import"./index-pkxgzw6e.js";import"./index-q6jkbsjp.js";import{Sn,Tn,no,Ke,At}from"./index-1xwmw8vb.js";export{Le as aiActionsFor,co as altAction,Tn as assertModelExists,Sn as authTypesForAiProvider,Ot as customAiAction,pe as defineAiAction,At as describeCmsFor,To as generateAction,Z as getAiAction,Co as improveAction,no as modelsForProvider,Ke as piCompletion,me as registeredAiActions,Oo as summarizeAction,uo as tagsAction,lo as translateAction};
|
package/dist/auth.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./index-
|
|
1
|
+
import"./index-q6jkbsjp.js";import{_e}from"./index-pkxgzw6e.js";import{Un,jt,Jn,Wn,nr,dn,be,un,pn}from"./index-5j0cqm43.js";import{Pe,mn,we,re,ie}from"./index-cnzt9x9x.js";import{w}from"./index-rw0hze6x.js";import{n}from"./index-x72d1hzh.js";function o(e){if(e.methods.length===0)throw new n("admin.auth.methods","at least one sign-in method is required");for(let[s,t]of[["session",e.session?.expiresIn],["invites",e.invites?.expiresIn],["magicLink",e.magicLink?.expiresIn],["passwordReset",e.passwordReset?.expiresIn],["apiKeys",e.apiKeys?.expiresIn]])if(t)w(t,`admin.auth.${s}.expiresIn`);for(let s of e.apiKeys?.scopes??[])if(!_e(s))throw new n("admin.auth.apiKeys.scopes",`"${s}" is not a scope; use "read", "write", "delete", "*" or "collection:action"`);let i=e.firstUser;if(typeof i==="object"){let s=i.roles;if(s!==void 0&&s.length===0)throw new n("admin.auth.firstUser.roles","the first account needs at least one role")}if(i!==void 0&&i!==!1&&!e.methods.includes("password"))throw new n("admin.auth.firstUser",'the first account signs in with a password; add "password" to methods, or set firstUser: false');let r=e.password?.minLength;if(r!==void 0&&r<8)throw new n("admin.auth.password.minLength","must be at least 8");return{kind:"cms-users",...e}}function a(e){if(!/^https?:\/\//.test(e.issuer))throw new n("admin.auth.sso.issuer","must be an HTTP(S) issuer URL");return{kind:"oidc",...e}}export{un as apiKeyPrefix,ie as base64url,Un as builtinProviders,o as cmsUsers,pn as createAuth,jt as decodeIdToken,Jn as generateTotpSecret,Pe as hashPassword,re as hashToken,a as oidc,we as randomToken,be as sessionCookieName,nr as totpCode,Wn as totpUri,mn as verifyPassword,dn as verifyTotp};
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import"./index-
|
|
2
|
+
import"./index-pkxgzw6e.js";import"./index-q6jkbsjp.js";import"./index-e3yknwyr.js";import"./index-0fe3ngv2.js";import"./index-rpdkj3qk.js";import"./index-2j6d79fk.js";import"./index-5yt6r97r.js";import"./index-2zpnecrk.js";import{ln,qn,Ln,Fn}from"./index-2djaxtj8.js";import{Jt,Wt,bn}from"./index-8j4p950b.js";import{qt,Lt,Ft,Nt,Ut}from"./index-mzxsxzkd.js";import"./index-1xwmw8vb.js";import"./index-n09v6gx3.js";import"./index-5j0cqm43.js";import{createRequire as C}from"node:module";var m=C(import.meta.url);import{createReadStream as b,createWriteStream as v}from"node:fs";import{readFile as p,stat as k}from"node:fs/promises";import{isAbsolute as I,resolve as l}from"node:path";import{pathToFileURL as M}from"node:url";import{randomBytes as P}from"node:crypto";var g=`
|
|
3
3
|
heyo-cms generate [--name <name>] write a migration for what changed
|
|
4
4
|
heyo-cms migrate apply pending migrations
|
|
5
5
|
heyo-cms status show applied, pending and unplanned changes
|
|
@@ -26,5 +26,5 @@ import"./index-axpzy2hj.js";import"./index-6m1kjq9g.js";import"./index-abfzb1ve.
|
|
|
26
26
|
--config <path> configuration module (default: ./heyo-cms.config.ts)
|
|
27
27
|
--dir <path> migrations directory (default: the one in the config)
|
|
28
28
|
--env <path> environment file (default: ./.env, then ./.env.local)
|
|
29
|
-
`;async function _(e){let{command:n,positionals:o,flags:t}=N(e);if(!n||n==="help"||t.has("--help"))return console.log(g),n&&n!=="help"?1:0;await U(t.get("--env"));let s=await j(t.get("--config"));switch(n){case"generate":case"migrate":case"status":return await A(n,s,t);case"create-admin":return await d(n,s,await x(s,t));case"seed":return await d(n,s,await O(s,t));case"export":return await d(n,s,await R(s,t));case"import":return await d(n,s,await W(s,o[1],t));case"telemetry":return await D(s);default:return console.error(`Unknown command: ${n}`),console.log(g),1}}async function A(e,n,o){let t=l(o.get("--dir")??n._config.migrationsDirectory),s=new
|
|
29
|
+
`;async function _(e){let{command:n,positionals:o,flags:t}=N(e);if(!n||n==="help"||t.has("--help"))return console.log(g),n&&n!=="help"?1:0;await U(t.get("--env"));let s=await j(t.get("--config"));switch(n){case"generate":case"migrate":case"status":return await A(n,s,t);case"create-admin":return await d(n,s,await x(s,t));case"seed":return await d(n,s,await O(s,t));case"export":return await d(n,s,await R(s,t));case"import":return await d(n,s,await W(s,o[1],t));case"telemetry":return await D(s);default:return console.error(`Unknown command: ${n}`),console.log(g),1}}async function A(e,n,o){let t=l(o.get("--dir")??n._config.migrationsDirectory),s=new ln(t),a=await n.database();if(e==="generate"){let i=await qn({adapter:a,store:s,target:n.schema,plugins:n._config.plugins.flatMap((c)=>(c.migrations??[]).map((u)=>({plugin:c.id,id:u.id,steps:u.steps}))),...o.get("--name")?{name:o.get("--name")}:{}});if(i.created){console.log(`Wrote ${i.file}`);for(let c of i.summary)console.log(` ${c}`)}for(let c of i.plugins??[])console.log(`Wrote ${c.file} (plugin migration)`);if(!i.created&&(i.plugins??[]).length===0)console.log("No schema changes. Nothing to generate.");return await d(e,n,0)}if(e==="migrate"){let i=await Ln({adapter:a,store:s});if(i.applied.length===0)return console.log(`Up to date (${i.alreadyApplied} migration(s) already applied).`),await d(e,n,0);for(let c of i.applied)console.log(`Applied ${c}`);return await d(e,n,0)}let r=await Fn({adapter:a,store:s,target:n.schema});console.log(`Applied: ${r.applied.length}`);for(let i of r.pending)console.log(` pending ${i}`);for(let i of r.modified)console.log(` MODIFIED ${i} (applied, then edited)`);if(r.unplanned.length>0)console.log(` ${r.unplanned.length} change(s) in the configuration have no migration yet; run "heyo-cms generate".`);return r.pending.length>0||r.modified.length>0||r.unplanned.length>0?1:0}async function x(e,n){let o=n.get("--email")??process.env.HEYO_CMS_ADMIN_EMAIL;if(!o)return console.error("An address is required: heyo-cms create-admin --email you@example.com"),1;let t=n.get("--password")??process.env.HEYO_CMS_ADMIN_PASSWORD,s=t??E(),a=(n.get("--roles")??"admin").split(",").map((c)=>c.trim()).filter((c)=>c.length>0),r=await e.auth.users.byEmail(o);if(r)return console.error(`${o} already has an account (${r.status}). Use the panel, or cms.auth.users.setPassword().`),1;let i=await e.auth.users.create({email:o,password:s,roles:a,status:"active",...n.get("--name")?{name:n.get("--name")}:{}});if(await e.drainEvents(),console.log(`Created ${i.email} with role(s) ${i.roles.join(", ")}.`),!t)console.log(`Password: ${s}`),console.log("This is the only time it is shown.");return console.log(`Sign in at ${e._config.basePath}${e._config.admin.path}.`),0}function E(){return P(24).toString("base64url")}var S=["heyo-cms.seed.ts","heyo-cms.seed.js","seed.ts","src/heyo-cms.seed.ts"];async function O(e,n){let o=n.get("--file")?l(n.get("--file")):await y(S,"seed module"),t=await h(o),s=t.seed??t.default;if(typeof s!=="function")return console.error(`${o} does not export a seed. Add \`export async function seed(cms) { ... }\`.`),1;return await s(e),await e.drainEvents(),console.log(`Seeded from ${o}.`),0}async function R(e,n){let o=n.get("--out"),t=o?F(l(o)):Y(),s=0,a=0;try{for await(let r of Nt(e,{...f(n,"--collections","collections"),...f(n,"--globals","globals"),...n.has("--include-trashed")?{includeTrashed:!0}:{}})){if(r.kind==="document")s+=1;if(r.kind==="global")a+=1;await t.line(Ft(r))}}finally{await t.close()}return console.error(`Exported ${s} document(s) and ${a} global(s).`),0}async function W(e,n,o){if(!n)return console.error('A file is required: heyo-cms import content.ndjson (or "-").'),1;let t=o.get("--on-conflict")??"skip";if(!["skip","update","fail"].includes(t))return console.error(`--on-conflict takes skip, update or fail; got ${t}.`),1;let s={onConflict:t,...o.has("--dry-run")?{dryRun:!0}:{}},a=n==="-"?H():q(l(n)),r=await Ut(e,qt(Lt(a)),s),i=s.dryRun?"Would import":"Imported";if(console.log(`${i} ${r.documents.created} new and ${r.documents.updated} updated document(s), ${r.globals.updated} global(s).`),r.documents.skipped>0)console.log(`Skipped ${r.documents.skipped} document(s).`);for(let c of r.errors)console.error(` ${c}`);return r.errors.length>0?1:0}async function D(e){let n=Jt(e._config.telemetry),o=Wt("telemetry",e,await w());return console.log(n.enabled?"Telemetry: on":"Telemetry: off"),console.log(` ${n.reason}`),console.log(""),console.log(" What a command would send, in full:"),console.log(""),console.log(JSON.stringify(o,null,2)),console.log(""),console.log(" Turn it off with any of:"),console.log(" HEYO_TELEMETRY_DISABLED=1"),console.log(" DO_NOT_TRACK=1"),console.log(" telemetry: { enabled: false } in heyo-cms.config.ts"),console.log(""),0}async function d(e,n,o){try{await bn({event:e,cms:n,version:await w(),...n._config.telemetry?{config:n._config.telemetry}:{}})}catch{}return o}function N(e){let n=new Map,o=[];for(let t=0;t<e.length;t+=1){let s=e[t];if(!s.startsWith("--")){o.push(s);continue}let a=e[t+1];if(a!==void 0&&!a.startsWith("--"))n.set(s,a),t+=1;else n.set(s,"true")}return{command:o[0],positionals:o,flags:n}}function f(e,n,o){let t=e.get(n);if(!t||t==="true")return{};return{[o]:t.split(",").map((s)=>s.trim()).filter((s)=>s.length>0)}}var T=["heyo-cms.config.ts","heyo-cms.config.js","heyo-cms.config.mjs","src/heyo-cms.config.ts","app/heyo-cms.config.ts"];async function j(e){let n=e?l(e):await y(T,"configuration"),o=await h(n),t=o.cms??o.default;if(!L(t))throw Error(`${n} does not export a CMS. Add \`export const cms = heyoCms({ ... })\`.`);return t}async function h(e){return await(I(e)?import(M(e).href):import(e))}async function y(e,n){for(let o of e){let t=l(o);try{return await k(t),t}catch{}}throw Error(`No ${n} found. Looked for ${e.join(", ")}. Use --config or --file.`)}function L(e){return typeof e==="object"&&e!==null&&"_config"in e&&"schema"in e&&typeof e.database==="function"}async function U(e){let n=e?[l(e)]:[l(".env"),l(".env.local")];for(let o of n){let t;try{t=await p(o,"utf8")}catch{if(e)throw Error(`No environment file at ${o}.`);continue}for(let s of t.split(`
|
|
30
30
|
`)){let a=/^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/.exec(s);if(!a)continue;let[,r,i]=a;if(process.env[r]!==void 0)continue;let c=i.trim(),u=/^(["'])([\s\S]*)\1$/.exec(c);process.env[r]=u?u[2]:c.split(" #")[0].trim()}}}async function w(){try{let e=await p(new URL("../package.json",import.meta.url),"utf8");return JSON.parse(e).version??"0.0.0"}catch{return"0.0.0"}}function F(e){let n=v(e,{encoding:"utf8"});return{line:(o)=>new Promise((t,s)=>{n.write(o,(a)=>a?s(a):t())}),close:()=>new Promise((o)=>n.end(()=>o()))}}function Y(){return{line:(e)=>new Promise((n,o)=>{process.stdout.write(e,(t)=>t?o(t):n())}),close:async()=>{}}}async function*q(e){let n=b(e,{encoding:"utf8"});for await(let o of n)yield o}async function*H(){process.stdin.setEncoding("utf8");for await(let e of process.stdin)yield e}if(m.main==m.module)_(process.argv.slice(2)).then((e)=>{process.exitCode=e}).catch((e)=>{console.error(e instanceof Error?e.message:String(e)),process.exitCode=1});export{_ as main};
|
package/dist/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Yn,Qn,Xn,bt}from"./index-0fe3ngv2.js";import"./index-2zpnecrk.js";import"./index-1xwmw8vb.js";import"./index-5yt6r97r.js";import"./index-n09v6gx3.js";import"./index-2j6d79fk.js";import"./index-rpdkj3qk.js";import{ge,et,tt}from"./index-y8kzzn94.js";import"./index-e3yknwyr.js";import"./index-5j0cqm43.js";import"./index-pkxgzw6e.js";import"./index-q6jkbsjp.js";export{et as defaultAdminPath,ge as defaultBasePath,tt as defaultMigrationsDirectory,Yn as defineCollection,Qn as defineGlobal,Xn as heyoCms,bt as systemActor};
|
package/dist/content.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./index-
|
|
1
|
+
import"./index-pkxgzw6e.js";import"./index-q6jkbsjp.js";import"./index-e3yknwyr.js";import"./index-0fe3ngv2.js";import"./index-rpdkj3qk.js";import"./index-2j6d79fk.js";import"./index-5yt6r97r.js";import"./index-2zpnecrk.js";import{ct,ze,Zn,qt,Lt,Ft,Nt,Ut,yn}from"./index-mzxsxzkd.js";import"./index-1xwmw8vb.js";import"./index-n09v6gx3.js";import"./index-5j0cqm43.js";export{Nt as exportContent,ct as exportFormat,ze as exportVersion,Ut as importContent,Zn as parseRecord,qt as readRecords,Ft as serializeRecord,yn as splitLocales,Lt as toLines};
|
package/dist/db/d1.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Dt,ce,st}from"../index-gv8j76x3.js";class n{binding;id="d1";constructor(e){this.binding=e}async all(e,t){return(await this.bind(e,t).all()).results??[]}async run(e,t){return{rowsAffected:(await this.bind(e,t).run()).meta?.changes??0}}async exec(e){for(let t of Dt(e))await this.binding.prepare(t).run()}bind(e,t){let r=this.binding.prepare(e);return t.length>0?r.bind(...t):r}}function o(e){return new ce(new n(e),st,{capabilities:{transactions:!1}})}export{o as d1};
|
package/dist/db/mongodb.d.ts
CHANGED
|
@@ -101,7 +101,8 @@ export declare class MongoDatabaseAdapter implements DatabaseAdapter {
|
|
|
101
101
|
*/
|
|
102
102
|
transaction<T>(fn: (tx: Tx) => Promise<T>): Promise<T>;
|
|
103
103
|
query(_tx: Tx, query: Query): Promise<Row[]>;
|
|
104
|
-
mutate(
|
|
104
|
+
mutate(tx: Tx, mutation: Mutation): Promise<MutationResult>;
|
|
105
|
+
private write;
|
|
105
106
|
private applyStep;
|
|
106
107
|
private filter;
|
|
107
108
|
private condition;
|
package/dist/db/mongodb.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongodb.d.ts","sourceRoot":"","sources":["../../src/db/mongodb.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,sBAAsB,EACtB,oBAAoB,EACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAGV,QAAQ,EACR,cAAc,EACd,KAAK,EACL,GAAG,EACH,EAAE,EAEH,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EACV,iBAAiB,EACjB,aAAa,EACb,cAAc,EAEf,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"mongodb.d.ts","sourceRoot":"","sources":["../../src/db/mongodb.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,sBAAsB,EACtB,oBAAoB,EACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EA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,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,sBAAsB,CAAC;AACrF,wBAAgB,OAAO,CAAC,QAAQ,EAAE,iBAAiB,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,eAAe,CAAC"}
|
package/dist/db/mongodb.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Ce,Oe}from"../index-
|
|
2
|
-
`,summary:i}}async applyMigration(o){let t=JSON.parse(o.content);for(let i of t.steps)await this.applyStep(i)}async listAppliedMigrations(){return(await this.database.collection(z).find({},{sort:{_id:1}}).toArray()).map((t)=>({id:String(t._id),checksum:String(t.checksum),appliedAt:new Date(String(t.applied_at))}))}async recordMigration(o,t){await this.database.collection(z).insertOne({_id:o,checksum:t,applied_at:new Date().toISOString()})}async transaction(o){return o(new
|
|
1
|
+
import{Kn,at}from"../index-4j1kkeg2.js";import{Ce,Oe}from"../index-q6ak9ph4.js";import{z}from"../index-344y6q4n.js";import{e,n}from"../index-x72d1hzh.js";class h{id;real;constructor(o,t){this.id=o;this.real=t}}class b{database;id="mongodb";capabilities;schema={version:1,tables:[],collections:[]};documentColumns=new Map;columnNames=new Map;constructor(o,t={}){this.database=o;this.capabilities={transactions:t.transactions===!0,sqlMigrations:!1,jsonQuery:!0}}useSchema(o){this.schema=o,this.documentColumns=new Map(o.tables.filter((t)=>t.documentColumn!==void 0).map((t)=>[t.name,t.documentColumn])),this.columnNames=new Map(o.tables.map((t)=>[t.name,new Set(t.columns.map((i)=>i.name))]))}async introspect(){let o=(await this.database.listCollections().toArray()).map((i)=>i.name).filter((i)=>i!==z).sort(),t=[];for(let i of o){let r=await this.database.collection(i).listIndexes().toArray();t.push({name:i,columns:[],primaryKey:["id"],indexes:r.filter((a)=>a.name!=="_id_").map((a)=>({name:a.name,table:i,targets:Object.keys(a.key).map((c)=>({kind:"column",column:c})),unique:a.unique===!0})).sort((a,c)=>a.name.localeCompare(c.name))})}return{version:1,tables:t,collections:[]}}plan(o,t){return Ce(o,t)}render(o,t){let i=o.map(Oe);return{id:t,extension:"json",content:`${JSON.stringify({id:t,summary:i,steps:o},null,2)}
|
|
2
|
+
`,summary:i}}async applyMigration(o){let t=JSON.parse(o.content);for(let i of t.steps)await this.applyStep(i)}async listAppliedMigrations(){return(await this.database.collection(z).find({},{sort:{_id:1}}).toArray()).map((t)=>({id:String(t._id),checksum:String(t.checksum),appliedAt:new Date(String(t.applied_at))}))}async recordMigration(o,t){await this.database.collection(z).insertOne({_id:o,checksum:t,applied_at:new Date().toISOString()})}async transaction(o){return o(new h(x(),this.capabilities.transactions))}async query(o,t){let i=this.database.collection(t.table),r=this.filter(t.table,t.where);if(t.count===!0)return[{count:await i.countDocuments(r)}];let a={};if(t.orderBy&&t.orderBy.length>0)a.sort=Object.fromEntries(t.orderBy.map((s)=>[this.path(t.table,s.path),s.direction==="desc"?-1:1]));if(t.limit!==void 0)a.limit=t.limit;if(t.offset!==void 0)a.skip=t.offset;return(await i.find(r,a).toArray()).map((s)=>this.decode(t.table,s,t.select,t.table))}async mutate(o,t){try{return await this.write(o,t)}catch(i){let r=Kn(i);if(r===null)throw i;throw at(this.schema,t.table,r,t.kind==="insert"?t.values:void 0,i)}}async write(o,t){let i=this.database.collection(t.table);if(t.kind==="insert"){let s=this.encode(t.values);return await i.insertOne(s),{rows:t.returning===!1?[]:[this.decode(t.table,s)],count:1}}if(t.kind==="update"){let s=this.filter(t.table,t.where),l=this.encode(t.set),u=t.returning===!1?[]:await i.find(s,{projection:{_id:1}}).toArray(),m=await i.updateMany(s,{$set:l}),p=m.modifiedCount??m.matchedCount??0;if(t.returning===!1)return{rows:[],count:p};let g=u.length===0?[]:await i.find({_id:{$in:u.map((d)=>d._id)}}).toArray();return{rows:g.map((d)=>this.decode(t.table,d)),count:Math.max(p,g.length)}}let r=this.filter(t.table,t.where),a=t.returning===!0?await i.find(r).toArray():[],c=await i.deleteMany(r);return{rows:a.map((s)=>this.decode(t.table,s)),count:c.deletedCount??a.length}}async applyStep(o){switch(o.kind){case"create_table":{if(!(await this.database.listCollections().toArray()).map((i)=>i.name).includes(o.table.name))await this.database.createCollection(o.table.name);return}case"drop_table":await this.database.dropCollection(o.table).catch(()=>{return});return;case"add_column":{if(o.column.default===void 0)return;await this.database.collection(o.table).updateMany({[o.column.name]:{$exists:!1}},{$set:{[o.column.name]:o.column.default}});return}case"drop_column":await this.database.collection(o.table).updateMany({},{$unset:{[o.column]:""}});return;case"alter_column":return;case"create_index":{let t={};for(let i of o.index.targets)t[i.kind==="column"?i.column:[i.column,...i.path].join(".")]=1;await this.database.collection(o.index.table).createIndex(t,{name:o.index.name,unique:o.index.unique,...o.index.where?{partialFilterExpression:{[o.index.where.column]:o.index.where.equals}}:{}});return}case"drop_index":await this.database.collection(o.table).dropIndex(o.index).catch(()=>{return});return;case"set_document_field":{let t=[o.documentColumn,...o.path].join(".");await this.database.collection(o.table).updateMany({collection:o.collection,[t]:{$exists:!1}},{$set:{[t]:o.value}});return}case"unset_document_field":{let t=[o.documentColumn,...o.path].join(".");await this.database.collection(o.table).updateMany({collection:o.collection},{$unset:{[t]:""}});return}}}filter(o,t){if(!t)return{};if(t.kind==="and"){if(t.conditions.length===0)return{};return{$and:t.conditions.map((c)=>this.filter(o,c))}}if(t.kind==="or"){if(t.conditions.length===0)return{_id:{$exists:!1}};return{$or:t.conditions.map((c)=>this.filter(o,c))}}if(t.kind==="not")return{$nor:[this.filter(o,t.condition)]};let i=this.path(o,t.path),r=this.documentColumns.get(o),a=r!==void 0&&i.startsWith(`${r}.`)?M(t.value):t.value;return{[i]:this.condition(t.operator,a)}}condition(o,t){switch(o){case"eq":return{$eq:t};case"ne":return{$ne:t};case"gt":return{$gt:t};case"gte":return{$gte:t};case"lt":return{$lt:t};case"lte":return{$lte:t};case"in":return{$in:Array.isArray(t)?t:[t]};case"nin":return{$nin:Array.isArray(t)?t:[t]};case"like":case"ilike":return{$regex:y(String(t)),...o==="ilike"?{$options:"i"}:{}};case"contains":return{$eq:t};case"exists":return t===!1?{$in:[null]}:{$nin:[null]}}}path(o,t){let[i,...r]=t.split("."),a=i;if(this.columnNames.get(o)?.has(a))return[a==="id"?"_id":a,...r].join(".");let c=this.documentColumns.get(o);if(!c)throw new e(`Unknown column ${o}.${t}`,{status:400,code:"unknown_column"});return[c,...t.split(".")].join(".")}encode(o){let t={};for(let[i,r]of Object.entries(o))t[i==="id"?"_id":i]=r;return t}decode(o,t,i,r){let a={};for(let[s,l]of Object.entries(t))a[s==="_id"?"id":s]=l;if(!i||i.length===0||r===void 0)return a;let c={};for(let s of i){let l=this.path(r,s).replace(/^_id\b/,"id");c[s]=w(a,l.split("."))}return c}}function w(o,t){let i=o;for(let r of t){if(i===null||typeof i!=="object")return null;i=i[r]}return i??null}function M(o){if(o instanceof Date)return o.toISOString();return Array.isArray(o)?o.map((t)=>t instanceof Date?t.toISOString():t):o}function y(o){return`^${o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replaceAll("%",".*").replaceAll("_",".")}$`}var f=0;function x(){return f+=1,`mongo_tx_${f}`}function k(o,t={}){if(typeof o==="string")return async()=>k(await C(o,t),t);return new b(o,t)}async function C(o,t){let r;try{r=await import("mongodb")}catch{throw new n("database",'mongodb(url) needs the "mongodb" package; install it, or pass a Db you built yourself')}let a=new r.MongoClient(o);return await a.connect(),t.database?a.db(t.database):a.db()}export{b as MongoDatabaseAdapter,k as mongodb};
|
package/dist/db/postgres.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ce,
|
|
1
|
+
import{ce,Bn}from"../index-gv8j76x3.js";import{n}from"../index-x72d1hzh.js";class a{client;id;constructor(t,e="postgres"){this.client=t;this.id=e}async all(t,e){return(await this.client.query(t,e)).rows}async run(t,e){return{rowsAffected:(await this.client.query(t,e)).rowCount??0}}async exec(t){await this.client.query(t)}async close(){await this.client.end?.()}}function u(t,e={}){if(typeof t==="string")return async()=>u(await g(t),e);let r=t,o=new a(r,e.id??"postgres");if(r.connect){let l=r.connect.bind(r);o.transaction=async(p)=>{let c=await l(),s=new a(c,o.id);try{await s.exec("BEGIN");let i=await p(s);return await s.exec("COMMIT"),i}catch(i){throw await s.exec("ROLLBACK").catch(()=>{return}),i}finally{c.release?.()}}}return new ce(o,Bn)}async function g(t){let r;try{r=await import("pg")}catch{throw new n("database",'postgres(url) needs the "pg" package; install it, or pass a client you built yourself')}return new r.Pool({connectionString:t})}export{u as postgres};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/db/sql/adapter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,KAAK,EACL,GAAG,EACH,EAAE,EACH,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACV,iBAAiB,EACjB,aAAa,EACb,cAAc,EACf,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/db/sql/adapter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,KAAK,EACL,GAAG,EACH,EAAE,EACH,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACV,iBAAiB,EACjB,aAAa,EACb,cAAc,EACf,MAAM,oBAAoB,CAAC;AAI5B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAY3D,MAAM,WAAW,iBAAiB;IAChC,uEAAuE;IACvE,YAAY,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAC7C,MAAM,CAAC,EAAE,cAAc,CAAC;CACzB;AAED;;;;;;GAMG;AACH,q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AK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAYhD;IAEK,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,cAAc,CAAC,CA6BhE;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3B;IAED;;;;;;OAMG;YACW,aAAa;CAW5B"}
|
package/dist/db/sql/dialect.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ColumnValue } from "../../types/query";
|
|
2
2
|
import type { ColumnSnapshot, ColumnType } from "../../types/schema";
|
|
3
|
+
import { type UniqueViolation } from "../unique";
|
|
3
4
|
/**
|
|
4
5
|
* Everything two SQL engines disagree about.
|
|
5
6
|
*
|
|
@@ -20,6 +21,8 @@ export interface SqlDialect {
|
|
|
20
21
|
likeOperator(caseInsensitive: boolean): string;
|
|
21
22
|
encode(value: ColumnValue | undefined, type: ColumnType): unknown;
|
|
22
23
|
decode(value: unknown, type: ColumnType): ColumnValue;
|
|
24
|
+
/** The unique rule a driver error reports breaking, or null. */
|
|
25
|
+
uniqueViolation(error: unknown): UniqueViolation | null;
|
|
23
26
|
/** True when `ALTER TABLE ... ALTER COLUMN` exists. */
|
|
24
27
|
readonly supportsAlterColumn: boolean;
|
|
25
28
|
/** The statement that opens a transaction; `BEGIN` when absent. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialect.d.ts","sourceRoot":"","sources":["../../../src/db/sql/dialect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"dialect.d.ts","sourceRoot":"","sources":["../../../src/db/sql/dialect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK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/dist/db/sqlite.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ce,st}from"../index-
|
|
1
|
+
import{ce,st}from"../index-gv8j76x3.js";import{n}from"../index-x72d1hzh.js";var r=5000;class s{database;id;constructor(e,t="sqlite"){this.database=e;this.id=t}async all(e,t){return this.database.prepare(e).all(...t)}async run(e,t){let a=this.database.prepare(e).run(...t);return{rowsAffected:Number(a.changes??0)}}async exec(e){this.database.exec(e)}async close(){this.database.close?.()}}function o(e,t={}){if("file"in e&&typeof e.file==="string")return async()=>o(await u(e.file),e);let a=e;return l(a,t.busyTimeout),new ce(new s(a,t.id??"sqlite"),st)}function l(e,t){if(t===void 0){let[a]=e.prepare("PRAGMA busy_timeout").all();if(Number(a?.timeout??0)>0)return}else if(!Number.isFinite(t)||t<0)throw new n("database","busyTimeout must be a number of milliseconds, 0 or more");e.exec(`PRAGMA busy_timeout = ${Math.trunc(t??r)}`)}async function u(e){for(let t of["bun:sqlite","node:sqlite"])try{let a=await import(t),i=a.Database??a.DatabaseSync;if(i)return new i(e)}catch{}throw new n("database","no SQLite is available in this runtime; pass a database instance instead")}export{o as sqlite};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { CmsError } from "../errors";
|
|
2
|
+
import type { Row } from "../types/query";
|
|
3
|
+
import type { SchemaSnapshot } from "../types/schema";
|
|
4
|
+
/**
|
|
5
|
+
* Which unique rule a write broke, in the words the engine used.
|
|
6
|
+
*
|
|
7
|
+
* Postgres and MongoDB name the index. SQLite names the index when it is one
|
|
8
|
+
* and the columns when the rule is a column's own — a primary key, above all.
|
|
9
|
+
*/
|
|
10
|
+
export interface UniqueViolation {
|
|
11
|
+
index?: string;
|
|
12
|
+
columns?: string[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Reads a unique violation out of a SQLite or D1 error.
|
|
16
|
+
*
|
|
17
|
+
* By the message, because that is the one thing `bun:sqlite`, `node:sqlite`,
|
|
18
|
+
* `better-sqlite3` and a D1 binding agree on: their codes live on different
|
|
19
|
+
* properties, and D1 adds its own prefix and suffix to the same sentence.
|
|
20
|
+
*/
|
|
21
|
+
export declare function sqliteUniqueViolation(error: unknown): UniqueViolation | null;
|
|
22
|
+
/**
|
|
23
|
+
* Reads a unique violation out of a Postgres error.
|
|
24
|
+
*
|
|
25
|
+
* SQLSTATE 23505 is the same for `pg`, Neon, PGlite and postgres.js. The
|
|
26
|
+
* constraint is `constraint` on the first three and `constraint_name` on the
|
|
27
|
+
* last; the message carries it for anything else.
|
|
28
|
+
*/
|
|
29
|
+
export declare function postgresUniqueViolation(error: unknown): UniqueViolation | null;
|
|
30
|
+
/**
|
|
31
|
+
* Reads a unique violation out of a MongoDB error: code 11000, or the
|
|
32
|
+
* `E11000` the message starts with when the code is not carried over.
|
|
33
|
+
*/
|
|
34
|
+
export declare function mongoUniqueViolation(error: unknown): UniqueViolation | null;
|
|
35
|
+
/**
|
|
36
|
+
* The 409 a broken unique rule is, instead of the 500 an unknown driver error
|
|
37
|
+
* would be.
|
|
38
|
+
*
|
|
39
|
+
* Said the way the person who sent the write thinks about it. A content
|
|
40
|
+
* field's index becomes "handle is already used", with the field in
|
|
41
|
+
* `details.fields` like a validation error, so a form can put it next to the
|
|
42
|
+
* input; the documents' primary key becomes the id an import tried to reuse.
|
|
43
|
+
* The driver's error stays as the `cause`, for the operator's log only.
|
|
44
|
+
*/
|
|
45
|
+
export declare function uniqueConflict(schema: SchemaSnapshot, table: string, violation: UniqueViolation, values: Row | undefined, cause: unknown): CmsError;
|
|
46
|
+
//# sourceMappingURL=unique.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unique.d.ts","sourceRoot":"","sources":["../../src/db/unique.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,EAAiB,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAErE;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAY5E;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,OAAO,GACb,eAAe,GAAG,IAAI,CAUxB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAM3E;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,cAAc,EACtB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,eAAe,EAC1B,MAAM,EAAE,GAAG,GAAG,SAAS,EACvB,KAAK,EAAE,OAAO,GACb,QAAQ,CAyDV"}
|
package/dist/editor.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Po,_o,$o,jo,Io,Eo,Mo,Do,qo,Lo,Fo,No,Uo,Jo,Wo,zo,Ho,Bo,Vo,Go,Ko,Zo,Yo,he,Mn}from"./index-rpdkj3qk.js";import{k,Y,Pt,sn,po,mo,Te,Q,fo,X,ho,Fe,Qo,Ne,Xe,ee}from"./index-twqpdtfh.js";export{jo as blockquoteNode,Bo as boldMark,Io as bulletListNode,Lo as codeBlockNode,Zo as codeMark,Y as defineEditorMark,k as defineEditorNode,Te as describeEditorSchema,Po as docNode,Fe as escapeHtml,Qo as escapeMarkdown,sn as getEditorMark,Pt as getEditorNode,No as hardBreakNode,$o as headingNode,Fo as horizontalRuleNode,Ne as htmlAttributes,Uo as imageNode,Xe as indentContinuation,Vo as italicMark,Yo as linkMark,Mo as listItemNode,Eo as orderedListNode,_o as paragraphNode,mo as registeredEditorMarks,po as registeredEditorNodes,Q as renderRichText,he as richTextFromMarkdown,Mn as richTextFromText,fo as richTextToHtml,X as richTextToMarkdown,ho as richTextToPlainText,Ko as strikeMark,ee as stringAttr,Ho as tableCellNode,zo as tableHeaderNode,Jo as tableNode,Wo as tableRowNode,qo as taskItemNode,Do as taskListNode,Go as underlineMark};
|
package/dist/fields.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Dn,an,ye}from"./index-e3yknwyr.js";import{go,Xo,er,C}from"./index-fy8r8e53.js";import{n}from"./index-x72d1hzh.js";import{z as e}from"zod";var o=e.looseObject({label:e.string().optional(),description:e.string().optional(),localized:e.boolean().optional(),required:e.boolean().optional(),unique:e.boolean().optional(),index:e.boolean().optional(),readOnly:e.boolean().optional()}),d=e.lazy(()=>e.union([e.string(),e.number(),e.boolean(),e.null(),e.array(d),e.record(e.string(),d)])),O=C({name:"text",optionsSchema:o.extend({default:e.string().optional(),minLength:e.number().int().nonnegative().optional(),maxLength:e.number().int().positive().optional(),pattern:e.string().optional()}),schema:(t)=>{let i=e.string();if(t.minLength!==void 0)i=i.min(t.minLength);if(t.maxLength!==void 0)i=i.max(t.maxLength);if(t.pattern!==void 0)i=i.regex(new RegExp(t.pattern));return i},column:(t)=>({type:"text",...t.default===void 0?{}:{default:t.default}}),aiActions:["improve","summarize","translate"]}),y=C({name:"textarea",optionsSchema:o.extend({default:e.string().optional(),maxLength:e.number().int().positive().optional(),rows:e.number().int().positive().optional()}),schema:(t)=>t.maxLength===void 0?e.string():e.string().max(t.maxLength),column:()=>({type:"text"}),aiActions:["improve","summarize","translate"]}),j=C({name:"richText",optionsSchema:o.extend({nodes:e.array(e.string()).optional()}),schema:()=>e.looseObject({type:e.string()}),column:()=>({type:"json"}),aiActions:["improve","summarize","translate"]}),I=C({name:"number",optionsSchema:o.extend({default:e.number().optional(),min:e.number().optional(),max:e.number().optional(),integer:e.boolean().optional()}),schema:(t)=>{let i=t.integer===!0?e.number().int():e.number();if(t.min!==void 0)i=i.min(t.min);if(t.max!==void 0)i=i.max(t.max);return i},column:(t)=>({type:t.integer===!0?"integer":"real",...t.default===void 0?{}:{default:t.default}})}),Z=C({name:"boolean",optionsSchema:o.extend({default:e.boolean().optional()}),schema:()=>e.boolean(),column:(t)=>({type:"boolean",...t.default===void 0?{}:{default:t.default}})}),v=C({name:"date",optionsSchema:o.extend({default:e.string().optional(),mode:e.enum(["date","datetime"]).optional()}),schema:()=>e.string().refine((t)=>!Number.isNaN(Date.parse(t)),"must be an ISO 8601 date"),column:()=>({type:"timestamp"})}),f=(t)=>t.map((i)=>typeof i==="string"?i:i.value),x=o.extend({options:e.array(e.union([e.string(),e.strictObject({label:e.string(),value:e.string()})])).min(1),default:e.string().optional()}),T=C({name:"select",optionsSchema:x,schema:(t)=>e.enum(f(t.options)),column:(t)=>({type:"text",...t.default===void 0?{}:{default:t.default}})});function J(t){return T(t)}var h=C({name:"multiselect",optionsSchema:x.extend({default:e.array(e.string()).optional(),minItems:e.number().int().nonnegative().optional(),maxItems:e.number().int().positive().optional()}),schema:(t)=>{let i=e.array(e.enum(f(t.options)));if(t.minItems!==void 0)i=i.min(t.minItems);if(t.maxItems!==void 0)i=i.max(t.maxItems);return i},column:()=>({type:"json",array:!0}),aiActions:["tags"]});function q(t){return h(t)}var B=C({name:"json",optionsSchema:o,schema:()=>d,column:()=>({type:"json"})}),b=C({name:"media",optionsSchema:o.extend({accept:e.string().optional()}),schema:()=>e.string().min(1),column:()=>({type:"text"}),aiActions:["alt"]}),F=C({name:"relation",optionsSchema:o.extend({relationTo:e.string().min(1),many:e.boolean().optional()}),schema:(t)=>t.many===!0?e.array(e.string().min(1)):e.string().min(1),column:(t)=>({type:"text",...t.many===!0?{type:"json",array:!0}:{}}),aiActions:["tags"]});function A(t,i){return F({...i??{},relationTo:t})}var w=C({name:"slug",optionsSchema:o.extend({from:e.string().min(1).optional(),history:e.boolean().optional(),maxLength:e.number().int().min(8).max(512).optional(),slugify:e.function().optional(),default:e.string().optional()}),schema:(t)=>e.string().max(t.maxLength??96).regex(new RegExp(Dn),"lowercase letters, digits and single hyphens only"),column:(t)=>({type:"text",...t.default===void 0?{}:{default:t.default}})});function K(t){let i={...t??{}},s=i.localized===!0,{maxLength:l,from:a}=i,r=i.slugify??((u)=>ye(u,l===void 0?{}:{maxLength:l}));return w({...i,unique:s?i.unique===!1?!1:void 0:i.unique??!0,index:s?void 0:i.index??!0,...i.generate===void 0&&a!==void 0?{generate:({fields:u})=>{let p=u[a],m=typeof p==="string"?r(p):"";return m===""?null:m}}:{}})}var E=C({name:"email",optionsSchema:o,schema:()=>e.string().email(),column:()=>({type:"text"})}),S=C({name:"url",optionsSchema:o,schema:()=>e.string().url(),column:()=>({type:"text"})}),c=new Set(["text","textarea","email","url","number","boolean","date","select","multiselect"]),V=["localized","unique","index","access","generate","aiGenerate","ai"],g=(t)=>typeof t==="object"&&t!==null&&typeof t.type==="string"&&typeof t.schema?.safeParse==="function",z=C({name:"list",optionsSchema:o.extend({fields:e.record(e.string(),e.custom(g,"must be a field, such as text()")),minItems:e.number().int().nonnegative().optional(),maxItems:e.number().int().positive().optional(),default:e.array(e.record(e.string(),d)).optional()}),schema:(t)=>{let i={};for(let[l,a]of Object.entries(t.fields))i[l]=a.required?a.schema:a.schema.optional();let s=e.array(e.strictObject(i));if(t.minItems!==void 0)s=s.min(t.minItems);if(t.maxItems!==void 0)s=s.max(t.maxItems);return s},column:()=>({type:"json",array:!0})});function M(t){let i=t?.fields;if(!i||typeof i!=="object"||Object.keys(i).length===0)throw new n("fields.list.fields","a list needs at least one field in a row");for(let[s,l]of Object.entries(i)){let a=`fields.list.fields.${s}`;if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(s))throw new n(a,"a row's field name must be an identifier (letters, digits, _)");if(!g(l))throw new n(a,"must be a field, such as text()");if(!c.has(l.type))throw new n(a,`a list row cannot hold a ${l.type} field; use ${[...c].join(", ")}`);for(let r of V)if(l.options[r]!==void 0)throw new n(`${a}.${r}`,r==="localized"?"a list is localized as a whole: set localized on the list":"not supported inside a list row")}if(t.unique===!0||t.index===!0)throw new n("fields.list","a list cannot be unique or indexed");if(t.minItems!==void 0&&t.maxItems!==void 0&&t.minItems>t.maxItems)throw new n("fields.list.minItems","cannot be more than maxItems");return z(t)}function N(){return{seoTitle:O({label:"SEO title",localized:!0,maxLength:70,aiGenerate:{label:"Suggest an SEO title",prompt:"Write a search-friendly title under 60 characters."}}),seoDescription:y({label:"SEO description",localized:!0,maxLength:160,aiGenerate:{label:"Suggest an SEO description",prompt:"Summarise the article in one sentence under 155 characters."}}),ogImage:b({label:"Social image",accept:"image/*"}),canonical:S({label:"Canonical URL"})}}export{Z as boolean,v as date,C as defineField,E as email,Xo as getFieldType,an as isSlug,B as json,M as list,b as media,q as multiselect,I as number,go as registerFieldType,er as registeredFieldTypes,A as relation,j as richText,J as select,N as seoFields,K as slug,Dn as slugPattern,ye as slugify,O as text,y as textarea,S as url};
|
package/dist/http.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./index-
|
|
1
|
+
import"./index-q6jkbsjp.js";import"./index-pkxgzw6e.js";import"./index-rpdkj3qk.js";import{Ze,g,Ye,y,I,Pn,oo,ro,P,G,i,_n,oe,K,Tt,en,f,De,v,W,Re,o,c,a,q,$n,h,r,N,Ct,jn,In,Se,qe}from"./index-5yt6r97r.js";import"./index-2j6d79fk.js";import"./index-n09v6gx3.js";import"./index-5j0cqm43.js";export{Se as Router,G as booleanParam,jn as buildOpenApi,qe as createCmsHttp,Tt as errorResponse,Pn as findArgs,P as integerParam,i as json,h as jsonBody,$n as listParams,q as localeParams,oe as noContent,r as okJson,W as optionalString,Re as optionalStringArray,ro as parseSort,oo as parseWhere,c as pathParam,a as queryParam,I as readArgs,en as readJson,f as readJsonObject,Ct as readResponses,o as ref,In as requestDb,y as requestSource,Ze as requireActor,De as requireData,g as requirePermission,Ye as requireSession,v as requireString,K as stopped,_n as text,N as writeResponses};
|