@niscorp/moss 0.8.1 → 0.9.0

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/DOCS.md +87 -26
  3. package/README.md +9 -8
  4. package/dist/{chunk-3DCTQKPQ.cjs → chunk-E6YAYR7G.cjs} +22 -5
  5. package/dist/chunk-E6YAYR7G.cjs.map +1 -0
  6. package/dist/{chunk-TMDKNZYL.cjs → chunk-L2GHVTJW.cjs} +103 -71
  7. package/dist/chunk-L2GHVTJW.cjs.map +1 -0
  8. package/dist/{chunk-I4UOWER3.cjs → chunk-LKTS4PCD.cjs} +5 -5
  9. package/dist/{chunk-I4UOWER3.cjs.map → chunk-LKTS4PCD.cjs.map} +1 -1
  10. package/dist/{chunk-3T422CCN.js → chunk-UUOATPZ7.js} +3 -3
  11. package/dist/{chunk-3T422CCN.js.map → chunk-UUOATPZ7.js.map} +1 -1
  12. package/dist/{chunk-6XC2MD7S.js → chunk-WTWRLOPK.js} +22 -5
  13. package/dist/chunk-WTWRLOPK.js.map +1 -0
  14. package/dist/{chunk-YZILOVCR.js → chunk-Y7PRASR3.js} +49 -18
  15. package/dist/chunk-Y7PRASR3.js.map +1 -0
  16. package/dist/{document-BYAY-Qle.d.ts → document-C3aS9uiW.d.ts} +2 -1
  17. package/dist/{document-DAE71J27.d.cts → document-deAs7Dre.d.cts} +2 -1
  18. package/dist/index.cjs +17 -13
  19. package/dist/index.d.cts +8 -5
  20. package/dist/index.d.ts +8 -5
  21. package/dist/index.js +2 -2
  22. package/dist/integrations.cjs +12 -5
  23. package/dist/integrations.cjs.map +1 -1
  24. package/dist/integrations.js +12 -5
  25. package/dist/integrations.js.map +1 -1
  26. package/dist/node.cjs +7 -7
  27. package/dist/node.d.cts +1 -1
  28. package/dist/node.d.ts +1 -1
  29. package/dist/node.js +3 -3
  30. package/dist/unverified.cjs +2 -2
  31. package/dist/unverified.js +1 -1
  32. package/dist/vite.cjs +8 -8
  33. package/dist/vite.d.cts +1 -1
  34. package/dist/vite.d.ts +1 -1
  35. package/dist/vite.js +3 -3
  36. package/package.json +12 -12
  37. package/dist/chunk-3DCTQKPQ.cjs.map +0 -1
  38. package/dist/chunk-6XC2MD7S.js.map +0 -1
  39. package/dist/chunk-TMDKNZYL.cjs.map +0 -1
  40. package/dist/chunk-YZILOVCR.js.map +0 -1
@@ -1,10 +1,10 @@
1
- import { entriesOf, receiveManifest, verifiedAtBoot, verifyManifest, withFragments, candidateOf, FRAME_LAYOUT_REF, canvasLayoutRef, functionsIn, charterOverFunctions, refusalOf, functionsWarning, layoutMisfits, freezeDeep, entryMisfits, sessionOn, endlessChains, actionLayoutRef, endShell, GENERATED_ID_PREFIX, layoutNameRefusal, actionOfLayoutRef, withLayoutInPlace, canvasesOf, treeOf, buildShell, SHELL_GONE, draftedIn, attach, holdGranted, layoutsOf, withVariants, variantLayouts } from './chunk-6XC2MD7S.js';
1
+ import { entriesOf, receiveManifest, verifiedAtBoot, verifyManifest, withFragments, candidateOf, FRAME_LAYOUT_REF, canvasLayoutRef, functionsIn, charterOverFunctions, refusalOf, functionsWarning, layoutMisfits, freezeDeep, entryMisfits, sessionOn, endlessChains, actionLayoutRef, endShell, GENERATED_ID_PREFIX, layoutNameRefusal, actionOfLayoutRef, withLayoutInPlace, canvasesOf, treeOf, buildShell, SHELL_GONE, draftedIn, attach, holdGranted, layoutsOf, withVariants, variantLayouts } from './chunk-WTWRLOPK.js';
2
2
  import { emitterOf, FabricMessageSchema, spanClock } from './chunk-QAHDSRPK.js';
