@north-light/cli 0.3.609 → 0.3.610
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/core/import/load/bind.d.ts +4 -11
- package/dist/core/import/load/bind.js +14 -14
- package/dist/core/import/load/blobs.d.ts +1 -1
- package/dist/core/import/load/blobs.js +1 -1
- package/dist/core/import/load/run.js +1 -1
- package/package.json +2 -2
- package/packages/crouter-identity/package.json +1 -1
- package/runtime.lock.json +13 -13
|
@@ -11,16 +11,9 @@ export declare function checkStagedPersons(input: RewriteInput): Promise<Record<
|
|
|
11
11
|
* document, the person's own object, an object with an `acts_for` fact for the person, or anything below those that is not directly under an app), and no profile or grant the
|
|
12
12
|
* rows name belongs to another person. */
|
|
13
13
|
export declare function checkStagedReferences(input: RewriteInput): Promise<void>;
|
|
14
|
-
/** After staging, before rewrite 1: every blob key a staged row names has the shape its row would produce and an owner (node) that is in this bundle
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
|
|
18
|
-
*
|
|
19
|
-
* A row whose owner node is in neither the bundle nor the target, and that no live row of the bundle holds, is what a deleted node left behind (the purge of a node
|
|
20
|
-
* keeps a conversation or attachment row and its blob; a deleted node's job rows stay too). It is dropped, not refused: a conversation no staged `sessions` row binds
|
|
21
|
-
* (its `conversation_parts` and `conversation_entries` rows), an `upload_uses` row whose `run_id` is not a node of the bundle, a `jobs` row whose job object is not
|
|
22
|
-
* owned by a node of the bundle. `moveRunBlobs` leaves the blob of such an owner where it was uploaded. A conversation's owner is the owner of its part keys; a
|
|
23
|
-
* `conversation_entries` row with no part names no owner and is copied as before. Returns rows dropped per table. */
|
|
24
|
-
export declare function checkStagedBlobKeys(input: RewriteInput): Promise<Record<string, number>>;
|
|
14
|
+
/** After staging, before rewrite 1: every blob key a staged row names has the shape its row would produce and an owner (node) that is in this bundle.
|
|
15
|
+
* A key naming another person's blob is `person_mismatch`; a key of no known shape is `bundle_invalid`. Without this, the importer's own node would read, and
|
|
16
|
+
* compaction would delete, a blob of someone else's conversation. (Human requests are checked by `checkStagedRequestKeys`, after their dirs are rewritten to blob keys.) */
|
|
17
|
+
export declare function checkStagedBlobKeys(input: RewriteInput): Promise<void>;
|
|
25
18
|
/** After rewrite 4b: a human request's `request_dir`, `presentation_dir` and `file` that are blob keys (`requests/…`) are under the request's own `requests/<its id>`. */
|
|
26
19
|
export declare function checkStagedRequestKeys(input: RewriteInput): Promise<void>;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var
|
|
2
|
-
UNION ALL SELECT 'grants' FROM ${
|
|
3
|
-
UNION ALL SELECT 'nodes' FROM ${
|
|
4
|
-
WHERE adapter_json::jsonb #>> '{principal,sub}' IS NOT NULL AND adapter_json::jsonb #>> '{principal,sub}' NOT IN (?, ?) LIMIT 5`,
|
|
5
|
-
AND ${
|
|
6
|
-
SELECT DISTINCT value, value FROM ${
|
|
7
|
-
UNION SELECT c.start, o.owner FROM chain c JOIN ${
|
|
1
|
+
var g=Object.defineProperty;var u=(s,t)=>g(s,"name",{value:t,configurable:!0});import{parseBlobKey as L}from"../bundle/blob-keys.js";import{q as E}from"./catalog.js";import{objectIdColumns as R}from"./rewrite.js";import{ImportLaneError as m}from"./stage.js";const w=/^user:[A-Za-z0-9._-]+$/,S=u(s=>s.replace(/^user:/,""),"bare"),I=u((s,t)=>`${E(s)}.${E(t)}`,"sq"),$=u(async(s,t,...r)=>await s.prepareUncached(t).all(...r),"all");function _(s,t){return new m("bind","person_mismatch",s,t)}u(_,"mismatch");function D(s,t,r,a){if(s===t||s===r)return r;throw _(`${a} names ${s}, which is neither the bundle's person nor the importing person`,{where:a,value:s})}u(D,"boundSub");async function k(s,t,r,a){if(!w.test(r))throw _(`the bundle's person ${JSON.stringify(r)} is not a user:<id> principal`,{where:"source.json person",value:r});if(r===a)return;const i=u(e=>I(t,e),"T"),n=await s.prepareUncached(`SELECT 'identities' AS tbl FROM ${i("identities")} WHERE scheme IN ('user', 'local-user') AND external_id = ?
|
|
2
|
+
UNION ALL SELECT 'grants' FROM ${i("grants")} WHERE sub = ? UNION ALL SELECT 'profiles' FROM ${i("profiles")} WHERE person = ?
|
|
3
|
+
UNION ALL SELECT 'nodes' FROM ${i("nodes")} WHERE sub = ? LIMIT 1`).get(r,r,r,r);if(n!==void 0)throw _(`the bundle's person ${r} is already a person in the target (${n.tbl}), not the importing person ${a}`,{where:`${n.tbl}`,value:r})}u(k,"checkSourcePerson");const v=[["nodes","sub"],["crons","sub"],["grants","sub"],["profiles","person"],["charges","sub"],["limits","sub"],["audit_rows","sub"],["provider_approvals","sub"]],C=[["charges","payer"],["limits","payer"],["audit_rows","payer"],["audit_rows","grantee"],["charges","grantee"],["run_events","grantee"],["idempotency_keys","grantee"],["uploads","grantee"],["provider_approvals","grantee"],["profiles","grantee"],["crons","grantee"]];async function H(s){const{db:t,schema:r,sourcePerson:a,targetPerson:i}=s,n=u(p=>I(r,p),"S"),e=u((p,d)=>{throw _(`${p} names ${d.join(", ")}, who is neither the bundle's person ${a} nor the importing person ${i}`,{where:p,values:d})},"refuse");for(const[p,d]of v){const o=await $(t,`SELECT DISTINCT ${E(d)} AS v FROM ${n(p)} WHERE ${E(d)} IS NOT NULL AND ${E(d)} <> '' AND ${E(d)} NOT IN (?, ?) LIMIT 5`,a,i);o.length>0&&e(`${p}.${d}`,o.map(l=>l.v))}for(const[p,d]of C){const o=await $(t,`SELECT DISTINCT ${E(d)} AS v FROM ${n(p)} WHERE ${E(d)} LIKE 'user:%' AND ${E(d)} NOT IN (?, ?) LIMIT 5`,a,i);o.length>0&&e(`${p}.${d}`,o.map(l=>l.v))}const c=await $(t,`SELECT DISTINCT external_id AS v FROM ${n("identities")} WHERE scheme IN ('user', 'local-user') AND external_id NOT IN (?, ?) LIMIT 5`,a,i);c.length>0&&e("identities.external_id",c.map(p=>p.v));const f=await $(t,`SELECT DISTINCT adapter_json::jsonb #>> '{principal,sub}' AS v FROM ${n("daemon_actions")}
|
|
4
|
+
WHERE adapter_json::jsonb #>> '{principal,sub}' IS NOT NULL AND adapter_json::jsonb #>> '{principal,sub}' NOT IN (?, ?) LIMIT 5`,a,i);f.length>0&&e("daemon_actions principal.sub",f.map(p=>p.v));const h=await $(t,`SELECT DISTINCT subject_id AS v FROM ${n("relations")} WHERE relation = 'acts_for' AND subject_type = 'user' AND subject_id NOT IN (?, ?) LIMIT 5`,S(a),S(i));h.length>0&&e("relations acts_for subject",h.map(p=>p.v));const N=Number((await t.prepareUncached(`DELETE FROM ${n("relations")} WHERE resource_type = 'crtr/group'`).run()).changes);return N>0?{relations:N}:{}}u(H,"checkStagedPersons");async function W(s){const{db:t,schema:r,target:a,catalog:i,targetPerson:n}=s,e=u(o=>I(r,o),"S"),c=u(o=>I(a,o),"T"),f=S(n);await t.exec(`CREATE TABLE ${e("_refs")} (tbl text NOT NULL, col text NOT NULL, value text NOT NULL)`);const h=[];for(const[o,l]of R(i))if(!(!i.tables.has(o)||o==="relations"))for(const b of l)!(o==="nodes"&&b==="profile_id")&&!(o==="crons"&&b==="profile")&&h.push([o,b,""]);h.push(["relations","resource_id","WHERE resource_type = 'crtr/object'"]);for(const[o,l,b]of h)await t.prepareUncached(`INSERT INTO ${e("_refs")} SELECT ?, ?, ${E(l)}::text FROM ${e(o)} ${b===""?"WHERE":`${b} AND`} ${E(l)} IS NOT NULL
|
|
5
|
+
AND ${E(l)}::text NOT IN (SELECT id FROM ${e("objects")}) AND ${E(l)}::text IN (SELECT id FROM ${c("objects")})`).run(o,l);const N=await $(t,`WITH RECURSIVE chain(start, id) AS (
|
|
6
|
+
SELECT DISTINCT value, value FROM ${e("_refs")}
|
|
7
|
+
UNION SELECT c.start, o.owner FROM chain c JOIN ${c("objects")} o ON o.id = c.id JOIN ${c("objects")} up ON up.id = o.owner AND up.type <> 'app'),
|
|
8
8
|
ok(id) AS (
|
|
9
|
-
SELECT o.id FROM ${
|
|
10
|
-
UNION SELECT d.object FROM ${
|
|
11
|
-
UNION SELECT i.object FROM ${
|
|
12
|
-
UNION SELECT r.resource_id FROM ${
|
|
13
|
-
SELECT r.tbl, r.col, r.value FROM ${
|
|
14
|
-
WHERE NOT EXISTS (SELECT 1 FROM chain c JOIN ok ON ok.id = c.id WHERE c.start = r.value) LIMIT 10`,
|
|
15
|
-
JOIN ${
|
|
9
|
+
SELECT o.id FROM ${c("objects")} o WHERE o.type = 'app'
|
|
10
|
+
UNION SELECT d.object FROM ${c("documents")} d WHERE d.source_path IS NOT NULL
|
|
11
|
+
UNION SELECT i.object FROM ${c("identities")} i WHERE i.scheme IN ('user', 'local-user') AND i.external_id = ?
|
|
12
|
+
UNION SELECT r.resource_id FROM ${c("relations")} r WHERE r.resource_type = 'crtr/object' AND r.relation = 'acts_for' AND r.subject_type = 'user' AND r.subject_id = ?)
|
|
13
|
+
SELECT r.tbl, r.col, r.value FROM ${e("_refs")} r
|
|
14
|
+
WHERE NOT EXISTS (SELECT 1 FROM chain c JOIN ok ON ok.id = c.id WHERE c.start = r.value) LIMIT 10`,n,f);if(N.length>0)throw _(`the bundle refers to objects that are not ${n}'s: ${N.map(o=>`${o.tbl}.${o.col}=${o.value}`).join(", ")}`,{references:N});const p=[["nodes","profile_id"],["crons","profile"],["profiles","id"]];for(const[o,l]of p){const b=await $(t,`SELECT DISTINCT s.${E(l)} AS v FROM ${e(o)} s JOIN ${c("profiles")} p ON p.id = s.${E(l)} WHERE p.person <> ? LIMIT 5`,n);if(b.length>0)throw _(`${o}.${l} names profiles that belong to another person: ${b.map(T=>T.v).join(", ")}`,{where:`${o}.${l}`,values:b.map(T=>T.v)})}for(const[o,l]of[["nodes","grant_id"],["crons","grant_id"]]){const b=await $(t,`SELECT DISTINCT s.${E(l)} AS v FROM ${e(o)} s JOIN ${c("grants")} g ON g.id = s.${E(l)} WHERE g.sub <> ? LIMIT 5`,n);if(b.length>0)throw _(`${o}.${l} names grants that belong to another person: ${b.map(T=>T.v).join(", ")}`,{where:`${o}.${l}`,values:b.map(T=>T.v)})}const d=await $(t,`SELECT DISTINCT d.adapter_json::jsonb #>> '{principal,grant_id}' AS v FROM ${e("daemon_actions")} d
|
|
15
|
+
JOIN ${c("grants")} g ON g.id = d.adapter_json::jsonb #>> '{principal,grant_id}' WHERE g.sub <> ? LIMIT 5`,n);if(d.length>0)throw _(`a queued action names grants that belong to another person: ${d.map(o=>o.v).join(", ")}`,{where:"daemon_actions principal.grant_id",values:d.map(o=>o.v)})}u(W,"checkStagedReferences");const O=u((s,t)=>new m("bind","bundle_invalid",s,t),"bundleInvalid");async function U(s){const{db:t,schema:r}=s,a=u(e=>I(r,e),"S"),i=new Set((await $(t,`SELECT node_id AS v FROM ${a("nodes")}`)).map(e=>e.v)),n=u((e,c,f,h)=>{const N=L(c);if(N===null||N.kind!==f||h!==void 0&&c!==h)throw O(`${e} holds ${JSON.stringify(c)}, which is not a ${f} blob key${h===void 0?"":` of the shape ${h}`}`,{where:e,value:c});if(!i.has(N.owner))throw _(`${e} holds ${c}, which belongs to node ${N.owner}, who is not in the bundle`,{where:e,value:c})},"check");for(const e of await $(t,`SELECT conversation_id, seq::text AS seq, blob_key FROM ${a("conversation_parts")}`))if(n("conversation_parts.blob_key",e.blob_key,"conversation"),e.blob_key.split("/")[2]!==e.conversation_id)throw O(`conversation_parts.blob_key ${e.blob_key} is not under its conversation ${e.conversation_id}`,{where:"conversation_parts.blob_key",value:e.blob_key});for(const e of await $(t,`SELECT blob_key FROM ${a("upload_uses")} WHERE blob_key IS NOT NULL`))n("upload_uses.blob_key",e.blob_key,"attachment");for(const e of await $(t,`SELECT object, output_key FROM ${a("jobs")} WHERE output_key IS NOT NULL`)){const c=e.output_key.split("/")[1]??"";n("jobs.output_key",e.output_key,"job",`jobs/${c}/${e.object}/output`)}}u(U,"checkStagedBlobKeys");async function q(s){const{db:t,schema:r}=s;for(const a of await $(t,`SELECT request_id, request_dir, presentation_dir, file FROM ${I(r,"human_requests")}`))for(const i of["request_dir","presentation_dir","file"]){const n=a[i];if(n===null||!n.startsWith("requests/"))continue;const e=L(n.includes("/",9)?n:`${n}/x`);if(e===null||e.kind!=="request")throw O(`human_requests.${i} holds ${JSON.stringify(n)}, which is not a request blob key`,{where:`human_requests.${i}`,value:n});if(e.owner!==a.request_id)throw _(`human_requests.${i} of ${a.request_id} holds ${n}, which belongs to request ${e.owner}`,{where:`human_requests.${i}`,value:n})}}u(q,"checkStagedRequestKeys");export{D as boundSub,k as checkSourcePerson,U as checkStagedBlobKeys,H as checkStagedPersons,W as checkStagedReferences,q as checkStagedRequestKeys};
|
|
@@ -5,6 +5,6 @@ export interface MovedBlobs {
|
|
|
5
5
|
left: number;
|
|
6
6
|
}
|
|
7
7
|
/** `created` collects the keys this call wrote, so the caller can delete them if the run fails before its copy commits. */
|
|
8
|
-
export declare function moveRunBlobs(db: CanvasDb, schema: string,
|
|
8
|
+
export declare function moveRunBlobs(db: CanvasDb, schema: string, blobs: BlobStore, runId: string, created: string[]): Promise<MovedBlobs>;
|
|
9
9
|
/** Delete the run's uploaded copies (after the run is done). */
|
|
10
10
|
export declare function deleteRunBlobs(blobs: BlobStore, runId: string): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var S=Object.defineProperty;var r=(e,n)=>S(e,"name",{value:n,configurable:!0});import{parseBlobKey as q,runBlobPrefix as f}from"../bundle/blob-keys.js";import{q as m}from"./catalog.js";import{ImportLaneError as h}from"./stage.js";const E=8;async function k(e,n,o,g,y){const v={nodes:new Set((await e.prepareUncached(`SELECT node_id AS v FROM ${m(n)}.nodes`).all()).map(t=>t.v)),human_requests:new Set((await e.prepareUncached(`SELECT request_id AS v FROM ${m(n)}.human_requests`).all()).map(t=>t.v))},w=f(g),s=await o.list(w),i={moved:0,left:0};let p=0;const x=r(async()=>{for(let t=p++;t<s.length;t=p++){const l=s[t],a=l.slice(w.length),c=q(a);if(c===null||!v[c.ownerTable].has(c.owner)){i.left+=1;continue}const u=await o.get(l);if(u===null)throw new h("blobs","bundle_invalid",`${l} was listed and is gone`);const d=await o.get(a);if(d===null)await o.put(a,u),y.push(a);else if(!d.equals(u))throw new h("blobs","unique_conflict",`${a} already exists with other contents; the import does not replace it`,{key:a});i.moved+=1}},"worker");return await Promise.all(Array.from({length:Math.min(E,s.length)},x)),i}r(k,"moveRunBlobs");async function A(e,n){for(const o of await e.list(f(n)))await e.delete(o)}r(A,"deleteRunBlobs");export{A as deleteRunBlobs,k as moveRunBlobs};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var Q=Object.defineProperty;var u=(e,i)=>Q(e,"name",{value:i,configurable:!0});import{zstdCompressSync as V}from"node:zlib";import{blobStore as Y}from"../../blobs/index.js";import{openDb as
|
|
1
|
+
var Q=Object.defineProperty;var u=(e,i)=>Q(e,"name",{value:i,configurable:!0});import{zstdCompressSync as V}from"node:zlib";import{blobStore as Y}from"../../blobs/index.js";import{openDb as E,withCanvasWrite as N}from"../../canvas/db.js";import{insertImportedRevisions as X}from"../../graph/documents.js";import{getById as Z}from"../../graph/objects.js";import{bundleKeys as S,decodeRows as x,rowKeys as ee,SEQ_TABLES as te}from"../bundle/layout.js";import{readCatalog as ae}from"./catalog.js";import{copyRows as ne,decodeKeys as C,encodeKeys as W}from"./copy.js";import{pruneStaged as ie,precheck as se,renameClashingProfiles as re,rewritePaths as oe,rewriteRequestPaths as de,takeRepoSyncedDocuments as pe}from"./prepare.js";import{boundSub as ce,checkSourcePerson as ue,checkStagedBlobKeys as fe,checkStagedPersons as le,checkStagedReferences as me,checkStagedRequestKeys as _e}from"./bind.js";import{deleteRunBlobs as we,moveRunBlobs as ge}from"./blobs.js";import{dropStubRows as be,findFleetGrant as he,grantMissing as ye,mapProfileIds as Ee,rewriteIds as Se,rewritePerson as ve}from"./rewrite.js";import{dropStaging as B,ImportLaneError as w,stage as Re,stagingSchema as Oe,targetSchema as Te}from"./stage.js";import{verifyRun as Pe}from"./verify.js";import{sandboxPathMap as ke,writeNodeFiles as Ie}from"./path-map.js";import{allStoreKeys as je,readPluginsStore as De,recordImportedActivations as Ae,writeStores as Me}from"./stores.js";import{publishImportedPlugins as Ne}from"./publish-plugins.js";import{COPIED_TABLES as Ce}from"../bundle/layout.js";import{ClaimLostError as We}from"../../../daemon/reconcilers/row-claim.js";const L=10*6e4,v=u(()=>new Date().toISOString(),"now"),R=u(async(e,i)=>{await(await E()).prepare("UPDATE import_runs SET step = ? WHERE run_id = ?").run(i,e)},"setStep");async function Be(e,i){const n=await e.get(S.source(i));if(n===null)throw new w("stage","bundle_invalid","source.json is missing");return JSON.parse(n.toString("utf8"))}u(Be,"readSource");async function Le(e,i,n,r,s,d){const t=await e.get(S.rows(n.run_id,"grants")),l=t===null?[]:x(t),m=[];for(const a of l){const p=ce(a.sub,r,n.person,"grants.sub");await he(i,s,d,p,a.grantee)===void 0&&m.push(a.grantee)}if(m.length===0)return!0;if(n.loaded_at===void 0||n.loaded_at===null)throw new w("stage","import_failed","a loading run has no loaded_at");if(Date.now()-Date.parse(n.loaded_at)>=L)throw ye(m);return!1}u(Le,"grantsReady");async function pt(e,i,n={}){const r=n.blobs??await Y(),s=await E(),d=Oe(e.run_id),t=u(async a=>{await i.assertOwned(),await R(e.run_id,a),await n.atStep?.(a)},"at");let l=e.state==="committed";const m=[];try{const a=await Be(r,e.run_id);if(e.source_kind==="machine"&&a.installId!==e.source_install_id)throw new w("stage","bundle_invalid",`source.json names install ${a.installId}, the run is for ${e.source_install_id}`);a.installId=e.source_install_id;const p=await Te(s),b=[...Ce],g=await ae(s,p,[...b,"grants"]);if(!l){const f={},P=[],k=[],I=n.fleetRuntime??process.env.CRTR_RUNTIME??null;if(await ue(s,p,a.person,e.person),!await Le(r,s,e,a.person,p,I)){await i.assertOwned(),await R(e.run_id,"waiting_for_grants");return}await t("publish-plugins");const y=await Ne(await De(r,e.run_id));if(y.unavailable.length>0){if(e.loaded_at===void 0||e.loaded_at===null)throw new w("publish-plugins","import_failed","a loading run has no loaded_at");if(Date.now()-Date.parse(e.loaded_at)>=L)throw new w("publish-plugins","directory_unavailable",`the directory did not answer for: ${y.unavailable.slice(0,10).join(", ")}; rerun the import once it is reachable`,{plugins:y.unavailable});await i.assertOwned(),await R(e.run_id,"waiting_for_directory");return}k.push(...y.refused),await t("stage");const K=await Re(s,e.run_id,a.counts,o=>ee(e.run_id,o,a),o=>r.get(o));for(const[o,c]of Object.entries(K))f[o]={staged:c,inserted:0,mapped:0,dropped:0};const _={db:s,schema:d,target:p,catalog:g,sourcePerson:a.person,targetPerson:e.person,fleetRuntime:I,shippedBodies:a.shippedBodies??{}};await t("bind-staged");for(const[o,c]of Object.entries(await le(_)))O(f,o,c);await fe(_),await t("rewrite-person"),await ve(_),await t("prune");const U=await ie(s,d,g,a),j=a.kind==="hosted"?ke(a.pathPrefixes??[]):[];await t("rewrite-paths"),await oe(s,d,j),await de(s,d),await _e(_);const F=await Ee(_);await re(s,d,p,a.installId,e.person),await t("rewrite-ids");const D=await Se(_,F);await t("drop");const J=await pe(s,d,p),q=await be(_);for(const[o,c]of Object.entries({...U}))O(f,o,c);for(const[o,c]of Object.entries(q))O(f,o,c);await me(_),await t("pre-check");const $=new Map([["messages",["seq"]],...te.map(o=>[o,["seq"]])]);await se(s,d,p,g,b,new Set,$),await t("blobs"),await ge(s,d,r,e.run_id,m),await t("copy"),await N(async o=>{await i.assertOwned();const c=await ne({db:o,runId:e.run_id,schema:d,target:p,catalog:g,source:a,person:e.person,idMap:D,pathMap:j}),A=await Ue(o,e.run_id,J);A>0&&(c.inserted.revisions=(c.inserted.revisions??0)+A),await Ie(o,d,e.run_id,a);const M=await Me({db:o,blobs:r,runId:e.run_id,person:e.person,objectMap:D.object});for(const[G,z]of Object.entries(M.inserted))c.inserted[G]=z.length;return P.push(...M.unresolvedPlugins),await o.prepare("UPDATE import_runs SET counts_json = ?, loaded_at = COALESCE(loaded_at, ?) WHERE run_id = ?").run(JSON.stringify({...Ke(f,c),unresolved_plugins:P,refused_plugins:k}),v(),e.run_id),c}),l=!0,await n.atStep?.("committed")}await t("verify");const h=await Pe(s,e.run_id,d,p,g,a.installId);if(await s.prepare("UPDATE import_runs SET verify_json = ? WHERE run_id = ?").run(JSON.stringify(h),e.run_id),!h.ok)throw new w("verify","verify_failed","the committed rows differ from the staged rows or an invariant failed",{differences:h.differences,invariants:h.invariants});await t("manifest");const T=S.manifest(e.run_id);await r.put(T,await Fe(e.run_id)),await B(s,e.run_id);for(const f of je(e.run_id))await r.delete(f);await we(r,e.run_id),await N(async f=>{await Ae(f,e.run_id,e.person),await f.prepare("UPDATE import_runs SET state = 'done', step = 'done', manifest_key = ?, finished_at = ? WHERE run_id = ?").run(T,v(),e.run_id)})}catch(a){if(a instanceof We)throw a;const p=He(a);if(await B(s,e.run_id).catch(()=>{}),!l)for(const b of m)await r.delete(b).catch(()=>{});await s.prepare("UPDATE import_runs SET state = 'failed', failure_json = ?, finished_at = ? WHERE run_id = ?").run(JSON.stringify(p),v(),e.run_id)}}u(pt,"processRun");function He(e){if(e instanceof w)return{step:e.step,code:e.code,message:e.message,...e.detail===void 0?{}:{detail:e.detail}};const i=e.code;return{step:"unknown",code:typeof i=="string"?i:"import_failed",message:e instanceof Error?e.message:String(e)}}u(He,"failureOf");function O(e,i,n){(e[i]??={staged:0,inserted:0,mapped:0,dropped:0}).dropped+=n}u(O,"addDropped");function Ke(e,i){for(const[n,r]of Object.entries(i.inserted))(e[n]??={staged:0,inserted:0,mapped:0,dropped:0}).inserted=r;for(const[n,r]of Object.entries(i.mapped))(e[n]??={staged:0,inserted:0,mapped:0,dropped:0}).mapped=r;return e}u(Ke,"withInserted");async function Ue(e,i,n){const r=new Set((await e.prepareUncached("SELECT rev_id FROM revisions WHERE rev_id IN (SELECT jsonb_array_elements_text(?::jsonb))").all(JSON.stringify(n.map(t=>t.rev_id)))).map(t=>t.rev_id)),s=n.filter(t=>!r.has(t.rev_id)),d=new Map;for(const t of n)d.set(t.document,[...d.get(t.document)??[],t]);for(const[t,l]of d){const m=await Z(e,t);m!==null&&await X(e,m,l.map(a=>({rev_id:a.rev_id,parents:a.parents,body_hash:a.body_hash,rationale:a.rationale,created_at:a.created_at})))}return await H(e,i,"revisions",s.map(t=>[t.rev_id])),await H(e,i,"revision_parents",s.flatMap(t=>t.parents.map(l=>[t.rev_id,l]))),s.length}u(Ue,"arrive");async function H(e,i,n,r){if(r.length===0)return;const s=await e.prepare("SELECT inserted_keys FROM import_manifest WHERE run_id = ? AND table_name = ?").get(i,n);s===void 0?await e.prepare("INSERT INTO import_manifest (run_id, table_name, inserted_keys) VALUES (?, ?, ?)").run(i,n,W(r)):await e.prepare("UPDATE import_manifest SET inserted_keys = ? WHERE run_id = ? AND table_name = ?").run(W([...C(s.inserted_keys),...r]),i,n)}u(H,"appendManifest");async function Fe(e){const n=await(await E()).prepare("SELECT table_name, inserted_keys FROM import_manifest WHERE run_id = ? ORDER BY table_name").all(e);return V(Buffer.from(n.map(r=>JSON.stringify({table:r.table_name,keys:C(r.inserted_keys)})).join(`
|
|
2
2
|
`)+`
|
|
3
3
|
`))}u(Fe,"manifestFile");export{L as GRANT_WAIT_MS,pt as processRun};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.610",
|
|
4
4
|
"description": "crtr — agent runtime with memory, plugins, and marketplaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -145,7 +145,7 @@
|
|
|
145
145
|
},
|
|
146
146
|
"license": "UNLICENSED",
|
|
147
147
|
"dependencies": {
|
|
148
|
-
"@north-light/identity": "0.3.
|
|
148
|
+
"@north-light/identity": "0.3.610",
|
|
149
149
|
"@earendil-works/chord": "1.1.0",
|
|
150
150
|
"@earendil-works/pi-agent-core": "1.1.0",
|
|
151
151
|
"@earendil-works/pi-ai": "1.1.0",
|
package/runtime.lock.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.610",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@north-light/cli",
|
|
9
|
-
"version": "0.3.
|
|
9
|
+
"version": "0.3.610",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "UNLICENSED",
|
|
12
12
|
"workspaces": [
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@milkdown/preset-gfm": "^7.22.3",
|
|
29
29
|
"@milkdown/prose": "^7.22.3",
|
|
30
30
|
"@milkdown/utils": "^7.22.3",
|
|
31
|
-
"@north-light/identity": "0.3.
|
|
31
|
+
"@north-light/identity": "0.3.610",
|
|
32
32
|
"cron-parser": "^5.6.0",
|
|
33
33
|
"esbuild": "^0.27.7",
|
|
34
34
|
"jose": "^6.2.12",
|
|
@@ -11956,17 +11956,17 @@
|
|
|
11956
11956
|
},
|
|
11957
11957
|
"packages/crouter-api": {
|
|
11958
11958
|
"name": "@north-light/api",
|
|
11959
|
-
"version": "0.3.
|
|
11959
|
+
"version": "0.3.610",
|
|
11960
11960
|
"license": "UNLICENSED"
|
|
11961
11961
|
},
|
|
11962
11962
|
"packages/crouter-env-docker": {
|
|
11963
11963
|
"name": "@north-light/env-docker",
|
|
11964
|
-
"version": "0.3.
|
|
11964
|
+
"version": "0.3.610",
|
|
11965
11965
|
"license": "UNLICENSED"
|
|
11966
11966
|
},
|
|
11967
11967
|
"packages/crouter-identity": {
|
|
11968
11968
|
"name": "@north-light/identity",
|
|
11969
|
-
"version": "0.3.
|
|
11969
|
+
"version": "0.3.610",
|
|
11970
11970
|
"license": "UNLICENSED",
|
|
11971
11971
|
"dependencies": {
|
|
11972
11972
|
"jose": "^6.2.1"
|
|
@@ -11974,21 +11974,21 @@
|
|
|
11974
11974
|
},
|
|
11975
11975
|
"packages/crouter-plugin": {
|
|
11976
11976
|
"name": "@north-light/plugin",
|
|
11977
|
-
"version": "0.3.
|
|
11977
|
+
"version": "0.3.610",
|
|
11978
11978
|
"license": "UNLICENSED",
|
|
11979
11979
|
"dependencies": {
|
|
11980
|
-
"@north-light/api": "0.3.
|
|
11981
|
-
"@north-light/identity": "0.3.
|
|
11980
|
+
"@north-light/api": "0.3.610",
|
|
11981
|
+
"@north-light/identity": "0.3.610"
|
|
11982
11982
|
}
|
|
11983
11983
|
},
|
|
11984
11984
|
"packages/crouter-sdk": {
|
|
11985
11985
|
"name": "@north-light/sdk",
|
|
11986
|
-
"version": "0.3.
|
|
11986
|
+
"version": "0.3.610",
|
|
11987
11987
|
"license": "UNLICENSED",
|
|
11988
11988
|
"dependencies": {
|
|
11989
|
-
"@north-light/api": "0.3.
|
|
11990
|
-
"@north-light/identity": "0.3.
|
|
11991
|
-
"@north-light/plugin": "0.3.
|
|
11989
|
+
"@north-light/api": "0.3.610",
|
|
11990
|
+
"@north-light/identity": "0.3.610",
|
|
11991
|
+
"@north-light/plugin": "0.3.610",
|
|
11992
11992
|
"jose": "^6.2.1"
|
|
11993
11993
|
},
|
|
11994
11994
|
"bin": {
|