3
3
  import { DEFAULT_TOKEN_KEY, sessionNameOf, SNAPSHOT_ELEMENT_ID, CLOSE_SHELL_FAILED, CLOSE_PROTOCOL_MISMATCH, CLOSE_INVALID_TOKEN, CLOSE_AT_CAPACITY, PROTOCOL_MIN, PROTOCOL, offeredSealed, offeredToken, ClientMessageSchema } from './chunk-4ZGAFZGS.js';
4
4
  import { z } from 'zod';
5
5
  import { randomBytes, createHash, timingSafeEqual, randomUUID } from 'crypto';
6
6
  import { createPostgresCache, createPostgresAdapter, resolve, pruneOptional, mutationMisfits, createMemoryCache, seedCache, handleDiscovery, handleQuery, mergeScopePolicies, createScopePolicy, createQueryEngine, scopeGrants, tablesChangedBy } from '@niscorp/vex';
7
- import { migrate, upgradeStore } from '@niscorp/strata/postgres';
7
+ import { status, migrate, upgradeStore } from '@niscorp/strata/postgres';
8
8
  import { exceedsDepth, StrataError, depthRefusal, createUpgrader } from '@niscorp/strata';
9
9
  import { NOVA_SEQUENCE } from '@niscorp/nova/migrations';
10
10
  import { evaluate } from '@niscorp/prism';
@@ -610,6 +610,18 @@ var oneAtATime = (query) => {
610
610
  return next;
611
611
  };
612
612
  };
613
+ var ownersOf = (runtime, app) => ({
614
+ pool: runtime.pool,
615
+ cache: runtime.cache,
616
+ storesSessions: runtime.session === "sessions",
617
+ featureTables: featureTablesOf(app),
618
+ tables: runtime.tables
619
+ });
620
+ var tableStatus = async (runtime, app) => status(runtime.pool, tableSequencesOf(ownersOf(runtime, app)), { complete: true });
621
+ var removalsRefused = (found) => [
622
+ ...found.removed.map((what) => `this run removes ${what}`),
623
+ ...found.retyped.map((what) => `this run changes the type of ${what}`)
624
+ ].map((sentence) => `${sentence} \u2014 nothing removed or retyped is applied unless it is allowed (\`allowRemoval\`; \`nisc migrate --allow-removal\`)`);
613
625
  var migrateTables = async (runtime, app, options = {}) => {
614
626
  const entries = entriesOf(app);
615
627
  const cache = runtime.cache ?? createPostgresCache({ pool: runtime.pool });
@@ -620,10 +632,10 @@ var migrateTables = async (runtime, app, options = {}) => {
620
632
  if (misfitsBefore.has(entry.fingerprint) && await isSeededAs(cache, entry).catch(() => false)) excused.add(entry.fingerprint);
621
633
  }
622
634
  let found = { removed: [], retyped: [], alreadyBroken: [] };
623
- const owners = { pool: runtime.pool, cache: runtime.cache, storesSessions: runtime.session === "sessions", featureTables: featureTablesOf(app), tables: runtime.tables };
624
- const report = await migrate(runtime.pool, tableSequencesOf(owners), {
635
+ const report = await migrate(runtime.pool, tableSequencesOf(ownersOf(runtime, app)), {
636
+ complete: true,
625
637
  ...options.dryRun === true ? { dryRun: true } : {},
626
- guard: async (tx) => {
638
+ guard: async (tx, run) => {
627
639
  const after = await createPostgresAdapter({ pool: { query: oneAtATime((text, values) => tx.query(text, values)) } }).introspect();
628
640
  const refused = [];
629
641
  const alreadyBroken = [];
@@ -631,11 +643,12 @@ var migrateTables = async (runtime, app, options = {}) => {
631
643
  if (excused.has(fingerprint)) alreadyBroken.push(`${fingerprint}: ${why}`);
632
644
  else refused.push(`${fingerprint}: ${why}`);
633
645
  }
634
- found = { ...changesBetween(before, after), alreadyBroken };
635
- return refused;
646
+ const changes = run.applied.length === 0 ? { removed: [], retyped: [] } : changesBetween(before, after);
647
+ found = { ...changes, alreadyBroken };
648
+ return options.allowRemoval === true ? refused : [...refused, ...removalsRefused(changes)];
636
649
  }
637
650
  });
638
- return { ...report, ...found, ...report.applied.length === 0 ? { removed: [], retyped: [] } : {} };
651
+ return { ...report, ...found };
639
652
  };
640
653
  var featureTablesOf = (app) => {
641
654
  const features = /* @__PURE__ */ new Set();
@@ -995,7 +1008,15 @@ var createIntentAnswers = (deps) => {
995
1008
  // src/data/data.ts
996
1009
  var callerOfRoles = (roles) => ({ memoKey: memoKey(roles, void 0), roles });
997
1010
  var prepareEngine = async (config) => {
998
- await migrate(config.pool, tableSequencesOf(config), { mode: config.migrations ?? "apply" });
1011
+ await migrate(config.pool, tableSequencesOf(config), { mode: config.migrations ?? "verify", complete: true }).catch((error) => {
1012
+ if (!(error instanceof StrataError) || error.code !== "PENDING") throw error;
1013
+ throw new StrataError(
1014
+ "PENDING",
1015
+ `The database is ${error.details.length} migration${error.details.length === 1 ? "" : "s"} behind this code, and the server only checks its tables at boot. Rehearse them with \`npx nisc migrate --check\`, then apply them with \`npx nisc migrate\`. A database that starts empty every time (PGlite in memory) is migrated at boot instead: its runtime sets \`migrations: 'apply'\`.`,
1016
+ error.details,
1017
+ { cause: error }
1018
+ );
1019
+ });
999
1020
  const grammars = await createGrammarUpgrader({ grammars: config.grammars });
1000
1021
  const layer = await createDataLayer(config);
1001
1022
  return {
@@ -2628,7 +2649,7 @@ var refusalOf2 = (error) => {
2628
2649
  var spanOf = (emit) => {
2629
2650
  if (emit === void 0) return void 0;
2630
2651
  const clock = spanClock();
2631
- return (name, status, hasPrincipal) => emit({ name, startUnixNano: clock.startUnixNano, endUnixNano: clock.endUnixNano(), status, attributes: { hasPrincipal } });
2652
+ return (name, status2, hasPrincipal) => emit({ name, startUnixNano: clock.startUnixNano, endUnixNano: clock.endUnixNano(), status: status2, attributes: { hasPrincipal } });
2632
2653
  };
2633
2654
  var openingOf = (config, { seed, path }) => {
2634
2655
  const route = path === void 0 ? void 0 : config.page?.(path);
@@ -3009,7 +3030,12 @@ var replaceShell = async (host, cell) => {
3009
3030
  for (const { connection, wants } of carried) attach(built.live, connection, host.delta && wants);
3010
3031
  };
3011
3032
  var resetCell = (host, cell) => {
3012
- const turn = (cell.resetting ?? Promise.resolve()).then(() => replaceShell(host, cell));
3033
+ if (cell.hasWaitingReset === true) return;
3034
+ cell.hasWaitingReset = true;
3035
+ const turn = (cell.resetting ?? Promise.resolve()).then(() => {
3036
+ cell.hasWaitingReset = false;
3037
+ return replaceShell(host, cell);
3038
+ });
3013
3039
  cell.resetting = turn.catch((error) => console.error("[moss/shells] a reset failed to rebuild", error));
3014
3040
  };
3015
3041
  var shellsOf = (host, principal) => {
@@ -3119,7 +3145,8 @@ var hostConfig = (deps, shell, kept) => {
3119
3145
  ...app.phrases !== void 0 ? { phrases: app.phrases } : {},
3120
3146
  ...app.functions !== void 0 ? { functions: app.functions } : {},
3121
3147
  ...app.onSession !== void 0 ? { onSession: app.onSession } : {},
3122
- ...app.runs !== void 0 ? { runs: app.runs } : {}
3148
+ ...app.runs !== void 0 ? { runs: app.runs } : {},
3149
+ ...app.reconcilers !== void 0 ? { reconcilers: app.reconcilers } : {}
3123
3150
  },
3124
3151
  ...app.phraseKeys !== void 0 ? { phraseKeys: app.phraseKeys } : {},
3125
3152
  kept,
@@ -3284,14 +3311,18 @@ var operatorPrefix = (runtime) => {
3284
3311
  guardOperator(operator, { key: runtime.operatorKey ?? "", gate: runtime.operatorGate });
3285
3312
  return operator;
3286
3313
  };
3287
- var buildSignals = ({ fabric, identity, reset, adopt: adopt2, deliver }) => {
3314
+ var buildSignals = ({ fabric, identity, reset, adopt: adopt2, adoptAll: adoptAll2, deliver }) => {
3288
3315
  const origin = randomBytes(8).toString("hex");
3289
3316
  const applyInvalidateIdentity = (principal) => {
3290
3317
  const held = identity.invalidate(principal);
3291
3318
  reset(principal);
3292
3319
  return held;
3293
3320
  };
3294
- const applyInvalidateTag = (tag) => identity.invalidateTag(tag).length;
3321
+ const applyInvalidateTag = (tag) => {
3322
+ const forgotten = identity.invalidateTag(tag).length;
3323
+ adoptAll2();
3324
+ return forgotten;
3325
+ };
3295
3326
  const applyNudge = (principal, channel) => {
3296
3327
  deliver(principal, channel);
3297
3328
  };
@@ -3433,7 +3464,7 @@ var assemble = async ({ app, runtime, session, revokeSessions, data }, stops) =>
3433
3464
  mountRoutes(server, { app, session, credentials: registered.credentials, identity, running, data });
3434
3465
  const hosts = buildShellHosts({ app, runtime, identity, running, data, savedAs: saved.of, wire: createInternalWire(server), wrapWire: composeWireWraps(registered), revokeSessions });
3435
3466
  stops.push(hosts.stop);
3436
- const signals = buildSignals({ fabric: runtime.fabric, identity, reset: hosts.reset, adopt: hosts.adoptFor, deliver: hosts.deliver });
3467
+ const signals = buildSignals({ fabric: runtime.fabric, identity, reset: hosts.reset, adopt: hosts.adoptFor, adoptAll: hosts.adopt, deliver: hosts.deliver });
3437
3468
  running.onChange(() => {
3438
3469
  identity.invalidateAll();
3439
3470
  hosts.adopt();
@@ -3551,6 +3582,6 @@ var subscribeReactions = ({ app, onWrite, deliver }) => {
3551
3582
  });
3552
3583
  };
3553
3584
 
3554
- export { MOSS_SEQUENCE, createServer, exportDocuments, migrateTables, mintDevToken, mintSession, renderDocument, revokeAllFor, sessionCookies };
3555
- //# sourceMappingURL=chunk-YZILOVCR.js.map
3556
- //# sourceMappingURL=chunk-YZILOVCR.js.map
3585
+ export { MOSS_SEQUENCE, createServer, exportDocuments, migrateTables, mintDevToken, mintSession, renderDocument, revokeAllFor, sessionCookies, tableStatus };
3586
+ //# sourceMappingURL=chunk-Y7PRASR3.js.map
3587
+ //# sourceMappingURL=chunk-Y7PRASR3.js.map